bad char
[vg.git] / vg_compiler.sh
diff --git a/vg_compiler.sh b/vg_compiler.sh
deleted file mode 100755 (executable)
index 11a4298..0000000
+++ /dev/null
@@ -1,332 +0,0 @@
-#!/bin/bash
-# Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
-
-vg_root=`readlink $0`
-vg_root=`dirname $vg_root`
-vg_version="0.1"
-
-opt_assets=false
-opt_release=false
-opt_play=false
-opt_linux=false
-opt_windows=false
-opt_tools=false
-opt_full=false
-opt_recompile_mini_audio=false
-opt_gcc=""
-opt_steam=""
-
-# 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"
-}
-
-titleit(){
-   echo ""
-   echo -e "\033[1;35m$@\e[0m"
-   echo "=========================="
-   echo ""
-}
-
-checkfatal(){
-       if [ $? -ne 0 ]; then
-               error "compiler signaled fail"
-               exit 1
-       fi
-}
-
-# Platforms
-# ===========================================
-
-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_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
-      target_opts="-ggdb3"
-   fi
-}
-
-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_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
-      target_opts="-O0 -fsanitize=address -ggdb3 -fno-omit-frame-pointer"
-   fi
-}
-
-precompile_x(){
-   cmd="$target_compiler -std=c99 -O3 -Wall -Wstrict-aliasing=3 -c $1 -o $2.o"
-
-   logit "    $cmd"
-   $cmd
-
-   checkfatal
-   success "$2.o 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 $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"
-
-   logit "    $cmd"
-   $cmd
-   
-   checkfatal
-       success "$2$target_ext built"
-}
-
-compile_main(){
-   titleit "Main build: $target_dir"
-   mkdir -p $target_dir
-
-   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/textures -p
-   mkdir $target_dir/sound -p
-   mkdir $target_dir/maps -p
-   mkdir $target_dir/sav -p
-
-   # Copy libraries
-   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
-   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
-}
-
-compile_tools(){
-   # These should only be compiled for native platform
-   titleit "Tools"
-
-       mkdir $vg_root/bin -p
-   
-   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(){
-   titleit "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";
-      $vg_root/bin/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
-   $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:"
-   $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
-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
-   error "getopt failed"
-   exit 1
-fi
-
-eval set -- "$parsed"
-while true; do
-   case "$1" in
-      -q)
-         opt_gcc=""
-         shift;
-         ;;
-      -a|--assets)
-         opt_assets=true
-         shift;
-         ;;
-      -r|--release)
-         opt_release=true
-         shift;
-         ;;
-      -p|--play)
-         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;
-         ;;
-      --miniaudio)
-         opt_recompile_mini_audio=true
-         shift;
-         ;;
-      --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;
-         ;;
-      --)
-         shift
-         break
-         ;;
-      *)
-         error "programming error"
-         break
-         ;;
-   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
-      target_os_windows
-   else
-      host_os=linux
-      target_os_linux
-   fi
-}
-
-detect_os
-
-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"
-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 
-   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