-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (74 loc) · 2.88 KB
/
Makefile
File metadata and controls
101 lines (74 loc) · 2.88 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
100
101
OCAML_LIB_DIR := $(shell ocamlc -where)
OCAML_VERSION := $(shell ocamlc -version)
OCAML_MAJOR := $(shell echo $(OCAML_VERSION) | cut -d. -f1)
SKIP_LL := external/skip.ll
SKIP_OBJ := build/skip.o
C_OBJS := build/memory.o build/pack.o build/interop.o build/util.o build/fork.o\
build/page_table.o
CPP_OBJS := build/map.o
# Runtime source and object files
RUNTIME_SRC_DIR := external/runtime
RUNTIME_C_SRCS := $(filter-out $(RUNTIME_SRC_DIR)/runtime32_specific.c, $(wildcard $(RUNTIME_SRC_DIR)/*.c))
RUNTIME_CPP_SRCS := $(wildcard $(RUNTIME_SRC_DIR)/*.cpp)
RUNTIME_OBJS := $(patsubst $(RUNTIME_SRC_DIR)/%.c, build/runtime_%.o, $(RUNTIME_C_SRCS)) \
$(patsubst $(RUNTIME_SRC_DIR)/%.cpp, build/runtime_%.o, $(RUNTIME_CPP_SRCS))
RUNTIME_LIB := build/libskip_runtime.a
STATIC_LIB := build/libskip_reactive.a
CMXA := build/reactive.cmxa
TARGET := build/main
EXT_LIBS := external/libbacktrace.a
# Conditionally add -DOCAML5
CFLAGS := -O2 -g -I$(OCAML_LIB_DIR) -Isrc/c -DSKIP64 -Wno-c2x-extensions -Wno-extern-c-compat
ifeq ($(shell [ $(OCAML_MAJOR) -ge 5 ] && echo yes),yes)
CFLAGS += -DOCAML5
endif
.PHONY: all clean
all: $(TARGET)
# Ensure build directory exists
$(shell mkdir -p build)
# Final binary: link cmxa, static lib, and explicitly -lstdc++
$(TARGET): $(CMXA) $(STATIC_LIB) src/main.ml
ocamlopt -g -o $@ -I build unix.cmxa reactive.cmxa src/main.ml\
$(STATIC_LIB) -cclib -lstdc++ -I +unix\
-ccopt -no-pie -ccopt -Wl,-Ttext=0x8000000
# OCaml static archive
$(CMXA): build/reactive.cmx
ocamlopt -a -o $@ $^
# Create unified static lib
$(STATIC_LIB): $(C_OBJS) $(CPP_OBJS) $(RUNTIME_OBJS) $(SKIP_OBJ)
ar rcs $@ $(C_OBJS) $(CPP_OBJS) $(RUNTIME_OBJS) $(SKIP_OBJ)
build/reactive.cmi: src/ocaml/reactive.mli
ocamlopt -g -c -o $@ $<
# OCaml object
build/reactive.cmx: src/ocaml/reactive.ml build/reactive.cmi
ocamlopt -I build/ -I +unix -g -c -o $@ $<
# Compile C sources
build/%.o: src/c/%.c
clang -g -c $(CFLAGS) $< -o $@
# Compile C++ sources
build/%.o: src/c/%.cpp
clang++ -g -c $(CFLAGS) $< -o $@
# Special rule for stripping 'main' from runtime64_specific.o
build/runtime_runtime64_specific.o: $(RUNTIME_SRC_DIR)/runtime64_specific.cpp
clang++ -g -c $(CFLAGS) $< -o $@
objcopy --strip-symbol=main $@
# Compile LLVM to object
$(SKIP_OBJ): $(SKIP_LL)
clang++ -g -c $< -o $@
# Compile runtime .c sources
build/runtime_%.o: $(RUNTIME_SRC_DIR)/%.c
clang -g -c $(CFLAGS) $< -o $@
# Compile runtime .cpp sources
build/runtime_%.o: $(RUNTIME_SRC_DIR)/%.cpp
clang++ -g -c $(CFLAGS) $< -o $@
TEST_SRC_DIR:=src/test
TESTS:=$(basename $(notdir $(wildcard $(TEST_SRC_DIR)/*.ml)))
TEST_BINS:=$(addprefix build/,$(TESTS))
.PHONY: tests run_tests
tests: $(TEST_BINS)
build/%: $(TEST_SRC_DIR)/%.ml $(CMXA) $(STATIC_LIB)
ocamlopt -g -o $@ -I build unix.cmxa reactive.cmxa $<\
$(STATIC_LIB) -cclib -lstdc++ -I +unix\
-ccopt -no-pie -ccopt -Wl,-Ttext=0x8000000\
clean:
rm -Rf build/