aa0d03e0c21f5fa1d6b07d7fa6ac41469bc05692
[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 $lib qoiconv.c -std=c99 -O3 -o tools/qoiconv
69 fi
70
71 # Resources
72 mkdir _temp_textures
73 # Convert all png to qoi
74 echo "Compiling textures"
75 for f in textures/*.png;
76 do echo "-> qoi: $f";
77 ./tools/qoiconv $f ./_temp_textures/"$(basename "$f" .png).qoi"
78 done
79
80 #if [ "$compile_models" = true ]; then
81 # echo "Recompiling models"
82 # for f in models/*.obj;
83 # do echo "Compiling $f..";
84 # ./tools/mdlcomp $f $f.h
85 # done
86 #fi
87
88 # Main build
89 if [ "$do_build" = true ]; then
90 gcc -Wall -Wstrict-aliasing=3 $lib $flags $src gl/glad.c -o $target $libs $steam_part -Wl,-rpath=./ $defines
91
92 if [ $? -ne 0 ]; then
93 echo "GCC build failed"
94 exit 1
95 fi
96
97 echo "Build succeeded"
98 fi
99
100 mkdir $build_dir/cfg -p
101 mkdir $build_dir/textures -p
102 mkdir $build_dir/sound -p
103 mkdir $build_dir/maps -p
104 mkdir $build_dir/sav -p
105
106 cp $target $build_dir/$target
107 cp ./steam/$steam_api $build_dir/$steam_api
108 rm -r $build_dir/textures
109 mv ./_temp_textures/ $build_dir/textures
110 cp -r ./sound/ $build_dir
111 cp -r ./maps/ $build_dir
112
113 if [ "$run_after" = true ]; then
114 echo "Playing"
115
116 cd $build_dir
117 ./$target
118 cd ./../
119 fi