vg_root=`readlink $0`
vg_root=`dirname $vg_root`
+vg_version="0.1"
-#echo "VG Root: $vg_root"
-#echo "Working dir: `pwd`"
-
-cmd_lib_dir="-I. -L$vg_root/lib -L./ -I$vg_root"
-cmd_release=false
-cmd_defines=""
-cmd_target="fishladder"
+opt_assets=false
+opt_release=false
+opt_play=false
+opt_linux=false
+opt_windows=false
+opt_tools=false
+opt_full=false
+opt_steam=""
# Util
# ===========================================
echo -e "\033[0;37m$@\e[0m"
}
+titleit(){
+ echo ""
+ echo -e "\033[1;35m$@\e[0m"
+ echo "=========================="
+ echo ""
+}
+
+if [[ -f vg.conf ]]; then
+ source vg.conf
+else
+ error "Directory is not a VG project"
+ exit 1
+fi
+
# Platforms
# ===========================================
target_libs="-lglfw3 -lopengl32 -lm -mwindows"
target_dir="build.win32"
target_steam_api="steam_api.dll"
- if [ $cmd_release = true ]; then
+ if [ $opt_release = true ]; then
target_opts="-O3"
else
target_opts="-ggdb3"
target_libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl"
target_dir="build.linux"
target_steam_api="libsteam_api.so"
- if [ $cmd_release = true ]; then
+ if [ $opt_release = true ]; then
target_opts="-O3"
else
target_opts="-fsanitize=address -ggdb3"
}
compile_x(){
- cmd_setup="$target_compiler -Wall -Wstrict-aliasing=3 -Wno-unused-function $cmd_lib_dir"
- cmd_targets="$1 ${vg_root}/gl/glad.c -o $2$target_ext"
- cmd_final="$target_libs -Wl,-rpath=./ $cmd_defines"
- cmd="$cmd_setup $target_opts $cmd_targets $cmd_final"
+ paths="-I. -L$vg_root/dep/glfw -I$vg_root/dep -I$vg_root/src"
+ setup="$target_compiler -Wall -Wstrict-aliasing=3 -Wno-unused-function $paths"
+ targets="$1 $vg_root/dep/glad/glad.c -o $2$target_ext"
+ final="$target_libs -Wl,-rpath=./ $opt_steam"
+ cmd="$setup $target_opts $targets $final"
- echo "Compile -> $2$target_ext:"
logit " $cmd"
$cmd
fi
success "$2$target_ext built"
- echo ""
}
compile_main(){
- echo ""
- echo "compile_main()"
+ titleit "Main build: $target_dir"
mkdir -p $target_dir
- compile_x fishladder.c $target_dir/$cmd_target
-
- echo "Setting up build structure"
+ compile_x $vg_src $target_dir/$vg_target
+ echo ""
+ logit "Setting up build structure"
# Setup build folder
mkdir $target_dir/cfg -p
mkdir $target_dir/sav -p
# Copy libraries
- cp $vg_root/steam/$target_steam_api $target_dir/$target_steam_api
+ if [ "$opt_steam" != "" ]; then
+ cp $vg_root/dep/steam/$target_steam_api $target_dir/$target_steam_api
+ fi
# Clear and copy assets
rm -r $target_dir/textures
mv $target_dir/.temp_textures $target_dir/textures
cp -r sound $target_dir
cp -r maps $target_dir
-
- success "Build made: $target_dir"
}
compile_tools(){
# These should only be compiled for native platform
- echo ""
- echo "compile_tools()"
- mkdir tools -p
+ titleit "Tools"
+
+ mkdir $vg_root/bin -p
- compile_x $vg_root/fontcomp.c tools/fontcomp
- compile_x $vg_root/texsheet.c tools/texsheet
- compile_x $vg_root/qoiconv.c tools/qoiconv
+ compile_x $vg_root/src/fontcomp.c $vg_root/bin/fontcomp
+ compile_x $vg_root/src/texsheet.c $vg_root/bin/texsheet
+ compile_x $vg_root/src/qoiconv.c $vg_root/bin/qoiconv
}
compile_assets(){
- echo ""
- echo "compile_assets()"
+ titleit "Assets"
[[ -d .temp_textures ]] && rm -r .temp_textures
mkdir .temp_textures
echo "Compile textures:"
for f in textures/*.png;
do logit " qoi: $f";
- ./tools/qoiconv$target_ext $f .temp_textures/"$(basename "$f" .png).qoi"
+ $vg_root/bin/qoiconv$target_ext $f .temp_textures/"$(basename "$f" .png).qoi"
done
# Autocombine textures
do logit " combine: $f";
auto_combine="$auto_combine $f"
done
- ../tools/texsheet$taget_ext ../.temp_textures/autocombine.qoi ../sprites_autocombine.h sprites_auto_combine $auto_combine
+ $vg_root/bin/texsheet$taget_ext ../.temp_textures/autocombine.qoi ../sprites_autocombine.h sprites_auto_combine $auto_combine
cd ..
# Compile font file
echo ""
echo "Compile fonts:"
- ./tools/fontcomp$target_ext $vg_root/fonts/vg_font.png $vg_root/vg/vg_pxfont.h
+ $vg_root/bin/fontcomp$target_ext $vg_root/src/fonts/vg_font.png $vg_root/src/vg/vg_pxfont.h
}
# ==============================================================
# Compile process
if [[ "$OSTYPE" != "linux-gnu"* ]]; then
- echo "Host: Microsoft Windows (implied)"
- host_is_linux=false
+ host_os=win32
target_os_windows
else
- echo "Host: GNU/Linux"
- host_is_linux=true
+ host_os=linux
target_os_linux
fi
-# Main compile loop
-while (( "$#" )); do
- case $1 in
- -r|--release)
- cmd_release=true
- ;;
- -s|--no-steam)
- cmd_defines="-DVG_NO_STEAM"
- ;;
- -t|--tools)
- compile_tools
- ;;
- -a|-assets)
- compile_assets
- ;;
- --build-linux)
- target_os_linux
- compile_main
- ;;
- --build-windows)
- target_os_windows
- compile_main
-
- # Extra glfw.dll copy step
- cp $vg_root/glfw/glfw3.dll $target_dir/glfw3.dll
- ;;
+options=rptlwa
+longopts=release,build-linux,build-windows,steam,play,build-tools,assets,full
+parsed=$(getopt --options=$options --longoptions=$longopts --name "vgc" -- "$@")
+
+if [ $? -ne 0 ]; then
+ error "getopt failed"
+ exit 1
+fi
+
+eval set -- "$parsed"
+while true; do
+ case "$1" in
+ -a|--assets)
+ opt_assets=true
+ shift;
+ ;;
+ -r|--release)
+ opt_release=true
+ shift;
+ ;;
-p|--play)
- if [ $host_is_linux ]; then
- target_os_linux
- else
- target_os_windows
- fi
-
- echo ""
- logit "======= exec: $target_dir/$cmd_target$target_ext ======="
- echo ""
-
- cd $target_dir
- ./$cmd_target
- cd ./../
- ;;
- *)
- echo "Unkown param: $1"
- exit 1
- ;;
- esac
- shift
+ opt_play=true
+ shift;
+ ;;
+ -l|--build-linux)
+ opt_linux=true
+ shift;
+ ;;
+ -w|--build-windows)
+ opt_windows=true
+ shift;
+ ;;
+ -t|--build-tools)
+ opt_tools=true
+ shift;
+ ;;
+ --full)
+ opt_full=true
+ opt_assets=true
+ opt_release=true
+ opt_play=true
+ opt_linux=true
+ opt_windows=true
+ opt_tools=true
+ shift;
+ ;;
+ --steam)
+ opt_steam="-DVG_STEAM"
+ shift;
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ error "programming error"
+ break
+ ;;
+ esac
done
-# Cleanup
-logit "cleaning up..."
+titleit " vgc ver: $vg_version\n host: $host_os"
+logit " assets: $opt_assets"
+logit " release: $opt_release"
+logit " play: $opt_play"
+logit " build-linux: $opt_linux"
+logit "build-windows: $opt_windows"
+logit " build-tools: $opt_tools"
+logit " steam: $opt_steam"
+
+# Main build steps
+
+if [ $opt_tools = true ]; then compile_tools; fi
+if [ $opt_assets = true ]; then compile_assets; fi
+if [ $opt_linux = true ]; then target_os_linux; compile_main; fi
+if [ $opt_windows = true ]; then
+ target_os_windows
+ compile_main
+
+ cp $vg_root/dep/glfw/glfw3.dll $target_dir/glfw3.dll
+fi
+
+if [ $opt_play = true ]; then
+
+ if [ $host_os = linux ]; then
+ target_os_linux
+ else
+ target_os_windows
+ fi
+
+ echo ""
+ logit "======= exec: $target_dir/$vg_target$target_ext ======="
+ echo ""
+
+ cd $target_dir
+ ./$vg_target$target_ext
+ cd ./../
+
+fi