Add build script
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 12s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 11s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 11s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 14s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 11s

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-07-26 22:20:41 +03:00
parent 82f5e3b77e
commit 0b5c556f84
3 changed files with 78 additions and 2 deletions

54
build.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/sh
set -e
BUILD_DIR="BUILD"
INSTALL_DIR="$(pwd)/install"
CFLAGS="-std=gnu99 -Wall -Wextra -pedantic -Werror -Wno-newline-eof -Wno-language-extension-token"
BUILD_SHARED=1
PTHREAD_SUPPORT=1
POSIX_SUPPORT=1
SRC_DIR="src"
INCLUDE_DIR="include"
OUTPUT_NAME="libdcfg"
for arg in "$@"; do
case $arg in
--debug) CFLAGS="$CFLAGS -g -O0" ;;
--release) CFLAGS="$CFLAGS -O2" ;;
--no-pthread) PTHREAD_SUPPORT=0 ;;
--no-posix) POSIX_SUPPORT=0 ;;
--clean) rm -rf "$BUILD_DIR" "$INSTALL_DIR"; echo "Cleaned."; exit 0 ;;
esac
done
# Setup directories
mkdir -p "$BUILD_DIR" "$INSTALL_DIR/lib" "$INSTALL_DIR/include"
# Compiler and linker
CC=${CC:-cc}
if [ "$PTHREAD_SUPPORT" -eq 1 ]; then
CFLAGS="$CFLAGS -DDCFG_PTHREAD_SUPPORT"
LIBS="$LIBS -lpthread"
fi
if [ "$POSIX_SUPPORT" -eq 1 ]; then
CFLAGS="$CFLAGS -DDCFG_POSIX_SUPPORT"
fi
echo "Building DCFG..."
cd "$BUILD_DIR"
set -x
$CC $CFLAGS -fPIC -shared "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR" -o "$OUTPUT_NAME.so" $LIBS
$CC $CFLAGS -c "../$SRC_DIR/dcfg.c" -I"../$INCLUDE_DIR"
ar rcs "$OUTPUT_NAME.a" dcfg.o
set +x
echo "Installing..."
cp -r "../$INCLUDE_DIR/"* "$INSTALL_DIR/include/"
cp "$OUTPUT_NAME.so" "$INSTALL_DIR/lib/"
cp "$OUTPUT_NAME.a" "$INSTALL_DIR/lib/"
echo "Done. Installed to $INSTALL_DIR"