cross compile build script
authorhgn <hgodden00@gmail.com>
Fri, 28 Jan 2022 07:34:08 +0000 (07:34 +0000)
committerhgn <hgodden00@gmail.com>
Fri, 28 Jan 2022 07:34:08 +0000 (07:34 +0000)
.gitignore
build.sh
fishladder.c
vg/vg_vector.h [deleted file]

index 42c290c13e0b582c2d1f6af1cd3667b5b1829ce5..2f78cd6c039050a080426f155c806b6071e8cf28 100755 (executable)
@@ -8,6 +8,7 @@
 build.linux/
 build.win32/
 restricted/
+.temp_textures/
 
 # ALLOW ============================
 !.gitattributes
index 2a31674e6ef11eebcc4fcfe9c7dce4b209b8d52c..9eb56fad4ba8f05fbfd2220ac84733caf79a28ed 100755 (executable)
--- a/build.sh
+++ b/build.sh
 # Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
 
-src="fishladder.c"
-target="fishladder"
-lib="-I. -L./lib -L./"
-libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl"
-steam_part="-l:steam/libsteam_api.so"
-flags="-fsanitize=address -ggdb3 -Wno-unused-function"
-build_dir="build.linux"
-steam_api="libsteam_api.so"
+cmd_lib_dir="-I. -L./lib -L./"
+cmd_release=false
+cmd_defines=""
+cmd_target="fishladder"
+
+# Util
+# ===========================================
+error(){
+    echo -e "\033[1;31mError:\e[0m $@"
+    exit 1
+}
+
+warning(){
+    echo -e "\033[1;33mWarning:\e[0m $@"
+}
+
+success(){
+   echo -e "\033[1;32mSuccess:\e[0m $@"
+}
+
+logit(){
+   echo -e "\033[0;37m$@\e[0m"
+}
+
+# Platforms
+# ===========================================
+
+target_os_windows(){
+   target_ext=".exe"
+   target_compiler="i686-w64-mingw32-gcc"
+       target_libs="-lglfw3 -lopengl32 -lm -mwindows"
+   target_dir="build.win32"
+       target_steam_api="steam_api.dll"
+   if [ $cmd_release = true ]; then
+      target_opts="-O3"
+   else
+      target_opts="-ggdb3"
+   fi
+}
+
+target_os_linux(){
+   target_ext=""
+   target_compiler="gcc"
+   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
+      target_opts="-O3"
+   else
+      target_opts="-fsanitize=address -ggdb3"
+   fi
+}
+
+compile_x(){
+   cmd_setup="$target_compiler -Wall -Wstrict-aliasing=3 -Wno-unused-function $cmd_lib_dir"
+   cmd_targets="$1 gl/glad.c -o $2$target_ext"
+   cmd_final="$target_libs -Wl,-rpath=./ $cmd_defines"
+   cmd="$cmd_setup $target_opts $cmd_targets $cmd_final"
+
+   echo "Compile -> $2$target_ext:"
+   logit "    $cmd"
+   $cmd
+   
+       if [ $? -ne 0 ]; then
+               error "compiler signaled fail"
+               exit 1
+       fi
 
-if [[ "$OSTYPE" != "linux-gnu"* ]]; then
-       echo "Operating system is not GNU/Linux, windows will be assumed."
+       success "$2$target_ext built"
+   echo ""
+}
 
