summaryrefslogtreecommitdiff
path: root/build.sh
blob: 1e881416c943013f3d28e0b37ea4fb8c8887339e (plain)
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
#!/bin/bash

# Set the project name here
PROJECT_NAME="mknes"  # Change this for each new project

# Base configuration common to all builds
CFLAGS="-std=gnu11 -mtune=generic "
CFLAGS+="-mbmi2 "
CFLAGS+="-mfunction-return=keep "
CFLAGS+="-mindirect-branch=keep "
CFLAGS+="-fwrapv -ffast-math -fno-trapping-math -fwhole-program -fvisibility=hidden "
CFLAGS+="-fno-stack-protector -fno-PIE -no-pie -fno-strict-aliasing -fcf-protection=none -ffunction-sections -fdata-sections "
# CFLAGS+="-fno-exceptions -fno-rtti -fno-use-cxa-atexit "
CFLAGS+="-fno-non-call-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables "
CFLAGS+="-Wall -Wextra "
CFLAGS+="-Wno-unused-parameter -Wno-sign-compare -Wno-trigraphs -Wno-maybe-uninitialized "
CFLAGS+="-Wno-unused-variable -Wno-unused-const-variable -Wno-unused-function -Wno-write-strings -Wno-missing-field-initializers "
CFLAGS+="-U_FORTIFY_SOURCE -fno-pic "

LDFLAGS="-Wl,--gc-sections -Wl,--as-needed "

# Base include paths (common for all platforms)
INCLUDE_PATHS="-Ibase -I.."

# Linux-specific includes and libraries
LINUX_INCLUDE="-I/usr/include/pipewire-0.3 -I/usr/include/spa-0.2"
LINUX_LIBS="-lpipewire-0.3 -lXi -lX11 -lGL -lm -ldl -pthread -lglfw -larchive"

# Windows-specific includes and libraries
# WINDOWS_INCLUDE=""
# WINDOWS_LIBS="-lwinmm -lksuser -lole32 -lmmdevapi -lavrt -lgdi32 -lopengl32 -luuid"

# Determine build type-specific flags
BUILD_TYPE=$1

if [ -z "$BUILD_TYPE" ]; then
	BUILD_TYPE="normal"
fi

case "$BUILD_TYPE" in
	"normal")
		CFLAGS+=" -ggdb -fno-omit-frame-pointer -O2 -DDEBUG_INTERNAL"
#  -pg # for gprof
#  -fsanitize=address,undefined,alignment,object-size,unreachable -fno-omit-frame-pointer"
		;;
	"release")
		CFLAGS+=" -s -Wl,--strip-all -O2"
		;;
	"profile")
		CFLAGS+=" -g -O2 -fprofile-generate"
		;;
	"profile_release")
		CFLAGS+=" -s -Wl,--strip-all -O2 -fprofile-use"
		;;
	"debug")
		CFLAGS+=" -g -O0"
		LDFLAGS+=" -fno-pie -no-pie"
		;;
	*)
		echo "Unknown build type: $BUILD_TYPE"
		exit 1
		;;
esac

# Make sure the shaders are up to date
shader2h 330 vertex_shader vertex_shader.glsl
shader2h 330 fragment_shader shader.h fragment_shader.glsl

# Make sure the compilation stops if any error happens.
set -e

# Build Linux version
(
	# ../bin/ctime -begin .${PROJECT_NAME}_linux
	gcc $CFLAGS ${PROJECT_NAME}.c -o ${PROJECT_NAME} $INCLUDE_PATHS $LINUX_INCLUDE $LDFLAGS $LINUX_LIBS
	# ../bin/ctime -end .${PROJECT_NAME}_linux $?
) &

# Build Windows version
# (
# 	../bin/ctime -begin .${PROJECT_NAME}_windows
# 	x86_64-w64-mingw32-gcc $CFLAGS ${PROJECT_NAME}.c -o ${PROJECT_NAME}.exe $INCLUDE_PATHS $WINDOWS_INCLUDE $LDFLAGS $WINDOWS_LIBS
# 	# x86_64-w64-mingw32-gcc $CFLAGS ${PROJECT_NAME}.c -o ${PROJECT_NAME}.exe -mwindows $INCLUDE_PATHS $WINDOWS_INCLUDE $LDFLAGS $WINDOWS_LIBS
# 	../bin/ctime -end .${PROJECT_NAME}_windows $?
# ) &

wait