-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
95 lines (81 loc) · 2.13 KB
/
GNUmakefile
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
# Nuke built-in rules and variables.
MAKEFLAGS += -rR
.SUFFIXES:
PLATFORM = salernos-x86_64
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard ,$d, $2) $(filter $(subst *, %, $2),$d))
CC := cc
LD := ld
CFLAGS := -g -O2 -pipe
CPPFLAGS :=
LDFLAGS :=
override CFLAGS += \
-nostdinc \
-I./ \
-I./crt/ \
-I./subprojects/ \
-I./sysdeps/$(PLATFORM) \
-Wall \
-Wextra \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-lto \
-fno-PIC \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-mno-red-zone \
-m64 \
override CPPFLAGS := \
$(CPPFLAGS) \
-MMD \
-MP
#
override LDFLAGS += \
-nostdlib \
-static \
-z max-page-size=0x1000
override SYSDEPS_CFILES = $(call rwildcard, sysdeps/$(PLATFORM)/, *.c)
override CRT_CFILES = $(call rwildcard, crt/, *.c)
override CFILES = $(call rwildcard, subprojects/$(OUTPUT)/, *.c)
override ASFILES = $(call rwildcard, sysdeps/$(PLATFORM), *.S)
override OBJ = $(addprefix obj/,$(CFILES:.c=.c.o))
override CRT_OBJ = $(addprefix obj/,$(CRT_CFILES:.c=.c.o))
override SYSDEPS_OBJ = $(addprefix obj/,$(SYSDEPS_CFILES:.c=.c.o) $(ASFILES:.S=.S.o))
override HEADER_DEPS = $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
.PHONY: all
all: sysdeps crt
@for proj in ./subprojects/* ; \
do \
file_name=$$(basename $${proj}) ; \
echo COMPILING $${file_name} ; \
make project OUTPUT=$${file_name} ; \
done
crt: $(CRT_OBJ)
sysdeps: $(SYSDEPS_OBJ)
# Default target.
.PHONY: project
project: bin/$(OUTPUT)
# Link rules for the final executable.
bin/$(OUTPUT): GNUmakefile $(OBJ)
@echo [LD] Linking...
@mkdir -p "$$(dirname $@)"
@$(LD) $(OBJ) $(SYSDEPS_OBJ) $(CRT_OBJ) $(LDFLAGS) -o $@
# Include header dependencies.
-include $(HEADER_DEPS)
# Compilation rules for *.c files.
obj/%.c.o: %.c GNUmakefile
@echo [CC] $<
@mkdir -p "$$(dirname $@)"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Compilation rules for *.S files.
obj/%.S.o: %.S GNUmakefile
@echo [AS] $<
@mkdir -p "$$(dirname $@)"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# Remove object files and the final executable.
.PHONY: clean
clean:
rm -rf bin obj