-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
72 lines (61 loc) · 1.93 KB
/
Makefile
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
.DEFAULT_GOAL := all
## Special options
# Things that generally dont need to be overwritten but can be if needed.
ROOTDIR?=.
OBJDIR:=$(ROOTDIR)/obj
EXECUTABLE=$(ROOTDIR)/$(projectname)
COMPILER_C_FLAGS?=
## Setup variables
# These can be modified if desired at project creation, but shouldn't need to
# be updated when compiling.
projectname:=squire
srcdir:=$(ROOTDIR)/src
includedir:=$(ROOTDIR)/include/$(projectname)
override required_compiler_flags:=\
-I$(dir $(includedir)) \
-Wall -Wpedantic -Wextra
## Internal variables
# These don't ever need to be edited
recurisve-c-files=$(foreach path,\
$(wildcard $(1)/*),\
$(if $(filter %.c,$(path)),$(path),$(call recurisve-c-files,$(path))))
sources:=$(call recurisve-c-files,$(srcdir))
objects:=$(sources:$(srcdir)/%.c=$(OBJDIR)/%.o)
## Custom logic
ifdef optimized
COMPILER_C_FLAGS+=-flto -O3 -DNDEBUG -DSQ_RELEASE_FAST
# SQ_USE_ALLOCA
else
COMPILER_C_FLAGS+=-g
COMPILER_C_FLAGS+=\
-Weverything -Wno-covered-switch-default \
-Wno-switch-enum -Wno-comma -Wno-padded -Wno-poison-system-directories \
-Wno-shorten-64-to-32 -Wno-cast-qual \
-Wno-conditional-uninitialized -Wno-sign-conversion
ifdef debug
COMPILER_C_FLAGS+=-fsanitize=address,undefined -DSQ_LOG
njoke:=1
endif
endif
ifdef njoke
COMPILER_C_FLAGS+=-DSQ_NMOON_JOKE
endif
override CFLAGS+=$(ANNOYING_FLAGS)
override cflags:=$(COMPILER_C_FLAGS) $(CFLAGS) $(required_compiler_flags)
## end custom logic
.PHONY: all
all: $(objects) $(EXECUTABLE)
.PHONY: clean
clean:
-rm -rf $(OBJDIR) $(EXECUTABLE)
# Compiles the executable
$(EXECUTABLE): $(objects)
@mkdir -p $(@D)
$(CC) $(cflags) -o $@ $+
# `token.c` is wonky cause it `#include`s a c file.
$(OBJDIR)/program/token.o: $(srcdir)/program/token.c $(srcdir)/program/macro.c
$(CC) $(cflags) -o $@ -c $<
# Create the object files. The `include` can be uncommented if that's what youre doing
$(OBJDIR)/%.o: $(srcdir)/%.c #$(includedir)/%.h
@mkdir -p $(@D)
$(CC) $(cflags) -o $@ -c $<