Blob Blame Raw
#!/bin/bash

set -e

TARGETPATH="$(pwd)"
PROGNAME="$1"
ARGS=()
for file in ${@:2}; do
	FILEPATH="$(realpath $file)"
    ARGS+=("$FILEPATH")
	echo "add file: $FILEPATH"
done


if [ -z "$PROGNAME" ] || [ -z "$ARGS" ]; then
	echo "Usage: $0 program_name file1.c file2.c ..."
	exit 1
fi

ROOT="$(cd `dirname "$0"`; pwd)"
cd "$ROOT"

source function.sh
source toolchain.sh


OPTIONS="-O3 -DNDEBUG"
#OPTIONS="-g -O0"

packages=""
newpackages="program"

#######################################################################


function build_program() {
	if [ -z "$LINUX" ]; then
		echocall $CC \
			"${ARGS[@]}" \
			-Wall $OPTIONS \
			-I"$ROOT/release/include/helianthus" \
			"$ROOT/release/lib-$bits/libhelianthus.a" \
			-lmingw32 -mconsole \
			-lm -static-libgcc \
			-lopengl32 -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lshlwapi \
			-lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid \
			-o "$TARGETPATH/$PROGNAME-$bits.exe"
	else
		echocall $CC \
			"${ARGS[@]}" \
			-Wall $OPTIONS \
			-I"$ROOT/release/include/helianthus" \
			"$ROOT/release/lib-$bits/libhelianthus.a" \
			-lm -static-libgcc -lGL -ldl -pthread \
			-o "$TARGETPATH/$PROGNAME-$bits"
	fi
}


#######################################################################


rm -f build*/program.done
build win32 i686-w64-mingw32
build win64 x86_64-w64-mingw32
#LINUX=1 ADDCFLAGS="-m32 -fPIC" build linux32 ""
LINUX=1 ADDCFLAGS=-fPIC build linux64 ""
rm -f build*/program.done

print_section done