aboutsummaryrefslogtreecommitdiff
path: root/makefile
diff options
context:
space:
mode:
authorMarvin Borner2022-12-13 15:43:39 +0100
committerMarvin Borner2022-12-13 15:44:59 +0100
commit2eecfca85b2b703318e57fcce33c864757b79c00 (patch)
tree5386231745ddb9b5d24281a889ef28dfa84f0b29 /makefile
Basic parsing
Diffstat (limited to 'makefile')
-rw-r--r--makefile40
1 files changed, 40 insertions, 0 deletions
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..713b3de
--- /dev/null
+++ b/makefile
@@ -0,0 +1,40 @@
+# Copyright (c) 2022, Marvin Borner <dev@marvinborner.de>
+# SPDX-License-Identifier: MIT
+
+CC = gcc
+LD = ld
+TG = ctags
+
+BUILD = $(PWD)/build
+SRC = ./src
+INC = ./inc
+SRCS = $(shell find $(SRC) -name '*.c')
+OBJS = $(SRCS:%=$(BUILD)/%.o)
+
+# I need the following on my machine. Look it up though before using it.
+# export ASAN_OPTIONS=verify_asan_link_order=0
+CFLAGS_DEBUG = -Wno-error -ggdb3 -Og -Wno-unused -fsanitize=address -fsanitize=undefined -fstack-protector-all
+CFLAGS_WARNINGS = -Wall -Wextra -Werror -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-switch-enum
+CFLAGS = $(CFLAGS_WARNINGS) -std=c99 -fno-profile-generate -fno-omit-frame-pointer -fno-common -fno-asynchronous-unwind-tables -mno-red-zone -Ofast -D_DEFAULT_SOURCE -I$(INC) $(CFLAGS_DEBUG)
+
+all: $(BUILD) $(OBJS) $(BUILD)/milcr
+
+compile: all sync
+
+clean:
+ @rm -rf $(BUILD)/*
+
+sync: # Ugly hack
+ @$(MAKE) --always-make --dry-run | grep -wE 'gcc' | jq -nR '[inputs|{directory: ".", command: ., file: match(" [^ ]+$$").string[1:]}]' >compile_commands.json &
+ @$(TG) -R --exclude=.git --exclude=build . &
+
+$(BUILD)/%.c.o: %.c
+ @$(CC) -c $(CFLAGS) $< -o $(patsubst $(BUILD)/$(SRC)/%.c.o,$(BUILD)/%.o,$@)
+
+$(BUILD)/milcr: $(OBJS)
+ $(CC) $(CFLAGS) $(patsubst $(BUILD)/$(SRC)/%.c.o,$(BUILD)/%.o,$^) -o $@
+
+.PHONY: all compile clean sync
+
+$(BUILD):
+ @mkdir -p $@