2 # Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
5 vg_root
=`dirname $vg_root`
14 opt_recompile_mini_audio
=false
17 target_platform_include
=""
18 target_standard
="-std=c99"
19 target_link_steam
=false
22 # ===========================================
24 echo -e "\033[1;31mError:\e[0m $@"
29 echo -e "\033[1;33mWarning:\e[0m $@"
33 echo -e "\033[1;32mSuccess:\e[0m $@"
37 echo -e "\033[0;37m$@\e[0m"
42 echo -e "\033[1;35m$@\e[0m"
43 echo "=========================="
49 error
"compiler signaled fail"
55 # ===========================================
59 target_compiler
="i686-w64-mingw32-gcc"
60 target_libs
="-lglfw3dll -lopengl32 -lm -mwindows"
61 target_libs_steam
="$vg_root/dep/steam/steam_api.dll"
62 target_dir
="build.win32"
63 target_steam_api
="steam_api.dll"
64 target_miniaudio
="$vg_root/dep/dr_soft/miniaudio_win32.o"
65 target_platform_include
=""
67 if [ $opt_release = true
]; then
77 target_libs
="-lGL -lglfw3 -lX11 -lXxf86vm -lXrandr -lm -pthread -lXi -ldl"
78 target_libs_steam
="-lsteam_api"
79 #target_platform_include="-include $vg_root/platformutils/force_link_glibc_2.23.h"
80 target_platform_include
=""
81 target_dir
="build.linux"
82 target_steam_api
="libsteam_api.so"
83 target_miniaudio
="$vg_root/dep/dr_soft/miniaudio_linux.o"
84 if [ $opt_release = true
]; then
87 target_opts
="-O1 -fsanitize=address -ggdb3 -fno-omit-frame-pointer"
92 if ! [ -x "$(command -v $target_compiler)" ]; then
93 warning
"Compiler $target_compiler is not installed. Skipping item"
98 cmd
="$target_compiler -D_REENTRANT $target_standard $target_opts $target_platform_include
110 if ! [ -x "$(command -v $target_compiler)" ]; then
111 warning
"Compiler $target_compiler is not installed. Skipping item"
115 include
="-I. -I$vg_root/dep -I$vg_root/src"
116 libs
="-L./ -L$vg_root/dep/glfw -L$vg_root/dep/steam"
119 if [ "$opt_steam" != "" ]; then
120 steam_part
="$opt_steam $target_libs_steam"
123 warnings
="-Wall -Wstrict-aliasing=3 -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable"
124 sources
="$1 $vg_root/dep/glad/glad.c $target_miniaudio"
125 output
="-o $2$target_ext"
127 cmd
="$target_compiler -D_REENTRANT $target_standard $target_opts $target_platform_include
133 $target_libs $steam_part
140 success
"$2$target_ext built"
144 titleit
"Main build: $target_dir"
147 if [ "$opt_recompile_mini_audio" == true
]; then
148 precompile_x
$vg_root/dep
/dr_soft
/miniaudio_impl.c
$target_miniaudio
151 compile_x
$vg_src $target_dir/$vg_target
153 logit
"Setting up build structure"
156 mkdir
$target_dir/cfg
-p
157 mkdir
$target_dir/textures
-p
158 mkdir
$target_dir/sound
-p
159 mkdir
$target_dir/maps
-p
160 mkdir
$target_dir/sav
-p
163 if [ "$opt_steam" != "" ]; then
164 cp $vg_root/dep
/steam
/$target_steam_api $target_dir/$target_steam_api
167 # Clear and copy assets
168 rm -r $target_dir/textures
169 rm -r $target_dir/sound
170 rm -r $target_dir/maps
172 cp -r .temp_textures
$target_dir
173 mv $target_dir/.temp_textures
$target_dir/textures
174 cp -r sound
$target_dir
175 cp -r maps
$target_dir
176 cp -r models
$target_dir
180 # These should only be compiled for native platform
183 mkdir
$vg_root/bin
-p
185 steam_prev
=$opt_steam
188 compile_x
$vg_root/src
/fontcomp.c
$vg_root/bin
/fontcomp
189 compile_x
$vg_root/src
/texsheet.c
$vg_root/bin
/texsheet
190 compile_x
$vg_root/src
/qoiconv.c
$vg_root/bin
/qoiconv
192 opt_steam
=$steam_prev
197 [[ -d .temp_textures
]] && rm -r .temp_textures
200 # Convert all png to qoi
201 echo "Compile textures:"
202 for f
in textures
/*.png
;
204 $vg_root/bin
/qoiconv
$target_ext $f .temp_textures
/"$(basename "$f" .png).qoi"
207 if [[ -d "textures_combine" ]]; then
208 # Autocombine textures
214 do logit
" combine: $f";
215 auto_combine
="$auto_combine $f"
217 $vg_root/bin
/texsheet
$taget_ext ..
/.temp_textures
/autocombine.qoi ..
/sprites_autocombine.h sprites_auto_combine
$auto_combine
223 echo "Compile fonts:"
224 $vg_root/bin
/fontcomp
$target_ext $vg_root/src
/fonts
/vg_font.png
$vg_root/src
/vg
/vg_pxfont.h
227 # ==============================================================
231 longopts
=release
,build-linux
,build-windows
,steam
,play
,build-tools
,assets
,full
,miniaudio
,template
232 parsed
=$
(getopt
--options=$options --longoptions=$longopts --name "vgc" -- "$@")
234 if [ $?
-ne 0 ]; then
235 error
"getopt failed"
239 eval set -- "$parsed"
272 opt_steam
="-DVG_STEAM"
273 opt_recompile_mini_audio
=true
277 opt_recompile_mini_audio
=true
281 opt_steam
="-DVG_STEAM"
286 if [ -f "main.c" ]; then error
"main.c already exists";
287 elif [ -f "vg_config.h" ]; then error
"vg_config.h already exists";
288 elif [ -f "vg.conf" ]; then error
"vg.conf already exists";
290 cp $vg_root/src
/template
/main.c main.c
291 cp $vg_root/src
/template
/vg_config.h vg_config.h
292 cp $vg_root/src
/template
/vg.conf vg.conf
302 error
"programming error"
308 if [[ -f vg.conf
]]; then
311 error
"Directory is not a VG project"
316 if [[ "$OSTYPE" != "linux-gnu"* ]]; then
327 titleit
" vgc ver: $vg_version\n host: $host_os"
328 logit
" assets: $opt_assets"
329 logit
" release: $opt_release"
330 logit
" play: $opt_play"
331 logit
" build-linux: $opt_linux"
332 logit
"build-windows: $opt_windows"
333 logit
" build-tools: $opt_tools"
334 logit
" steam: $opt_steam"
335 logit
" miniaudio: $opt_recompile_mini_audio"
339 if [ $opt_tools = true
]; then detect_os
; compile_tools
; fi
340 if [ $opt_assets = true
]; then compile_assets
; fi
341 if [ $opt_linux = true
]; then target_os_linux
; compile_main
; fi
342 if [ $opt_windows = true
]; then
346 cp $vg_root/dep
/glfw
/glfw3.dll
$target_dir/glfw3.dll
349 success
"Build completed (check compiler results)"
351 if [ $opt_play = true
]; then
353 if [ $host_os = linux
]; then
360 logit
"======= exec: $target_dir/$vg_target$target_ext ======="
364 .
/$vg_target$target_ext