2 # Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
5 vg_root
=`dirname $vg_root`
15 opt_recompile_mini_audio
=false
20 # ===========================================
22 echo -e "\033[1;31mError:\e[0m $@"
27 echo -e "\033[1;33mWarning:\e[0m $@"
31 echo -e "\033[1;32mSuccess:\e[0m $@"
35 echo -e "\033[0;37m$@\e[0m"
40 echo -e "\033[1;35m$@\e[0m"
41 echo "=========================="
47 error
"compiler signaled fail"
53 # ===========================================
57 target_compiler
="i686-w64-mingw32-gcc"
58 target_libs
="-lglfw3 -lopengl32 -lm -mwindows $vg_root/dep/steam/steam_api.dll"
59 target_dir
="build.win32"
60 target_steam_api
="steam_api.dll"
61 target_miniaudio
="$vg_root/dep/dr_soft/miniaudio_win32.o"
62 if [ $opt_release = true
]; then
72 target_libs
="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl -static-libgcc"
74 if [ "$opt_steam" != "" ]; then
75 target_libs
="$target_libs -lsteam_api"
78 target_dir
="build.linux"
79 target_steam_api
="libsteam_api.so"
80 target_miniaudio
="$vg_root/dep/dr_soft/miniaudio_linux.o"
81 if [ $opt_release = true
]; then
84 target_opts
="-O0 -fsanitize=address -ggdb3 -fno-omit-frame-pointer"
89 cmd
="$target_compiler -O3 -Wall -Wstrict-aliasing=3 -c $1 -o $2.o"
99 paths
="-I. -L./ -L$vg_root/dep/glfw -L$vg_root/dep/steam -I$vg_root/dep -I$vg_root/src"
100 setup
="$target_compiler $opt_gcc -Wall -Wstrict-aliasing=3 -Wno-unused-function $paths"
101 targets
="$1 $vg_root/dep/glad/glad.c $target_miniaudio -o $2$target_ext"
102 final
="$target_libs -Wl,-rpath=./ $opt_steam"
103 cmd
="$setup $target_opts $targets $final"
109 success
"$2$target_ext built"
113 titleit
"Main build: $target_dir"
116 compile_x
$vg_src $target_dir/$vg_target
118 logit
"Setting up build structure"
121 mkdir
$target_dir/cfg
-p
122 mkdir
$target_dir/textures
-p
123 mkdir
$target_dir/sound
-p
124 mkdir
$target_dir/maps
-p
125 mkdir
$target_dir/sav
-p
128 if [ "$opt_steam" != "" ]; then
129 cp $vg_root/dep
/steam
/$target_steam_api $target_dir/$target_steam_api
132 # Clear and copy assets
133 rm -r $target_dir/textures
134 rm -r $target_dir/sound
135 rm -r $target_dir/maps
137 cp -r .temp_textures
$target_dir
138 mv $target_dir/.temp_textures
$target_dir/textures
139 cp -r sound
$target_dir
140 cp -r maps
$target_dir
144 # These should only be compiled for native platform
147 mkdir
$vg_root/bin
-p
149 compile_x
$vg_root/src
/fontcomp.c
$vg_root/bin
/fontcomp
150 compile_x
$vg_root/src
/texsheet.c
$vg_root/bin
/texsheet
151 compile_x
$vg_root/src
/qoiconv.c
$vg_root/bin
/qoiconv
156 [[ -d .temp_textures
]] && rm -r .temp_textures
159 # Convert all png to qoi
160 echo "Compile textures:"
161 for f
in textures
/*.png
;
163 $vg_root/bin
/qoiconv
$target_ext $f .temp_textures
/"$(basename "$f" .png).qoi"
166 # Autocombine textures
172 do logit
" combine: $f";
173 auto_combine
="$auto_combine $f"
175 $vg_root/bin
/texsheet
$taget_ext ..
/.temp_textures
/autocombine.qoi ..
/sprites_autocombine.h sprites_auto_combine
$auto_combine
180 echo "Compile fonts:"
181 $vg_root/bin
/fontcomp
$target_ext $vg_root/src
/fonts
/vg_font.png
$vg_root/src
/vg
/vg_pxfont.h
184 recompile_miniaudio
(){
185 precompile_x
$vg_root/dep
/dr_soft
/miniaudio_impl.c
$target_miniaudio
188 # ==============================================================
193 longopts
=release
,build-linux
,build-windows
,steam
,play
,build-tools
,assets
,full
,miniaudio
,template
194 parsed
=$
(getopt
--options=$options --longoptions=$longopts --name "vgc" -- "$@")
196 if [ $?
-ne 0 ]; then
197 error
"getopt failed"
201 eval set -- "$parsed"
243 opt_recompile_mini_audio
=true
247 opt_steam
="-DVG_STEAM"
252 if [ -f "main.c" ]; then error
"main.c already exists";
253 elif [ -f "vg_config.h" ]; then error
"vg_config.h already exists";
254 elif [ -f "vg.conf" ]; then error
"vg.conf already exists";
256 cp $vg_root/src
/template
/main.c main.c
257 cp $vg_root/src
/template
/vg_config.h vg_config.h
258 cp $vg_root/src
/template
/vg.conf vg.conf
268 error
"programming error"
274 if [[ -f vg.conf
]]; then
277 error
"Directory is not a VG project"
282 if [[ "$OSTYPE" != "linux-gnu"* ]]; then
293 titleit
" vgc ver: $vg_version\n host: $host_os"
294 logit
" assets: $opt_assets"
295 logit
" release: $opt_release"
296 logit
" play: $opt_play"
297 logit
" build-linux: $opt_linux"
298 logit
"build-windows: $opt_windows"
299 logit
" build-tools: $opt_tools"
300 logit
" steam: $opt_steam"
301 logit
" miniaudio: $opt_recompile_mini_audio"
305 if [ $opt_recompile_mini_audio = true
]; then recompile_miniaudio
; fi
306 if [ $opt_tools = true
]; then detect_os
; compile_tools
; fi
307 if [ $opt_assets = true
]; then compile_assets
; fi
308 if [ $opt_linux = true
]; then target_os_linux
; compile_main
; fi
309 if [ $opt_windows = true
]; then
313 cp $vg_root/dep
/glfw
/glfw3.dll
$target_dir/glfw3.dll
316 if [ $opt_play = true
]; then
318 if [ $host_os = linux
]; then
325 logit
"======= exec: $target_dir/$vg_target$target_ext ======="
329 .
/$vg_target$target_ext