1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#!/bin/sh
# Change your executable name here
GAME_NAME="gunner.exe"
# Set your sources here (relative paths!)
# Example with two source folders:
# SOURCES="src/*.c src/submodule/*.c"
SOURCES="src/*.c"
# Set your raylib/src location here (relative path!)
RAYLIB_SRC="raylib"
# About this build script: it does many things, but in essence, it's
# very simple. It has 3 compiler invocations: building raylib (which
# is not done always, see logic by searching "Build raylib"), building
# src/*.c files, and linking together those two. Each invocation is
# wrapped in an if statement to make the -qq flag work, it's pretty
# verbose, sorry.
# Stop the script if a compilation (or something else?) fails
set -e
# Get arguments
while getopts ":hdusrcq" opt; do
case $opt in
h)
echo "Usage: ./build.sh [-hdurcqq]"
echo " -h Show this information"
echo " -d Faster builds that have debug symbols, and enable warnings"
echo " -u Run upx* on the executable after compilation (before -r)"
echo " -r Run the executable after compilation"
echo " -c Remove the temp/(debug|release) directory, ie. full recompile"
echo " -q Suppress this script's informational prints"
echo ""
echo "Examples:"
echo " Build a release build: ./build.sh"
echo " Build a release build, full recompile: ./build.sh -c"
echo " Build a debug build and run: ./build.sh -d -r"
exit 0
;;
d)
BUILD_DEBUG="1"
;;
u)
UPX_IT="1"
;;
r)
RUN_AFTER_BUILD="1"
;;
c)
BUILD_ALL="1"
;;
q)
QUIET="1"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Set CC if it's not set already
if [ -z "$CC" ]; then
CC=cc
fi
# Directories
ROOT_DIR=$PWD
SOURCES="$ROOT_DIR/$SOURCES"
RAYLIB_SRC="$ROOT_DIR/$RAYLIB_SRC"
TINYCC_SRC="$ROOT_DIR/tinycc"
# Flags
COMPILATION_FLAGS="-std=gnu99 -Os -flto=auto -s -D__USE_MINGW_ANSI_STDIO=0 -mno-stack-arg-probe -Xlinker --stack=0x200000,0x200000
-fno-asynchronous-unwind-tables -fwhole-program -Wl,--gc-sections -mavx"
FINAL_FLAGS=$COMPILATION_FLAGS
WARNING_FLAGS="-Wall -Wextra"
LINK_FLAGS="-lopengl32 -lgdi32 -lwinmm -lxinput1_4"
# Debug changes to flags
if [ -n "$BUILD_DEBUG" ]; then
COMPILATION_FLAGS="-std=gnu99 -O0 -g3"
FINAL_FLAGS="-std=gnu99 -Og -g3 -fsanitize-trap=undefined"
fi
# Display what we're doing
if [ -n "$BUILD_DEBUG" ]; then
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling in debug mode."
else
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling in release mode."
fi
# Create the raylib cache directory
TEMP_DIR="cache/release"
if [ -n "$BUILD_DEBUG" ]; then
TEMP_DIR="cache/debug"
fi
# If there's a -c flag, remove the cache
if [ -d "$TEMP_DIR" ] && [ -n "$BUILD_ALL" ]; then
[ -z "$QUIET" ] && echo "COMPILE-INFO: Found cached raylib, rebuilding."
rm -r "$TEMP_DIR"
fi
# If temp directory doesn't exist, build libs
if [ ! -d "$TEMP_DIR" ]; then
mkdir -p $TEMP_DIR
cd $TEMP_DIR
TCC_DEFINES="-DTCC_TARGET_PE -DTCC_TARGET_X86_64 -DCONFIG_TCC_PREDEFS"
TCC_VERS=$(cat "$TINYCC_SRC/VERSION")
echo "#define TCC_VERSION \"$TCC_VERS\"" >> "$TINYCC_SRC/config.h"
$CC -c $TCC_DEFINES $COMPILATION_FLAGS "$TINYCC_SRC/libtcc.c"
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33"
RAYLIB_C_FILES="$RAYLIB_SRC/rcore.c $RAYLIB_SRC/rshapes.c $RAYLIB_SRC/rtextures.c $RAYLIB_SRC/rtext.c $RAYLIB_SRC/rmodels.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c $RAYLIB_SRC/rglfw.c"
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I$RAYLIB_SRC/external/glfw/include"
$CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS $RAYLIB_C_FILES
[ -z "$QUIET" ] && echo "COMPILE-INFO: raylib compiled into object files in: $TEMP_DIR/"
cd $ROOT_DIR
fi
# Build the actual game
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling game code."
$CC -c -I$RAYLIB_SRC -I$TINYCC_SRC $FINAL_FLAGS $WARNING_FLAGS $SOURCES
$CC -o $GAME_NAME $ROOT_DIR/$TEMP_DIR/*.o *.o $LINK_FLAGS
rm *.o
if [ -n "$UPX_IT" ]; then
[ -z "$QUIET" ] && echo "COMPILE-INFO: Packing $GAME_NAME with upx."
upx $GAME_NAME --brute > /dev/null 2>&1
fi
if [ -n "$RUN_AFTER_BUILD" ]; then
[ -z "$QUIET" ] && echo "COMPILE-INFO: Running."
./$GAME_NAME
fi
|