-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile.posix
63 lines (54 loc) · 2.6 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
54
55
56
57
58
59
60
61
62
63
# 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-16 \
|| which /usr/local/opt/llvm@16/bin/llvm-config \
|| which /opt/homebrew/opt/llvm@16/bin/llvm-config \
|| which llvm-config-15 \
|| which /usr/local/opt/llvm@15/bin/llvm-config \
|| which /opt/homebrew/opt/llvm@15/bin/llvm-config \
|| which llvm-config-14 \
|| which /usr/local/opt/llvm@14/bin/llvm-config \
|| which /opt/homebrew/opt/llvm@14/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: compile_flags.txt jou
# 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 \"$(CC)\"" >> config.h
config.jou:
@v=`$(LLVM_CONFIG) --version`; case "$$v" in 14.*|15.*|16.*) ;; *) echo "Error: Found unsupported LLVM version $$v. Only LLVM 14, 15 and 16 are supported."; exit 1; esac
echo "# auto-generated by Makefile" > config.jou
echo "def get_jou_clang_path() -> byte*:" >> config.jou
echo " return \"$(CC)\"" >> config.jou
# Stage 1 of bootstrapping: Compile the bootstrap compiler with a C compiler.
BSRC := $(wildcard bootstrap_compiler/*.c)
obj/%.o: bootstrap_compiler/%.c $(wildcard bootstrap_compiler/*.h) config.h
mkdir -p obj && $(CC) -c $(CFLAGS) $< -o $@
jou_stage1: $(BSRC:bootstrap_compiler/%.c=obj/%.o)
$(CC) $(CFLAGS) $^ -o jou_stage1 $(LDFLAGS)
# Stage 2 of bootstrapping: Compile the Jou compiler with the bootstrap compiler.
# Don't depend on Jou files, so that only stage 3 recompiles if they're changed.
jou_stage2: jou_stage1 config.jou
rm -rf compiler/jou_compiled && ./jou_stage1 -o jou_stage2 --linker-flags "$(LDFLAGS)" compiler/main.jou
# Stage 3 of bootstrapping: Compile the Jou compiler with the Jou compiler.
jou: jou_stage2 config.jou $(wildcard compiler/*.jou compiler/*/*.jou)
rm -rf compiler/jou_compiled && ./jou_stage2 -o jou --linker-flags "$(LDFLAGS)" compiler/main.jou
.PHONY: clean
clean:
rm -rvf obj jou jou.exe jou_stage* tmp compile_flags.txt config.jou config.h
find . -name jou_compiled -print -exec rm -rf '{}' +