moved miniaudio to its own compile unit cos its HEFTY
[vg.git] / vg_compiler.sh
index 49a12fd47c765e8cefe4a3f4fb0be05739dbf258..b9ee1abaa1b7996cf696548576d4e5a34c78a0f6 100755 (executable)
@@ -12,6 +12,7 @@ opt_linux=false
 opt_windows=false
 opt_tools=false
 opt_full=false
+opt_recompile_mini_audio=false
 opt_gcc=""
 opt_steam=""
 
@@ -41,6 +42,13 @@ titleit(){
    echo ""
 }
 
+checkfatal(){
+       if [ $? -ne 0 ]; then
+               error "compiler signaled fail"
+               exit 1
+       fi
+}
+
 if [[ -f vg.conf ]]; then
    source vg.conf
 else
@@ -57,6 +65,7 @@ target_os_windows(){
        target_libs="-lglfw3 -lopengl32 -lm -mwindows"
    target_dir="build.win32"
        target_steam_api="steam_api.dll"
+   target_miniaudio="$vg_root/dep/dr_soft/miniaudio_win32.o"
    if [ $opt_release = true ]; then
       target_opts="-O3"
    else
@@ -70,6 +79,7 @@ target_os_linux(){
    target_libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl -lsteam_api"
    target_dir="build.linux"
    target_steam_api="libsteam_api.so"
+   target_miniaudio="$vg_root/dep/dr_soft/miniaudio_linux.o"
    if [ $opt_release = true ]; then
       target_opts="-O3"
    else
@@ -77,21 +87,27 @@ target_os_linux(){
    fi
 }
 
+precompile_x(){
+   cmd="$target_compiler -O3 -Wall -c $1 -o $2.o"
+
+   logit "    $cmd"
+   $cmd
+
+   checkfatal
+   success "$2.o built"
+}
+
 compile_x(){
    paths="-I. -L$vg_root/dep/glfw -L$vg_root/dep/steam -I$vg_root/dep -I$vg_root/src"
    setup="$target_compiler $opt_gcc -Wall -Wstrict-aliasing=3 -Wno-unused-function $paths"
-   targets="$1 $vg_root/dep/glad/glad.c -o $2$target_ext"
+   targets="$1 $vg_root/dep/glad/glad.c $target_miniaudio -o $2$target_ext"
    final="$target_libs -Wl,-rpath=./ $opt_steam"
    cmd="$setup $target_opts $targets $final"
 
    logit "    $cmd"
    $cmd
    
-       if [ $? -ne 0 ]; then
-               error "compiler signaled fail"
-               exit 1
-       fi
-
+   checkfatal
        success "$2$target_ext built"
 }
 
@@ -167,19 +183,20 @@ compile_assets(){
    $vg_root/bin/fontcomp$target_ext $vg_root/src/fonts/vg_font.png $vg_root/src/vg/vg_pxfont.h
 }
 
+recompile_miniaudio(){
+   target_os_windows
+   precompile_x $vg_root/dep/dr_soft/miniaudio_impl.c $vg_root/dep/dr_soft/miniaudio_win32
+
+   target_os_linux
+   precompile_x $vg_root/dep/dr_soft/miniaudio_impl.c $vg_root/dep/dr_soft/miniaudio_linux
+}
+
 # ==============================================================
 # Compile process
 
-if [[ "$OSTYPE" != "linux-gnu"* ]]; then
-   host_os=win32
-   target_os_windows
-else
-   host_os=linux
-   target_os_linux
-fi
 
 options=rptlwaq
-longopts=release,build-linux,build-windows,steam,play,build-tools,assets,full
+longopts=release,build-linux,build-windows,steam,play,build-tools,assets,full,miniaudio
 parsed=$(getopt --options=$options --longoptions=$longopts --name "vgc" -- "$@")
 
 if [ $? -ne 0 ]; then
@@ -228,6 +245,10 @@ while true; do
          opt_tools=true
          shift;
          ;;
+      --miniaudio)
+         opt_recompile_mini_audio=true
+         shift;
+         ;;
       --steam)
          opt_steam="-DVG_STEAM"
          shift;
@@ -243,6 +264,20 @@ while true; do
    esac
 done
 
+detect_os(){
+   if [[ "$OSTYPE" != "linux-gnu"* ]]; then
+      host_os=win32
+      target_os_windows
+   else
+      host_os=linux
+      target_os_linux
+   fi
+}
+
+detect_os
+
+if [ ! -f $vg_root/dep/dr_soft/miniaudio_linux.o ]; then opt_recompile_mini_audio=true; fi
+
 titleit "      vgc ver: $vg_version\n         host: $host_os"
 logit "       assets: $opt_assets"
 logit "      release: $opt_release"
@@ -251,10 +286,12 @@ logit "  build-linux: $opt_linux"
 logit "build-windows: $opt_windows"
 logit "  build-tools: $opt_tools"
 logit "        steam: $opt_steam"
+logit "    miniaudio: $opt_recompile_mini_audio"
 
 # Main build steps
 
-if [ $opt_tools = true ]; then compile_tools; fi
+if [ $opt_recompile_mini_audio = true ]; then recompile_miniaudio; fi
+if [ $opt_tools = true ]; then detect_os; 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