blob: 9a89746098e7e8f8bc6f3ece793a50cf420aed35 (
plain) (
blame)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
DO != echo -n > deps.mk
LLVM ?= 0
RELEASE ?= 0
DEBUGFLAGS != [ "$(RELEASE)" != "0" ] \
&& echo "-flto=auto -O2 -DNODEBUG" \
|| echo "-O0 -g -DDEBUG"
CFLAGS = -Wall -Wextra
DEPFLAGS = -MT $@ -MMD -MP -MF $@.d
LINTFLAGS = -fsyntax-only
INCLUDEFLAGS = -Iinclude
COMPILEFLAGS =
LINKFLAGS =
all: copyjit
# default values
CROSS_COMPILE ?=
# common programs
OBJCOPY != [ "$(LLVM)" != "0" ] \
&& echo llvm-objcopy \
|| echo $(CROSS_COMPILE)objcopy
# weird, I thought clang accepted the same system target triplet as gcc?
# apparently it should be passed without a trailing dash, will have to fix
COMPILER != [ "$(LLVM)" != "0" ] \
&& echo clang --target="$(CROSS_COMPILE)" \
|| echo $(CROSS_COMPILE)gcc
SOURCES :=
OP_SOURCES :=
IMM_SOURCES :=
include ops/source.mk
include src/source.mk
# compile tools with these flags
# at the moment just prune.c, wonder if it should be rewritten in some
# scripting language?
HOST_COMPILE = $(CC) $(DEBUGFLAGS) $(CFLAGS)
COMPILE = $(COMPILER) $(DEBUGFLAGS)\
$(CFLAGS) $(DEPFLAGS) $(COMPILEFLAGS) $(INCLUDEFLAGS)
OP_COMPILE := $(COMPILER) \
-Wall -Wextra -O2 \
-fno-schedule-insns -fno-schedule-insns2 \
-fpic -fpie \
-T lib/link.ld \
-ffreestanding \
-nostdlib
IMM_COMPILE := $(COMPILER) \
-Wall -Wextra -O2 \
-fpic -fpie \
-T lib/imm.ld \
-ffreestanding \
-nostdlib
# load arch specific compilation options
# as much as I'd like to have everything be completely generic,
# it seems that some arch specific memory models generate unsuitable code
# so we have to specify which models we want to use.
ARCH != uname -m
-include arch/$(ARCH).mk
LINT = $(COMPILE) $(LINTFLAGS)
TEST_OBJS != ./scripts/gen-deps --sources tests/check.c
OBJS != ./scripts/gen-deps --sources "$(SOURCES)"
OPS != ./scripts/gen-ops --ops "$(OP_SOURCES)"
IMMS != ./scripts/gen-ops --imms "$(IMM_SOURCES)"
include deps.mk
include lib/source.mk
.PHONY: lint
lint: $(OBJS:.o=.o.l)
.PHONY: format
format:
@find src ops lib -iname '*.[ch]' |\
xargs -n 10 -P 0 uncrustify -c uncrustify.conf --no-backup -F -
.PHONY: license
license:
@find . -iname '*.[ch]' |\
xargs -n 10 -P 0 ./scripts/license
.PHONY: docs
docs:
@./scripts/warn-undocumented
@doxygen docs/doxygen.conf
.PHONY: check
check: tests/check
./tests/check
tests/check: $(OBJS) $(TEST_OBJS)
$(COMPILE) build/tests/check.o build/src/copyjit.o -o tests/check
copyjit: $(OBJS)
$(COMPILE) $(OBJS) -o $@
# todo: generate operations after cloning? a bit tricky to tell make to generate
# a bunch of files only when required, maybe have a configure stage?
# todo: set up some qemu cross compile environment and test different
# architectures
# could probably make this a bit prettier
.PHONY: clean
clean:
@$(RM) -r build copyjit lib/gen/* lib/*.bin lib/*.d lib/empty lib/prune deps.mk
@$(RM) -r lib/*decls.h lib/*defns.h lib/ops.h lib/imm.h
@$(RM) tests/check
.PHONY: clean_docs
clean_docs:
@$(RM) -r docs/output
.PHONY: clean_all
clean_all: clean clean_docs
|