forked from bext-lang/b
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
99 lines (80 loc) · 2.9 KB
/
Makefile
File metadata and controls
99 lines (80 loc) · 2.9 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
BUILD=build
SRC=src
ifneq ($(OS),Windows_NT)
UNAMEOS = $(shell uname)
ifeq ($(UNAMEOS),Darwin)
LDFLAGS=-lc
else ifeq ($(shell uname -o), Android)
LDFLAGS=-lc
else
LDFLAGS=-lc -lgcc
endif
endif
CRUST_FLAGS=-g --edition 2021 -C opt-level=0 -C panic="abort"
RSS=\
$(SRC)/arena.rs \
$(SRC)/b.rs \
$(SRC)/ir.rs \
$(SRC)/crust.rs \
$(SRC)/flag.rs \
$(SRC)/glob.rs \
$(SRC)/lexer.rs \
$(SRC)/nob.rs \
$(SRC)/targets.rs \
$(SRC)/time.rs \
$(SRC)/jim.rs \
$(SRC)/jimp.rs \
POSIX_OBJS=\
$(BUILD)/nob.posix.o \
$(BUILD)/flag.posix.o \
$(BUILD)/glob.posix.o \
$(BUILD)/libc.posix.o \
$(BUILD)/arena.posix.o \
$(BUILD)/time.posix.o \
$(BUILD)/jim.posix.o \
$(BUILD)/jimp.posix.o \
$(BUILD)/shlex.posix.o \
MINGW32_OBJS=\
$(BUILD)/nob.mingw32.o \
$(BUILD)/flag.mingw32.o \
$(BUILD)/glob.mingw32.o \
$(BUILD)/libc.mingw32.o \
$(BUILD)/arena.mingw32.o \
$(BUILD)/time.mingw32.o \
$(BUILD)/jim.mingw32.o \
$(BUILD)/jimp.mingw32.o \
$(BUILD)/shlex.mingw32.o \
.PHONY: all
all: $(BUILD)/b $(BUILD)/btest $(BUILD)/libb/
.PHONY: test
test: $(BUILD)/b $(BUILD)/btest $(BUILD)/libb/
$(BUILD)/btest
.PHONY: mingw32-all
mingw32-all: $(BUILD)/b.exe $(BUILD)/btest.exe $(BUILD)/libb/
$(BUILD)/b: $(RSS) $(POSIX_OBJS) $(SRC)/codegen/.INDEX.rs | $(BUILD)
rustc $(CRUST_FLAGS) -L $(BUILD) -C link-args="$(POSIX_OBJS) $(LDFLAGS)" $(SRC)/b.rs -o $(BUILD)/b
$(BUILD)/btest: $(SRC)/btest.rs $(RSS) $(POSIX_OBJS) $(SRC)/codegen/.INDEX.rs | $(BUILD)
rustc $(CRUST_FLAGS) -C link-args="$(POSIX_OBJS) $(LDFLAGS)" $(SRC)/btest.rs -o $(BUILD)/btest
ifneq ($(OS),Windows_NT)
$(SRC)/codegen/.INDEX.rs $(BUILD)/libb/ &: $(BUILD)/bgen $(SRC)/codegen ./libb/
$(BUILD)/bgen
else
$(SRC)/codegen/.INDEX.rs $(BUILD)/libb/ &: $(BUILD)/bgen.exe $(SRC)/codegen ./libb/
$(BUILD)/bgen.exe
endif
$(BUILD)/bgen: $(SRC)/bgen.rs $(RSS) $(POSIX_OBJS) | $(BUILD)
rustc $(CRUST_FLAGS) -C link-args="$(POSIX_OBJS) $(LDFLAGS)" $(SRC)/bgen.rs -o $(BUILD)/bgen
$(BUILD)/%.posix.o: ./thirdparty/%.c | $(BUILD)
$(CC) -fPIC -g -c $< -o $@ $(LDFLAGS)
# Cross-compilation on POSIX to Windows using mingw32-w64
# Invoked on demand by `make ./build/b.exe`
$(BUILD)/b.exe: $(RSS) $(MINGW32_OBJS) $(SRC)/codegen/.INDEX.rs | $(BUILD)
rustc $(CRUST_FLAGS) --target x86_64-pc-windows-gnu -C link-args="$(MINGW32_OBJS) -lmingwex -lmsvcrt -lkernel32" $(SRC)/b.rs -o $(BUILD)/b.exe
$(BUILD)/btest.exe: $(SRC)/btest.rs $(RSS) $(MINGW32_OBJS) $(SRC)/codegen/.INDEX.rs | $(BUILD)
rustc $(CRUST_FLAGS) --target x86_64-pc-windows-gnu -C link-args="$(MINGW32_OBJS) -lmingwex -lmsvcrt -lkernel32" $(SRC)/btest.rs -o $(BUILD)/btest.exe
$(BUILD)/bgen.exe: $(SRC)/bgen.rs $(RSS) $(MINGW32_OBJS) | $(BUILD)
rustc $(CRUST_FLAGS) --target x86_64-pc-windows-gnu -C link-args="$(MINGW32_OBJS) -lmingwex -lmsvcrt -lkernel32" $(SRC)/bgen.rs -o $(BUILD)/bgen.exe
$(BUILD)/%.mingw32.o: ./thirdparty/%.c | $(BUILD)
x86_64-w64-mingw32-gcc -fPIC -g -c $< -o $@
$(BUILD):
mkdir -pv $(BUILD)