#!/bin/bash set -eo pipefail CMP="gcc" WARN="-std=c99 -Wall -Wextra -Wno-discarded-qualifiers -Wno-unused-parameter" ARGS_DEBUG="-O0 -g" ARGS_RELEASE="-O2 -flto=auto -fdata-sections -ffunction-sections -Wl,--gc-sections" if [[ "$1" = "debug" ]]; then ARGS=$ARGS_DEBUG else ARGS=$ARGS_RELEASE fi SRC="$(find src -name '*.c')" OS=$(../detect_os.sh) ARCH=$(../detect_arch.sh) OUTFILE="bin/libkerep-$OS-$ARCH.a" rm -rf obj mkdir obj mkdir -p bin echo "----------------[kerep]-----------------" compiler_call="$CMP $WARN $ARGS -c" echo "$compiler_call" OBJECTS= for srcfile in $SRC do echo " $srcfile" object="obj/$(basename $srcfile).o" OBJECTS="$OBJECTS $object" command="$compiler_call $srcfile -o $object" if ! $($command); then exit 1 fi done command="ar rcs $OUTFILE $OBJECTS" echo "$command" if $($command) then echo "static lib $OUTFILE created" rm -r obj else exit 1 fi