blob: 902b20fd52494ef3591bb5042c4ffb1fe0c986a2 [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.
Andrew Scheller902d9552014-04-07 01:35:45 +010038@$(CP) $(@:.o=.d) $(@:.o=.P); \
39 $(SED) -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
Dave Hylandsc89c6812014-01-24 01:05:30 -080040 -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
Andrew Scheller902d9552014-04-07 01:35:45 +010041 $(RM) -f $(@:.o=.d)
Dave Hylandsc89c6812014-01-24 01:05:30 -080042endef
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
Damien Georged553be52014-04-17 18:03:27 +010054# checking to be performed.
Dave Hylandsc89c6812014-01-24 01:05:30 -080055#
Sven Wegenerb98c1622014-11-06 09:25:44 +010056# We don't know which source files actually need the generated.h (since
57# it is #included from str.h). The compiler generated dependencies will cause
58# the right .o's to get recompiled if the generated.h file changes. Adding
59# an order-only dependendency to all of the .o's will cause the generated .h
60# to get built before we try to compile any of them.
61$(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/py-version.h
62
Dave Hylandsc89c6812014-01-24 01:05:30 -080063# $(sort $(var)) removes duplicates
64#
65# The net effect of this, is it causes the objects to depend on the
Damien Georged553be52014-04-17 18:03:27 +010066# object directories (but only for existence), and the object directories
Dave Hylandsc89c6812014-01-24 01:05:30 -080067# will be created if they don't exist.
68OBJ_DIRS = $(sort $(dir $(OBJ)))
Sven Wegenerb98c1622014-11-06 09:25:44 +010069$(OBJ): | $(OBJ_DIRS)
Dave Hylandsc89c6812014-01-24 01:05:30 -080070$(OBJ_DIRS):
Andrew Scheller902d9552014-04-07 01:35:45 +010071 $(MKDIR) -p $@
Dave Hylandsc89c6812014-01-24 01:05:30 -080072
Andrew Scheller70a7d7a2014-04-16 22:10:33 +010073$(HEADER_BUILD):
74 $(MKDIR) -p $@
75
Dave Hylandsc89c6812014-01-24 01:05:30 -080076ifneq ($(PROG),)
77# Build a standalone executable (unix and unix-cpy do this)
78
79all: $(PROG)
80
81$(PROG): $(OBJ)
Dave Hylands1a3b0d52014-01-25 08:55:31 -080082 $(ECHO) "LINK $@"
Paul Sokolovsky4c4b9d12014-06-20 20:33:20 +030083 $(Q)$(CC) $(COPT) -o $@ $(OBJ) $(LIB) $(LDFLAGS)
Dave Hylandsc89c6812014-01-24 01:05:30 -080084ifndef DEBUG
Paul Sokolovsky0fc7efb2014-06-20 20:25:35 +030085 $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
Dave Hylandsc89c6812014-01-24 01:05:30 -080086endif
Andrew Scheller902d9552014-04-07 01:35:45 +010087 $(Q)$(SIZE) $(PROG)
Dave Hylandsc89c6812014-01-24 01:05:30 -080088
89clean: clean-prog
90clean-prog:
91 $(RM) -f $(PROG)
Andrew Scheller83346742014-04-11 00:41:59 +010092 $(RM) -f $(PROG).map
Dave Hylandsc89c6812014-01-24 01:05:30 -080093
94.PHONY: clean-prog
95endif
96
97clean:
98 $(RM) -rf $(BUILD)
99.PHONY: clean
100
101print-cfg:
102 $(ECHO) "PY_SRC = $(PY_SRC)"
103 $(ECHO) "BUILD = $(BUILD)"
104 $(ECHO) "OBJ = $(OBJ)"
105.PHONY: print-cfg
106
Dave Hylands4f1b7fe2014-06-15 22:33:14 -0700107print-def:
108 @$(ECHO) "The following defines are built into the $(CC) compiler"
109 touch __empty__.c
110 @$(CC) -E -Wp,-dM __empty__.c
111 @$(RM) -f __empty__.c
112
Dave Hylandsc89c6812014-01-24 01:05:30 -0800113-include $(OBJ:.o=.P)