Blob Blame Raw
#!/bin/bash

set -e

if [ -z "$TARGETPATH" ]; then
	TARGETPATH="$(pwd)"
fi

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 ..."
	echo "You may set environment variable TARGETPATH - the full path to target directory"
	exit 1
fi

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

source function.sh
source toolchain.sh


if [ -z "OPTIONS" ]; then
	OPTIONS="-O3 -DNDEBUG"
	#OPTIONS="-g -O0"
fi

COMP="CC"
COMP_OPTIONS=
if [ "$COMPILER" = "c++" ]; then
	COMP="CXX"
	COMP_OPTIONS="-static-libstdc++"
fi


packages=""
newpackages="program"

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


function build_program() {
	local CMP=${!COMP}
	if [ -z "$LINUX" ]; then
		echocall $CMP \
			"${ARGS[@]}" \
			-Wall $OPTIONS \
			-I"$ROOT/release/include/helianthus" \
			"$ROOT/release/lib-$bits/libhelianthus.a" \
			-lmingw32 -mconsole \
			-lm -static-libgcc $COMP_OPTIONS \
			-lopengl32 -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lshlwapi \
			-lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lsetupapi -lversion -luuid \
			-o "$TARGETPATH/$PROGNAME-$bits.exe"
	else
		echocall $CMP \
			"${ARGS[@]}" \
			-Wall $OPTIONS \
			-I"$ROOT/release/include/helianthus" \
			"$ROOT/release/lib-$bits/libhelianthus.a" \
			-lm -static-libgcc $COMP_OPTIONS -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