-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile.base
48 lines (37 loc) · 1.53 KB
/
Makefile.base
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
# Common stuff for makefiles, like compiler and flags
# Allow the use of advanced globs in paths
SHELL := /bin/bash -O extglob -O globstar -c
# GCC and ld by default
# Clang is supported in the sense that setting CC=clang LD=ld.lld works,
# but performance may or may not be the same, it's mostly useful for -Weverything
CC ?= gcc
LD ?= ld
# C11, latest POSIX with GNU extensions (unfortunately)
CFLAGS += -std=c11 -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE
# Max optimizations
CFLAGS += -O2
CFLAGS += -march=native
CFLAGS += -flto
ifeq (, $(findstring clang,$(CC)))
# Allow LTO shared objects to also be linked without LTO if needed
CFLAGS += -ffat-lto-objects
endif
# Required
CFLAGS += -fPIC
# Don't emit unneeded stuff in the binary
CFLAGS += -fno-unwind-tables -fno-asynchronous-unwind-tables
# Don't protect the stack, the code is verified
# NOTE: This is an easy way to change the binary a little bit in case some unrelated change causes the hot path to be slower
CFLAGS += -fno-stack-protector
# Good warnings, and make them fatal errors to avoid walls of output for minor mistakes
CFLAGS += -Wall -Wextra -Werror -pedantic -Wshadow -Wstrict-aliasing -Wpadded -Wfatal-errors
ifneq (, $(findstring clang,$(CC)))
# All the warnings!
CFLAGS += -Weverything
# ...except this one, somehow clang thinks -nostdinc is not actually used
CFLAGS += -Wno-unused-command-line-argument
# ...and also this one, because -Wpacked warns about "unnecessary" uses but this is by definition arch-dependent
CFLAGS += -Wno-packed
endif
# Debug log
# CFLAGS += -DDEBUG_LEVEL=1