-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
114 lines (87 loc) · 2.62 KB
/
makefile
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
PROG = holyc
# CC := gcc
#
UNAME := $(shell uname)
#--
CFLAGS += -g
# simple code output
CFLAGS += -O0
# output standalone executable
CFLAGS += -static
# don't link any libs or startup files
CFLAGS += -nostdlib
# disable builtin functions
#
# Note that it is assumed that a freestanding environment will additionally
# provide memcpy, memmove, memset and memcmp implementations, as these are
# needed for efficient codegen for many programs.
#
CFLAGS += -ffreestanding
# ensure 16-byte alignment, required by SysV | TODO: any of this needed?
ifeq ($(UNAME), Linux)
CFLAGS += -mincoming-stack-boundary=4
# Ensure we can still `call` without having to check if `__APPLE__`
CFLAGS += -fleading-underscore
endif
ifeq ($(UNAME), Darwin)
# CFLAGS += -mstack-alignment=4
# Needed to prevent:
# Undefined symbols for architecture x86_64:
# "___stack_chk_fail", referenced from:
# __printf_print_itoa in hc.o
# __warnf_print_itoa in hc.o
# _main in hc.o
# "___stack_chk_guard", referenced from:
# __printf_print_itoa in hc.o
# __warnf_print_itoa in hc.o
# _main in hc.o
CFLAGS += -fno-stack-protector
endif
# 128-byte redzone, required by SysV (kernel code can't use it)
CFLAGS += -mno-red-zone
#-- warnings
CFLAGS += -Wall
CFLAGS += -Werror
# clang yells at us for using `-e` with `-c`...
# CFLAGS += -Wno-unused-command-line-argument
# .eh_frame stuff?, required by SysV
# TODO: is this needed?
# CFLAGS += -fno-asynchronous-unwind-tables
# Allow for #include </lib/...> instead of relative paths
CFLAGS += -I . -I lib/c/include -I include
#--
default: test
SRCS := $(wildcard src/*.c)
OBJS := $(SRCS:.c=.o)
LIBC := lib/c/libc.a
LIBC_FLAGS := -Llib/c -lc
$(LIBC):
$(MAKE) -C lib/c
$(PROG): $(OBJS) | $(LIBC)
$(CC) -e _start $(CFLAGS) $(LIBC_FLAGS) $^ $(LIBC) -o $(PROG)
clean:
rm -f $(OBJS) $(PROG) *.out test/*.o $(TEST_MAIN)
$(MAKE) -C lib/c clean
#--
test/bin:
mkdir -p $@
test/bin/lex: test/lex.o src/lex.o $(LIBC) | test/bin
$(CC) -e _start $(CFLAGS) $(LIBC_FLAGS) $^ -o $@
./$@
test/bin/parse: test/parse.o $(filter-out src/main.o, $(OBJS)) $(LIBC) | test/bin
$(CC) -e _start $(CFLAGS) $(LIBC_FLAGS) $^ -o $@
./$@
test/bin/asm: test/asm.o $(filter-out src/main.o, $(OBJS)) $(LIBC) | test/bin
$(CC) -e _start $(CFLAGS) $(LIBC_FLAGS) $^ -o $@
./$@
test: test/bin/lex test/bin/parse $(PROG) FORCE
sh test/main.sh
FORCE:
lint: $(SRCS)
clang-format -i $^
#--
docker: docker-build docker-run
docker-build:
docker build -t holyc .
docker-run:
docker run -it --rm --cap-add=SYS_PTRACE --security-opt seccomp=unconfined holyc