blob: 2730eff4155b4914c38bffd3b121875a73c80386 [file] [log] [blame]
Dave Hylandsc89c6812014-01-24 01:05:30 -08001ifneq ($(MKENV_INCLUDED),1)
2# We assume that mkenv is in the same directory as this file.
3THIS_MAKEFILE = $(lastword $(MAKEFILE_LIST))
4include $(dir $(THIS_MAKEFILE))mkenv.mk
5endif
6
7# This file expects that OBJ contains a list of all of the object files.
8# The directory portion of each object file is used to locate the source
9# and should not contain any ..'s but rather be relative to the top of the
10# tree.
11#
12# So for example, py/map.c would have an object file name py/map.o
13# The object files will go into the build directory and mantain the same
14# directory structure as the source tree. So the final dependency will look
15# like this:
16#
17# build/py/map.o: py/map.c
18#
19# We set vpath to point to the top of the tree so that the source files
20# can be located. By following this scheme, it allows a single build rule
21# to be used to compile all .c files.
22
23vpath %.S . $(TOP)
24$(BUILD)/%.o: %.S
25 $(ECHO) "CC $<"
26 $(Q)$(CC) $(CFLAGS) -c -o $@ $<
27
28vpath %.s . $(TOP)
29$(BUILD)/%.o: %.s
30 $(ECHO) "AS $<"
31 $(Q)$(AS) -o $@ $<
32
33define compile_c
34$(ECHO) "CC $<"
35$(Q)$(CC) $(CFLAGS) -c -MD -o $@ $<
36@# The following fixes the dependency file.
37@# See http://make.paulandlesley.org/autodep.html for details.
38@cp $(@:.o=.d) $(@:.o=.P); \
39 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
40 -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
41 rm -f $(@:.o=.d)
42endef
43
44vpath %.c . $(TOP)
45$(BUILD)/%.o: %.c
46 $(call compile_c)
47
Dave Hylandsca5444e2014-03-14 23:41:28 -070048$(BUILD)/%.pp: %.c
49 $(ECHO) "PreProcess $<"
50 $(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<
51
Dave Hylandsc89c6812014-01-24 01:05:30 -080052# The following rule uses | to create an order only prereuisite. Order only
53# prerequisites only get built if they don't exist. They don't cause timestamp
54# checkng to be performed.
55#
56# $(sort $(var)) removes duplicates
57#
58# The net effect of this, is it causes the objects to depend on the
59# object directories (but only for existance), and the object directories
60# will be created if they don't exist.
61OBJ_DIRS = $(sort $(dir $(OBJ)))
62$(OBJ): | $(OBJ_DIRS)
63$(OBJ_DIRS):
64 mkdir -p $@
65
66ifneq ($(PROG),)
67# Build a standalone executable (unix and unix-cpy do this)
68
69all: $(PROG)
70
71$(PROG): $(OBJ)
Dave Hylands1a3b0d52014-01-25 08:55:31 -080072 $(ECHO) "LINK $@"
Dave Hylandsc89c6812014-01-24 01:05:30 -080073 $(Q)$(CC) -o $@ $(OBJ) $(LIB) $(LDFLAGS)
74ifndef DEBUG
75 $(Q)strip $(PROG)
76endif
77 $(Q)size $(PROG)
78
79clean: clean-prog
80clean-prog:
81 $(RM) -f $(PROG)
82
83.PHONY: clean-prog
84endif
85
86clean:
87 $(RM) -rf $(BUILD)
88.PHONY: clean
89
90print-cfg:
91 $(ECHO) "PY_SRC = $(PY_SRC)"
92 $(ECHO) "BUILD = $(BUILD)"
93 $(ECHO) "OBJ = $(OBJ)"
94.PHONY: print-cfg
95
96-include $(OBJ:.o=.P)