-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.posix
37 lines (28 loc) · 1.26 KB
/
Makefile.posix
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
LLVM_CONFIG ?= $(shell which llvm-config-13 || which llvm-config-11)
CFLAGS += $(shell $(LLVM_CONFIG) --cflags)
LDFLAGS ?= $(shell $(LLVM_CONFIG) --ldflags --libs)
ifeq ($(CC),cc)
# default c compiler --> use clang
CC := $(shell $(LLVM_CONFIG) --bindir)/clang
endif
all: jou compile_flags.txt
# point clangd to the right include folder so i don't get red squiggles in my editor
compile_flags.txt:
echo "-I$(shell $(LLVM_CONFIG) --includedir)" > compile_flags.txt
config.h:
echo "// auto-generated by Makefile" > config.h
echo "#define JOU_CLANG_PATH \"$(shell $(LLVM_CONFIG) --bindir)/clang\"" >> config.h
obj/%.o: src/%.c $(wildcard src/*.h) config.h
mkdir -vp obj && $(CC) -c $(CFLAGS) $< -o $@
jou: $(SRC:src/%.c=obj/%.o)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
config.jou:
echo "# auto-generated by Makefile" > config.jou
echo "def get_jou_clang_path() -> byte*:" >> config.jou
echo " return \"$(shell $(LLVM_CONFIG) --bindir)/clang\"" >> config.jou
self_hosted_compiler: jou config.jou $(wildcard self_hosted/*.jou)
./jou -v -o $@ --linker-flags "$(LDFLAGS)" self_hosted/main.jou
.PHONY: clean
clean:
rm -rvf obj jou jou.exe self_hosted_compiler self_hosted_compiler.exe tmp config.h config.jou compile_flags.txt
find -name jou_compiled -print -exec rm -rf '{}' +