aboutsummaryrefslogtreecommitdiff
path: root/makefile
blob: ebf50dc2292edb7ffac9bd5f8240088eecc3f57c (plain) (blame)
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
INCLUDEDIR = $(PWD)/inc
SOURCEDIR = $(PWD)/src
BUILDDIR = $(PWD)/build
SOURCES = $(wildcard $(SOURCEDIR)/*.c)
OBJS = $(patsubst $(SOURCEDIR)/%.c, $(BUILDDIR)/%.o, $(SOURCES))

CA = ccache
AS = $(CA) nasm
LD = $(CA) ld
CC = $(CA) gcc
CFLAGS = -Ofast -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wformat=1 -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wswitch-default -Wswitch-enum -Wlogical-op -Wunreachable-code -Wundef -Wold-style-definition -Wvla -std=c99 -fsanitize=address -fsanitize=undefined -fstack-protector-strong -I$(INCLUDEDIR)

all: $(OBJS)
	@$(CC) -o $(BUILDDIR)/out $(CFLAGS) $^

clean:
	@$(RM) -rf $(BUILDDIR)

run: clean all sync
	@$(BUILDDIR)/out test.fun

$(BUILDDIR)/%.o: $(SOURCEDIR)/%.c
	@mkdir -p $(BUILDDIR)
	@$(CC) -c -o $@ $(CFLAGS) $<

compile:
	@$(AS) -f elf64 -o $(BUILDDIR)/test.o $(BUILDDIR)/test.asm
	@$(LD) $(BUILDDIR)/test.o -o $(BUILDDIR)/test

sync:
	@ctags -R --exclude=.git --exclude=build .
	@make --always-make --dry-run | grep -wE 'gcc|g\+\+' | grep -w '\-c' | jq -nR '[inputs|{directory:".", command:., file: match(" [^ ]+$$").string[1:]}]' > compile_commands.json