mc 1.9
[vg.git] / vg_compiler.sh
index b9ee1abaa1b7996cf696548576d4e5a34c78a0f6..2573a403abe7d09ae34d9fed0bc86ff0a3bc012e 100755 (executable)
@@ -49,20 +49,13 @@ checkfatal(){
        fi
 }
 
-if [[ -f vg.conf ]]; then
-   source vg.conf
-else
-  error "Directory is not a VG project" 
-  exit 1
-fi
-
 # Platforms
 # ===========================================
 
 target_os_windows(){
    target_ext=".exe"
    target_compiler="i686-w64-mingw32-gcc"
-       target_libs="-lglfw3 -lopengl32 -lm -mwindows"
+       target_libs="-lglfw3 -lopengl32 -lm -mwindows $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"
@@ -76,19 +69,24 @@ target_os_windows(){
 target_os_linux(){
    target_ext=""
    target_compiler="gcc"
-   target_libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl -lsteam_api"
+   target_libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl"
+   
+   if [ "$opt_steam" != "" ]; then
+      target_libs="$target_libs -lsteam_api"
+   fi
+
    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"
+      target_opts="-O0"
    else
-      target_opts="-fsanitize=address -ggdb3"
+      target_opts="-O0 -fsanitize=address -ggdb3 -fno-omit-frame-pointer"
    fi
 }
 
 precompile_x(){
-   cmd="$target_compiler -O3 -Wall -c $1 -o $2.o"
+   cmd="$target_compiler -O3 -Wall -Wstrict-aliasing=3 -c $1 -o $2.o"
 
    logit "    $cmd"
    $cmd
@@ -98,7 +96,7 @@ precompile_x(){
 }
 
 compile_x(){
-   paths="-I. -L$vg_root/dep/glfw -L$vg_root/dep/steam -I$vg_root/dep -I$vg_root/src"
+   paths="-I. -L./ -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 $target_miniaudio -o $2$target_ext"
    final="$target_libs -Wl,-rpath=./ $opt_steam"
@@ -196,7 +194,7 @@ recompile_miniaudio(){
 
 
 options=rptlwaq
-longopts=release,build-linux,build-windows,steam,play,build-tools,assets,full,miniaudio
+longopts=release,build-linux,build-windows,steam,play,build-tools,assets,full,miniaudio,template
 parsed=$(getopt --options=$options --longoptions=$longopts --name "vgc" -- "$@")
 
 if [ $? -ne 0 ]; then
@@ -251,6 +249,19 @@ while true; do
          ;;
       --steam)
          opt_steam="-DVG_STEAM"
+         shift;
+         ;;
+      --template)
+         
+         if [ -f "main.c" ]; then error "main.c already exists";
+         elif [ -f "vg_config.h" ]; then error "vg_config.h already exists";
+         elif [ -f "vg.conf" ]; then error "vg.conf already exists";
+         else
+            cp $vg_root/src/template/main.c main.c
+            cp $vg_root/src/template/vg_config.h vg_config.h
+            cp $vg_root/src/template/vg.conf vg.conf
+         fi
+
          shift;
          ;;
       --)
@@ -264,6 +275,13 @@ while true; do
    esac
 done
 
+if [[ -f vg.conf ]]; then
+   source vg.conf
+else
+  error "Directory is not a VG project" 
+  exit 1
+fi
+
 detect_os(){
    if [[ "$OSTYPE" != "linux-gnu"* ]]; then
       host_os=win32