cbuild-c/build.sh
2023-07-12 14:08:26 +03:00

39 lines
723 B
Bash

#!/bin/bash
set -eo pipefail
CMP="gcc"
WARN="-Wall -Wextra -Wno-discarded-qualifiers -Wno-unused-parameter"
ARGS="-O2 -flto -fdata-sections -ffunction-sections -Wl,--gc-sections"
SRC="$(find src -name '*.c')"
OS="$(./detect_os.sh)"
ARCH="$(./detect_arch.sh)"
LINK="-Lkerep/bin -lkerep-$OS-$ARCH"
if [[ OS -eq "windows" ]]; then
OUT_FILE="cbuild.exe"
else
OUT_FILE="cbuild"
fi
command="$CMP $ARGS
$WARN
-DOS=\"$OS\" -DARCH=\"$ARCH\"
$SRC
$LINK
-o bin/$OUT_FILE"
if [ ! -f "kerep/bin/libkerep-$OS-$ARCH.a" ]; then
echo "libkerep-$OS-$ARCH.a not found"
cd kerep
./build.sh
cd ..
fi
rm -rf bin
mkdir bin
echo "----------------[cbuild]----------------"
echo "$command"
$($command)