-       target="fishladder.exe"
-       libs="-lglfw3 -lopengl32 -lm -mwindows"
-       flags="-ggdb3 -Wno-unused-function"
-       build_dir="build.win32"
-       steam_api="steam_api.dll"
-fi
+compile_main(){
+   echo ""
+   echo "compile_main()"
+   mkdir -p $target_dir
+
+   compile_x fishladder.c $target_dir/$cmd_target
+
+   echo "Setting up build structure"
+
+   # Setup build folder
+   mkdir $target_dir/cfg -p
+   mkdir $target_dir/textures -p
+   mkdir $target_dir/sound -p
+   mkdir $target_dir/maps -p
+   mkdir $target_dir/sav -p
+
+   # Copy libraries
+   cp steam/$target_steam_api $target_dir/$target_steam_api
 
-run_after=false
-do_build=true
-compile_tools=false
-#compile_models=false
+   # Clear and copy assets
+   rm -r $target_dir/textures
+   rm -r $target_dir/sound
+   rm -r $target_dir/maps
 
+   cp -r .temp_textures $target_dir
+   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
+   
+   compile_x fontcomp.c tools/fontcomp
+   compile_x texsheet.c tools/texsheet
+   compile_x qoiconv.c tools/qoiconv
+}
+
+compile_assets(){
+   echo ""
+   echo "compile_assets()"
+   [[ -d .temp_textures ]] && rm -r .temp_textures
+   mkdir .temp_textures
+   
+   # Convert all png to qoi
+   echo "Compile textures:"
+   for f in textures/*.png;
+      do logit "  qoi: $f";
+      ./tools/qoiconv$target_ext $f .temp_textures/"$(basename "$f" .png).qoi"
+   done
+
+   # Autocombine textures
+   echo "  [combine]:"
+
+   auto_combine=""
+   cd textures_combine
+   for f in *.png;
+      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
+   cd ..
+
+   # Compile font file
+   echo ""
+   echo "Compile fonts:"
+   ./tools/fontcomp$target_ext fonts/vg_font.png vg/vg_pxfont.h
+}
+
+# ==============================================================
+# Compile process
+
+if [[ "$OSTYPE" != "linux-gnu"* ]]; then
+   echo "Host: Microsoft Windows (implied)"
+   host_is_linux=false
+   target_os_windows
+else
+   echo "Host: GNU/Linux"
+   host_is_linux=true
+   target_os_linux
+fi
+
+# Main compile loop
 while (( "$#" )); do
        case $1 in
                -r|--release) 
-                       flags="-O3 -Wno-unused-function"
-                       echo "Release mode" 
-               ;;
-               -p|--play)
-                       run_after=true 
-                       echo "& Run" 
+         cmd_release=true
+                       echo " + Release Mode" 
                ;;
                -s|--no-steam)
-                       steam_part=""
-                       defines="-DNO_STEAM"
-                       echo "no-steam"
-               ;;
-               -n|--nobuild)
-                       do_build=false
-                       echo "no-build"
+                       cmd_defines="-DVG_NO_STEAM"
+                       echo " + Disable steam"
                ;;
                -t|--tools)
-                       compile_tools=true
-                       echo "build-tools"
+         compile_tools
                ;;
-               #-m|--models)
-               #       compile_models=true
-               #       echo "build-models"
-               #;;
+      -a|-assets)
+         compile_assets
+      ;;
+      --build-linux)
+         target_os_linux
+         compile_main
+      ;;
+      --build-windows)
+         target_os_windows
+         compile_main
+
+         # Extra glfw.dll copy step
+         cp glfw/glfw3.dll $target_dir/glfw3.dll
+      ;;
+      -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
@@ -59,67 +210,5 @@ while (( "$#" )); do
        shift
 done
 
-# Tools
-if [ "$compile_tools" = true ]; then
-       echo "Building tools"
-       mkdir tools -p
-       gcc -Wall -Wstrict-aliasing=3 $lib $flags mdlcomp.c gl/glad.c -o tools/mdlcomp $libs $steam_part -Wl,-rpath=./ $defines
-       gcc -Wall -Wstrict-aliasing=3 $lib $flags fontcomp.c gl/glad.c -o tools/fontcomp $libs $steam_part -Wl,-rpath=./ $defines
-       gcc -Wall -Wstrict-aliasing=3 $lib $flags texsheet.c gl/glad.c -o tools/texsheet $libs $steam_part -Wl,-rpath=./ $defines
-       gcc $lib qoiconv.c -std=c99 -O3 -o tools/qoiconv
-fi
-
-# Resources
-mkdir _temp_textures
-# Convert all png to qoi
-echo "Compiling textures"
-for f in textures/*.png;
-       do echo "-> qoi: $f";
-       ./tools/qoiconv $f ./_temp_textures/"$(basename "$f" .png).qoi"
-done
-
-# Autocombine textures
-auto_combine=""
-cd textures_combine
-for f in *.png;
-       do echo "[combine] $f";
-       auto_combine="$auto_combine $f"
-done
-../tools/texsheet ../_temp_textures/autocombine.qoi ../sprites_autocombine.h sprites_auto_combine $auto_combine
-cd ..
-
-# Compile font file
-./tools/fontcomp fonts/vg_font.png vg/vg_pxfont.h
-
-# Main build
-if [ "$do_build" = true ]; then
-       gcc -Wall -Wstrict-aliasing=3 $lib $flags $src gl/glad.c -o $target $libs $steam_part -Wl,-rpath=./ $defines
-
-       if [ $? -ne 0 ]; then
-               echo "GCC build failed"
-               exit 1
-       fi
-
-       echo "Build succeeded"
-fi
-
-mkdir $build_dir/cfg -p
-mkdir $build_dir/textures -p
-mkdir $build_dir/sound -p
-mkdir $build_dir/maps -p
-mkdir $build_dir/sav -p
-
-cp $target $build_dir/$target
-cp ./steam/$steam_api $build_dir/$steam_api
-rm -r $build_dir/textures
-mv ./_temp_textures/ $build_dir/textures
-cp -r ./sound/ $build_dir
-cp -r ./maps/ $build_dir
-
-if [ "$run_after" = true ]; then
-       echo "Playing"
-
-       cd $build_dir
-       ./$target
-       cd ./../
-fi
+# Cleanup
+logit "cleaning up..."
index b8f6d5ba1d692a126ef5e75761bb93a2488fc325..b6fc80be87a9949d9ddcbb98c9a30685ea40941e 100644 (file)
@@ -2,7 +2,7 @@
 
 #define MARBLE_COMP_VERSION 4
 //#define VG_CAPTURE_MODE
-#define VG_STEAM
+//#define VG_STEAM
 #define VG_STEAM_APPID 1218140U
 #include "vg/vg.h"
 
diff --git a/vg/vg_vector.h b/vg/vg_vector.h
deleted file mode 100644 (file)
index 384fdd9..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
-
-struct vg_vector_vert
-{
-       u16 co[2];      // 8b
-       u16 uv[2];      // 8b
-       u32 colour;             // 4b
-       ui_rect clip;   //64 8
-}