63f64def69addf806e2e5df32f4bc098604bd94a
[fishladder.git] / build.sh
1 # Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
2
3 src="fishladder.c"
4 target="fishladder"
5 lib="-I. -L./lib -L./"
6 libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl"
7 steam_part="-l:steam/libsteam_api.so"
8 flags="-fsanitize=address -ggdb3 -Wno-unused-function"
9 build_dir="build.linux"
10 steam_api="libsteam_api.so"
11
12 if [[ "$OSTYPE" != "linux-gnu"* ]]; then
13 echo "Operating system is not GNU/Linux, windows will be assumed."
14
15 target="fishladder.exe"
16 libs="-lglfw3 -lopengl32 -lm -mwindows"
17 flags="-ggdb3 -Wno-unused-function"
18 build_dir="build.win32"
19 steam_api="steam_api.dll"
20 fi
21
22 run_after=false
23 do_build=true
24 compile_tools=false
25 #compile_models=false
26
27 while (( "$#" )); do
28 case $1 in
29 -r|--release)
30 flags="-O3 -Wno-unused-function"
31 echo "Release mode"
32 ;;
33 -p|--play)
34 run_after=true
35 echo "& Run"
36 ;;
37 -s|--no-steam)
38 steam_part=""
39 defines="-DNO_STEAM"
40 echo "no-steam"
41 ;;
42 -n|--nobuild)
43 do_build=false
44 echo "no-build"
45 ;;
46 -t|--tools)
47 compile_tools=true
48 echo "build-tools"
49 ;;
50 #-m|--models)
51 # compile_models=true
52 # echo "build-models"
53 #;;
54 *)
55 echo "Unkown param: $1"
56 exit 1
57 ;;
58 esac
59 shift
60 done
61
62 # Tools
63 if [ "$compile_tools" = true ]; then
64 echo "Building tools"
65 mkdir tools -p
66 gcc -Wall -Wstrict-aliasing=3 $lib $flags mdlcomp.c gl/glad.c -o tools/mdlcomp $libs $steam_part -Wl,-rpath=./ $defines
67 gcc -Wall -Wstrict-aliasing=3 $lib $flags fontcomp.c gl/glad.c -o tools/fontcomp $libs $steam_part -Wl,-rpath=./ $defines
68 gcc -Wall -Wstrict-aliasing=3 $lib $flags texsheet.c gl/glad.c -o tools/texsheet $libs $steam_part -Wl,-rpath=./ $defines
69 gcc $lib qoiconv.c -std=c99 -O3 -o tools/qoiconv
70 fi
71
72 # Resources
73 mkdir _temp_textures
74 # Convert all png to qoi
75 echo "Compiling textures"
76 for f in textures/*.png;
77 do echo "-> qoi: $f";
78 ./tools/qoiconv $f ./_temp_textures/"$(basename "$f" .png).qoi"
79 done
80
81 # Autocombine textures
82 auto_combine=""
83 cd textures_combine
84 for f in *.png;
85 do echo "[combine] $f";
86 auto_combine="$auto_combine $f"
87 done
88 ../tools/texsheet ../_temp_textures/autocombine.qoi ../sprites_autocombine.h sprites_auto_combine $auto_combine
89 cd ..
90
91 # Main build
92 if [ "$do_build" = true ]; then
93 gcc -Wall -Wstrict-aliasing=3 $lib $flags $src gl/glad.c -o $target $libs $steam_part -Wl,-rpath=./ $defines
94
95 if [ $? -ne 0 ]; then
96 echo "GCC build failed"
97 exit 1
98 fi
99
100 echo "Build succeeded"
101 fi
102
103 mkdir $build_dir/cfg -p
104 mkdir $build_dir/textures -p
105 mkdir $build_dir/sound -p
106 mkdir $build_dir/maps -p
107 mkdir $build_dir/sav -p
108
109 cp $target $build_dir/$target
110 cp ./steam/$steam_api $build_dir/$steam_api
111 rm -r $build_dir/textures
112 mv ./_temp_textures/ $build_dir/textures
113 cp -r ./sound/ $build_dir
114 cp -r ./maps/ $build_dir
115
116 if [ "$run_after" = true ]; then
117 echo "Playing"
118
119 cd $build_dir
120 ./$target
121 cd ./../
122 fi