80 lines
1.5 KiB
Bash
Executable File
80 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
if [ -z $MODE ]; then
|
|
MODE='debug'
|
|
fi
|
|
|
|
if [ -z $CC ]; then
|
|
CC='gcc'
|
|
fi
|
|
|
|
# setup dirs
|
|
BUILD_DIR=./out
|
|
GEN_DIR=$BUILD_DIR/gen
|
|
TOOL_SRC=tools/file2header.c
|
|
TOOL_EXE=$BUILD_DIR/file2header
|
|
|
|
# clean cmd
|
|
case $1 in
|
|
"clean")
|
|
echo "Deleting $BUILD_DIR"
|
|
rm -rf $BUILD_DIR
|
|
exit 0
|
|
esac
|
|
|
|
# create the build dir if it doesnt exist
|
|
if [ -d $BUILD_DIR ]; then
|
|
echo "Building to $BUILD_DIR"
|
|
else
|
|
echo "$BUILD_DIR not found, creating"
|
|
mkdir -p $BUILD_DIR
|
|
fi
|
|
|
|
# Ensure gen dir exists
|
|
mkdir -p $GEN_DIR
|
|
|
|
# Check if tool source exists
|
|
if [ ! -f $TOOL_SRC ]; then
|
|
echo "Error: $TOOL_SRC not found!"
|
|
exit 1
|
|
fi
|
|
|
|
# Compile tool if exe missing or source changed
|
|
if [ ! -f $TOOL_EXE ] || [ $TOOL_SRC -nt $TOOL_EXE ]; then
|
|
echo "Compiling file2header tool..."
|
|
$CC $TOOL_SRC -o $TOOL_EXE
|
|
fi
|
|
|
|
if [ -d "arch" ]; then
|
|
for file in arch/*.c; do
|
|
name=$(basename "$file" .c)
|
|
out_header="$GEN_DIR/${name}.h"
|
|
|
|
if [ ! -f "$out_header" ] || [ "$file" -nt "$out_header" ]; then
|
|
echo "Packing $file -> $out_header"
|
|
$TOOL_EXE "$file" > "$out_header"
|
|
fi
|
|
done
|
|
else
|
|
echo "Warning: 'arch' directory not found."
|
|
fi
|
|
|
|
# setup the build flags based on the build mode
|
|
case $MODE in
|
|
"debug")
|
|
BUILD_FLAGS="-g -Wall -Wextra -Werror -pedantic"
|
|
;;
|
|
"release")
|
|
BUILD_FLAGS="-O3 -Wall -Wextra -Werror -pedantic"
|
|
;;
|
|
esac
|
|
|
|
BUILD_CMD="$CC -o $BUILD_DIR/undar main.c -I$GEN_DIR $BUILD_FLAGS"
|
|
|
|
echo "$BUILD_CMD"
|
|
${BUILD_CMD}
|
|
|
|
echo "Finished building to $BUILD_DIR/undar"
|