-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile.posix
53 lines (44 loc) · 1.88 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Linux has llvm-config-xx in PATH, where xx is version number
# On macos, brew installs LLVM to a weird place in /usr/local/
# On NetBSD, use llvm-config from libLLVM (package from pkgsrc)
LLVM_CONFIG ?= $(shell \
which llvm-config-14 \
|| which /usr/local/opt/llvm@14/bin/llvm-config \
|| which llvm-config-13 \
|| which /usr/local/opt/llvm@13/bin/llvm-config \
|| which llvm-config-11 \
|| which /usr/local/opt/llvm@11/bin/llvm-config \
|| which /usr/pkg/libexec/libLLVM/llvm-config \
)
CFLAGS += $(shell $(LLVM_CONFIG) --cflags)
CFLAGS += -gdwarf-4 # https://github.com/llvm/llvm-project/issues/56550
LDFLAGS ?= $(shell $(LLVM_CONFIG) --ldflags --libs)
ifeq ($(CC),cc)
# default c compiler --> use clang
CC := $(shell \
which `$(LLVM_CONFIG) --bindir`/clang \
|| which 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:
@v=`$(LLVM_CONFIG) --version`; case "$$v" in 11.*|13.*|14.*) ;; *) echo "Error: Found unsupported LLVM version $$v. Only LLVM 11, 13 and 14 are supported."; exit 1; esac
echo "// auto-generated by Makefile" > config.h
echo "#define JOU_CLANG_PATH \"$(CC)\"" >> config.h
obj/%.o: src/%.c $(wildcard src/*.h) config.h
mkdir -p 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 \"$(CC)\"" >> config.jou
self_hosted_compiler: jou config.jou $(wildcard self_hosted/*.jou)
./jou -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 '{}' +