2 # Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
5 vg_root
=`dirname $vg_root`
15 opt_recompile_mini_audio
=false
18 target_platform_include
=""
19 target_standard
="-std=c99"
20 target_link_steam
=false
24 # ===========================================
26 echo -e "\033[1;31mError:\e[0m $@"
31 echo -e "\033[1;33mWarning:\e[0m $@"
35 echo -e "\033[1;32mSuccess:\e[0m $@"
39 echo -e "\033[0;37m$@\e[0m"
44 echo -e "\033[1;35m$@\e[0m"
45 echo "=========================="
51 error
"compiler signaled fail"
57 # ===========================================
61 target_compiler
="i686-w64-mingw32-gcc"
62 target_libs
="-lglfw3dll -lopengl32 -lm -mwindows"
63 target_libs_steam
="$vg_root/dep/steam/steam_api.dll"
64 target_dir
="build.win32"
65 target_steam_api
="steam_api.dll"
66 target_miniaudio
="$vg_root/dep/dr_soft/miniaudio_win32.o"
67 target_platform_include
=""
69 if [ $opt_release = true
]; then
70 target_opts
="-O3 -DVG_RELEASE"
79 target_libs
="-lGL -lglfw3 -lX11 -lXxf86vm -lXrandr -lm -pthread -lXi -ldl"
80 target_libs_steam
="-lsteam_api"
81 #target_platform_include="-include $vg_root/platformutils/force_link_glibc_2.23.h"
82 target_platform_include
=""
83 target_dir
="build.linux"
84 target_steam_api
="libsteam_api.so"
85 target_miniaudio
="$vg_root/dep/dr_soft/miniaudio_linux.o"
86 if [ $opt_release = true
]; then
87 target_opts
="-O3 -DVG_RELEASE"
89 target_opts
="-O0 -fsanitize=address -ggdb3 -fno-omit-frame-pointer"
94 if ! [ -x "$(command -v $target_compiler)" ]; then
95 warning
"Compiler $target_compiler is not installed. Skipping item"
100 cmd
="$target_compiler $target_standard $target_opts $target_platform_include
112 if ! [ -x "$(command -v $target_compiler)" ]; then
113 warning
"Compiler $target_compiler is not installed. Skipping item"
117 include
="-I. -I$vg_root/dep -I$vg_root/src"
118 libs
="-L./ -L$vg_root/dep/glfw -L$vg_root/dep/steam"
121 if [ "$opt_steam" != "" ]; then
122 steam_part
="$opt_steam $target_libs_steam"
125 warnings
="-Wall -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable"
126 sources
="$1 $vg_root/dep/glad/glad.c $target_miniaudio"
127 output
="-o $2$target_ext"
129 cmd
="$target_compiler -D_REENTRANT $target_standard $target_opts $target_platform_include
135 $target_libs $steam_part
142 success
"$2$target_ext built"
146 titleit
"Main build: $target_dir"
149 if [ "$opt_recompile_mini_audio" == true
]; then
150 precompile_x
$vg_root/dep
/dr_soft
/miniaudio_impl.c
$target_miniaudio
153 compile_x
$vg_src $target_dir/$vg_target
155 logit
"Setting up build structure"
158 mkdir
$target_dir/cfg
-p
159 mkdir
$target_dir/textures
-p
160 mkdir
$target_dir/sound
-p
161 mkdir
$target_dir/maps
-p
162 mkdir
$target_dir/sav
-p
165 if [ "$opt_steam" != "" ]; then
166 cp $vg_root/dep
/steam
/$target_steam_api $target_dir/$target_steam_api
171 # These should only be compiled for native platform
174 mkdir
$vg_root/bin
-p
176 steam_prev
=$opt_steam
179 compile_x
$vg_root/src
/fontcomp.c
$vg_root/bin
/fontcomp
180 compile_x
$vg_root/src
/texsheet.c
$vg_root/bin
/texsheet
181 compile_x
$vg_root/src
/qoiconv.c
$vg_root/bin
/qoiconv
182 compile_x
$vg_root/src
/shader.c
$vg_root/bin
/shader
184 opt_steam
=$steam_prev
188 [[ -d .temp_textures
]] && rm -r .temp_textures
191 # Convert all png to qoi
192 echo "Compile textures:"
193 for f
in textures
/*.png
;
195 $vg_root/bin
/qoiconv
$target_ext $f .temp_textures
/"$(basename "$f" .png).qoi"
198 if [[ -d "textures_combine" ]]; then
204 do logit
" combine: $f";
205 auto_combine
="$auto_combine $f"
207 $vg_root/bin
/texsheet
$target_ext ..
/.temp_textures
/autocombine.qoi ..
/sprites_autocombine.h sprites_auto_combine
$auto_combine
213 echo "Compile fonts:"
214 $vg_root/bin
/fontcomp
$target_ext $vg_root/src
/fonts
/vg_font.png
$vg_root/src
/vg
/vg_pxfont.h
216 # Clear and copy assets
217 rm -r $target_dir/textures
218 rm -r $target_dir/sound
219 rm -r $target_dir/maps
221 cp -r .temp_textures
$target_dir
222 mv $target_dir/.temp_textures
$target_dir/textures
223 cp -r sound
$target_dir
224 cp -r maps
$target_dir
225 cp -r models
$target_dir
231 if [[ -d "shaders" ]]; then
233 $vg_root/bin
/shader
$target_ext $target_shaders
239 target_shaders
="$target_shaders $1 $2 $3"
242 # ==============================================================
246 longopts
=release
,build-linux
,build-windows
,steam
,play
,build-tools
,assets
,full
,miniaudio
,template
247 parsed
=$
(getopt
--options=$options --longoptions=$longopts --name "vgc" -- "$@")
249 if [ $?
-ne 0 ]; then
250 error
"getopt failed"
254 eval set -- "$parsed"
292 opt_steam
="-DVG_STEAM"
293 opt_recompile_mini_audio
=true
297 opt_recompile_mini_audio
=true
301 opt_steam
="-DVG_STEAM"
306 if [ -f "main.c" ]; then error
"main.c already exists";
307 elif [ -f "vg_config.h" ]; then error
"vg_config.h already exists";
308 elif [ -f "vg.conf" ]; then error
"vg.conf already exists";
310 cp $vg_root/src
/template
/main.c main.c
311 cp $vg_root/src
/template
/vg_config.h vg_config.h
312 cp $vg_root/src
/template
/vg.conf vg.conf
322 error
"programming error"
328 if [[ -f vg.conf
]]; then
331 error
"Directory is not a VG project"
336 if [[ "$OSTYPE" != "linux-gnu"* ]]; then
347 titleit
" vgc ver: $vg_version\n host: $host_os"
348 logit
" assets: $opt_assets"
349 logit
" shaders: $opt_shaders"
350 logit
" release: $opt_release"
351 logit
" play: $opt_play"
352 logit
" build-linux: $opt_linux"
353 logit
"build-windows: $opt_windows"
354 logit
" build-tools: $opt_tools"
355 logit
" steam: $opt_steam"
356 logit
" miniaudio: $opt_recompile_mini_audio"
360 if [ $opt_tools = true
]; then detect_os
; compile_tools
; fi
361 if [ $opt_assets = true
]; then compile_assets
; fi
362 if [ $opt_shaders = true
]; then compile_shaders
; fi
363 if [ $opt_linux = true
]; then target_os_linux
; compile_main
; fi
364 if [ $opt_windows = true
]; then
368 cp $vg_root/dep
/glfw
/glfw3.dll
$target_dir/glfw3.dll
371 success
"Build completed (check compiler results)"
373 if [ $opt_play = true
]; then
375 if [ $host_os = linux
]; then
382 logit
"======= exec: $target_dir/$vg_target$target_ext ======="
386 .
/$vg_target$target_ext