platform utils
[vg.git] / vg_compiler.sh
index 89007f914d403c263a35297f22d959ccc117a25f..899a04a641f72e10a3d85247f9ed7d372f13d6b3 100755 (executable)
@@ -3,7 +3,7 @@
 
 vg_root=`readlink $0`
 vg_root=`dirname $vg_root`
-vg_version="0.1"
+vg_version="0.2"
 
 opt_assets=false
 opt_release=false
@@ -11,11 +11,13 @@ opt_play=false
 opt_linux=false
 opt_windows=false
 opt_tools=false
-opt_full=false
 opt_recompile_mini_audio=false
-opt_gcc=""
 opt_steam=""
 
+target_platform_include=""
+target_standard="-std=c99"
+target_link_steam=false
+
 # Util
 # ===========================================
 error(){
@@ -55,10 +57,13 @@ checkfatal(){
 target_os_windows(){
    target_ext=".exe"
    target_compiler="i686-w64-mingw32-gcc"
-       target_libs="-lglfw3 -lopengl32 -lm -mwindows $vg_root/dep/steam/steam_api.dll"
+       target_libs="-lglfw3 -lopengl32 -lm -mwindows"
+   target_libs_steam="$vg_root/dep/steam/steam_api.dll"
    target_dir="build.win32"
        target_steam_api="steam_api.dll"
    target_miniaudio="$vg_root/dep/dr_soft/miniaudio_win32.o"
+   target_platform_include=""
+
    if [ $opt_release = true ]; then
       target_opts="-O3"
    else
@@ -69,12 +74,10 @@ target_os_windows(){
 target_os_linux(){
    target_ext=""
    target_compiler="gcc"
-   target_libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl -static-libgcc"
-   
-   if [ "$opt_steam" != "" ]; then
-      target_libs="$target_libs -lsteam_api"
-   fi
-
+   target_libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -pthread -lXi -ldl"
+   target_libs_steam="-lsteam_api"
+   #target_platform_include="-include $vg_root/platformutils/force_link_glibc_2.23.h"
+   target_platform_include=""
    target_dir="build.linux"
    target_steam_api="libsteam_api.so"
    target_miniaudio="$vg_root/dep/dr_soft/miniaudio_linux.o"
@@ -86,23 +89,42 @@ target_os_linux(){
 }
 
 precompile_x(){
-   cmd="$target_compiler -std=c99 -O3 -Wall -Wstrict-aliasing=3 -c $1 -o $2.o"
+   sources="$1"
+   output="-o $2"
+   cmd="$target_compiler -D_REENTRANT $target_standard $target_opts $target_platform_include
+        -c $sources
+        $output"
 
    logit "    $cmd"
    $cmd
 
    checkfatal
-   success "$2.o built"
+   success "$2 built"
 }
 
 compile_x(){
-   paths="-I. -L./ -L$vg_root/dep/glfw -L$vg_root/dep/steam -I$vg_root/dep -I$vg_root/src"
-   setup="$target_compiler -std=c99 $opt_gcc -Wall -Wstrict-aliasing=3 -Wno-unused-function $paths"
-   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"
+   include="-I. -I$vg_root/dep -I$vg_root/src"
+   libs="-L./ -L$vg_root/dep/glfw -L$vg_root/dep/steam"
 
-   logit "    $cmd"
+   steam_part=""
+   if [ "$opt_steam" != "" ]; then
+      steam_part="$opt_steam $target_libs_steam"
+   fi
+
+   warnings="-Wall -Wstrict-aliasing=3 -Wno-unused-function"
+   sources="$1 $vg_root/dep/glad/glad.c $target_miniaudio"
+   output="-o $2$target_ext"
+
+   cmd="$target_compiler -D_REENTRANT $target_standard $target_opts $target_platform_include
+        $warnings
+        $include
+        $libs
+        $sources
+        $output
+        $target_libs $steam_part
+        -Wl,-rpath=./"
+
+   logit "    $cmd\n"
    $cmd
    
    checkfatal
@@ -112,6 +134,10 @@ compile_x(){
 compile_main(){
    titleit "Main build: $target_dir"
    mkdir -p $target_dir
+   
+   if [ "$opt_recompile_mini_audio" == true ]; then
+      precompile_x $vg_root/dep/dr_soft/miniaudio_impl.c $target_miniaudio
+   fi
 
    compile_x $vg_src $target_dir/$vg_target
    echo ""
@@ -146,9 +172,14 @@ compile_tools(){
 
        mkdir $vg_root/bin -p
    
+   steam_prev=$opt_steam
+   opt_steam=""
+
    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
+
+   opt_steam=$steam_prev
 }
 
 compile_assets(){
@@ -181,15 +212,10 @@ compile_assets(){
    $vg_root/bin/fontcomp$target_ext $vg_root/src/fonts/vg_font.png $vg_root/src/vg/vg_pxfont.h
 }
 
-recompile_miniaudio(){
-   precompile_x $vg_root/dep/dr_soft/miniaudio_impl.c $target_miniaudio
-}
-
 # ==============================================================
 # Compile process
 
-
-options=rptlwaq
+options=rptlwa
 longopts=release,build-linux,build-windows,steam,play,build-tools,assets,full,miniaudio,template
 parsed=$(getopt --options=$options --longoptions=$longopts --name "vgc" -- "$@")
 
@@ -201,10 +227,6 @@ fi
 eval set -- "$parsed"
 while true; do
    case "$1" in
-      -q)
-         opt_gcc=""
-         shift;
-         ;;
       -a|--assets)
          opt_assets=true
          shift;
@@ -230,13 +252,13 @@ while true; do
          shift;
          ;;
       --full)
-         opt_full=true
          opt_assets=true
          opt_release=true
-         opt_play=true
          opt_linux=true
          opt_windows=true
          opt_tools=true
+         opt_steam="-DVG_STEAM"
+         opt_recompile_mini_audio=true
          shift;
          ;;
       --miniaudio)
@@ -302,9 +324,6 @@ logit "    miniaudio: $opt_recompile_mini_audio"
 
 # Main build steps
 
-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 
    target_os_windows 
@@ -312,6 +331,8 @@ if [ $opt_windows = true ]; then
 
    cp $vg_root/dep/glfw/glfw3.dll $target_dir/glfw3.dll
 fi
+if [ $opt_tools = true ]; then detect_os; compile_tools; fi
+if [ $opt_assets = true ]; then compile_assets; fi
 
 if [ $opt_play = true ]; then