-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
53 lines (40 loc) · 1.77 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
# TODO: I think I'm using make wrong
SOURCEDIR = $(PWD)/src
TESTSDIR = $(PWD)/tests
INCDIR = $(PWD)/inc
BUILDDIR = $(PWD)/build
SOURCES = $(wildcard $(SOURCEDIR)/*.c)
OBJS = $(patsubst $(SOURCEDIR)/%.c, $(BUILDDIR)/%.o, $(SOURCES))
CTESTS = $(wildcard $(TESTSDIR)/c/*.c)
CTESTSOBJS = $(patsubst $(TESTSDIR)/c/%.c, $(BUILDDIR)/test_c_%.o, $(CTESTS))
ASMTESTS = $(wildcard $(TESTSDIR)/asm/*.asm)
ASMTESTSOBJS = $(patsubst $(TESTSDIR)/asm/%.asm, $(BUILDDIR)/test_asm_%.o, $(ASMTESTS))
CC = gcc
AS = nasm
LD = ld
WARNINGS = -Wall -Wextra -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wformat=2 -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wswitch-default -Wswitch-enum -Wunreachable-code -Wundef -Wold-style-definition -Wvla -pedantic -Wno-pointer-arith
DEBUG = -fsanitize=undefined,address,leak -fstack-protector-strong -s -Og
CFLAGS = -Ofast $(shell pkg-config --cflags --libs gtk4) $(WARNINGS) -I$(INCDIR) #$(DEBUG)
ASFLAGS = -O2 -f elf64 # TODO: Use -O0
all: $(BUILDDIR)/out tests
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.c
@$(CC) -c $< $(CFLAGS) -o $@
$(BUILDDIR)/out: $(OBJS)
@$(CC) $^ $(CFLAGS) -o $@
tests: $(CTESTSOBJS) $(ASMTESTSOBJS)
$(ASMTESTSOBJS): $(ASMTESTS)
@$(AS) $(ASFLAGS) $< -o $@
@$(LD) $@ -o $(basename $@)
$(CTESTSOBJS): $(CTESTS)
@$(CC) $< -o $(basename $@)
clean:
@$(RM) -rf $(BUILDDIR)/*
run: all sync
@$(BUILDDIR)/out $(BUILDDIR)/test_asm_yay
sync:
@$(MAKE) $(BUILDDIR)/out --always-make --dry-run | grep -wE 'gcc|g\+\+' | grep -w '\-c' | jq -nR '[inputs|{directory:".", command:., file: match(" [^ ]+$$").string[1:]}]' >compile_commands.json
@ctags -R --exclude=.git --exclude=build .
$(BUILDDIR)/%.o: $(SOURCEDIR)/%.c
@mkdir -p $(BUILDDIR)
@$(CC) -c -o $@ $(CFLAGS) $<
.PHONY: all out tests clean run sync