-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
72 lines (56 loc) · 1.7 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
# Makefile for mkern
PROJECT=mkern
CROSS_PREFIX :=
PP=$(CROSS_PREFIX)cpp
CC=$(CROSS_PREFIX)gcc
CCFLAGS=-O3 -pipe -Wall -Werror $(CFLAGS) \
-nostdlib -T ld.script \
-Wa,-mla-global-with-pcrel \
-Wa,-mla-global-with-pcrel \
-Wa,-mla-global-with-abs \
-fno-plt -Wa,-mla-global-with-abs,-mla-local-with-abs
SRCDIR=src
BINDIR=bin
CONFDIR=conf
BUILDDIR=build
TARGET=$(BINDIR)/mkern
-include build.mk
CCSRCS=$(filter %.c,$(SRCFILES))
ASSRCS=$(filter %.S,$(SRCFILES))
LDOBJS=$(patsubst $(SRCDIR)/%.c,$(BUILDDIR)/%.o,$(CCSRCS)) \
$(patsubst $(SRCDIR)/%.S,$(BUILDDIR)/%.o,$(ASSRCS))
DEPEND=$(LDOBJS:.o=.dep)
BUILDMSG="\e[1;31mBUILD\e[0m %s\n"
LINKMSG="\e[1;34mLINK\e[0m \e[1;32m%s\e[0m\n"
CLEANMSG="\e[1;34mCLEAN\e[0m %s\n"
V :=
ECHO_PREFIX := @
ifeq ($(V),1)
undefine ECHO_PREFIX
endif
.PHONY: all clean
all : $(TARGET)
clean :
$(ECHO_PREFIX) $(RM) -rf $(BINDIR) $(BUILDDIR)
@printf $(CLEANMSG) $(PROJECT)
$(TARGET) : $(LDOBJS)
$(ECHO_PREFIX) mkdir -p $(dir $@)
$(ECHO_PREFIX) $(CC) -o $@ $(LDOBJS) $(CCFLAGS)
@printf $(LINKMSG) $@
$(BUILDDIR)/%.dep : $(SRCDIR)/%.c
$(ECHO_PREFIX) mkdir -p $(dir $@)
$(ECHO_PREFIX) $(PP) $(CCFLAGS) -MM -MT$(@:.dep=.o) -MF$@ $< 2>/dev/null
$(BUILDDIR)/%.dep : $(SRCDIR)/%.S
$(ECHO_PREFIX) mkdir -p $(dir $@)
$(ECHO_PREFIX) $(PP) $(CCFLAGS) -MM -MT$(@:.dep=.o) -MF$@ $< 2>/dev/null
$(BUILDDIR)/%.o : $(SRCDIR)/%.c
$(ECHO_PREFIX) mkdir -p $(dir $@)
$(ECHO_PREFIX) $(CC) $(CCFLAGS) -c -o $@ $<
@printf $(BUILDMSG) $<
$(BUILDDIR)/%.o : $(SRCDIR)/%.S
$(ECHO_PREFIX) mkdir -p $(dir $@)
$(ECHO_PREFIX) $(CC) $(CCFLAGS) -c -o $@ $<
@printf $(BUILDMSG) $<
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPEND)
endif