mkrules.mk 2.72 KB
Newer Older
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
ifneq ($(MKENV_INCLUDED),1)
# We assume that mkenv is in the same directory as this file.
THIS_MAKEFILE = $(lastword $(MAKEFILE_LIST))
include $(dir $(THIS_MAKEFILE))mkenv.mk
endif

# This file expects that OBJ contains a list of all of the object files.
# The directory portion of each object file is used to locate the source
# and should not contain any ..'s but rather be relative to the top of the 
# tree.
#
# So for example, py/map.c would have an object file name py/map.o
# The object files will go into the build directory and mantain the same
# directory structure as the source tree. So the final dependency will look
# like this:
#
# build/py/map.o: py/map.c
#
# We set vpath to point to the top of the tree so that the source files
# can be located. By following this scheme, it allows a single build rule
# to be used to compile all .c files.

vpath %.S . $(TOP)
$(BUILD)/%.o: %.S
	$(ECHO) "CC $<"
	$(Q)$(CC) $(CFLAGS) -c -o $@ $<

vpath %.s . $(TOP)
$(BUILD)/%.o: %.s
	$(ECHO) "AS $<"
	$(Q)$(AS) -o $@ $<

define compile_c
$(ECHO) "CC $<"
$(Q)$(CC) $(CFLAGS) -c -MD -o $@ $<
@# The following fixes the dependency file.
@# See http://make.paulandlesley.org/autodep.html for details.
38
39
@$(CP) $(@:.o=.d) $(@:.o=.P); \
  $(SED) -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
40
      -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
41
  $(RM) -f $(@:.o=.d)
42
43
44
45
46
47
endef

vpath %.c . $(TOP)
$(BUILD)/%.o: %.c
	$(call compile_c)

48
49
50
51
$(BUILD)/%.pp: %.c
	$(ECHO) "PreProcess $<"
	$(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<

52
53
# The following rule uses | to create an order only prereuisite. Order only
# prerequisites only get built if they don't exist. They don't cause timestamp
54
# checking to be performed.
55
56
57
58
#
# $(sort $(var)) removes duplicates
#
# The net effect of this, is it causes the objects to depend on the
59
# object directories (but only for existence), and the object directories
60
61
# will be created if they don't exist.
OBJ_DIRS = $(sort $(dir $(OBJ)))
62
$(OBJ): $(HEADER_BUILD)/qstrdefs.generated.h | $(OBJ_DIRS)
63
$(OBJ_DIRS):
64
	$(MKDIR) -p $@
65

66
67
68
$(HEADER_BUILD):
	$(MKDIR) -p $@

69
70
71
72
73
74
ifneq ($(PROG),)
# Build a standalone executable (unix and unix-cpy do this)

all: $(PROG)

$(PROG): $(OBJ)
75
	$(ECHO) "LINK $@"
76
	$(Q)$(CC) $(COPT) -o $@ $(OBJ) $(LIB) $(LDFLAGS)
77
ifndef DEBUG
78
	$(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
79
endif
80
	$(Q)$(SIZE) $(PROG)
81
82
83
84

clean: clean-prog
clean-prog:
	$(RM) -f $(PROG)
Andrew Scheller's avatar
Andrew Scheller committed
85
	$(RM) -f $(PROG).map
86
87
88
89
90
91
92
93
94
95
96
97
98
99

.PHONY: clean-prog
endif

clean:
	$(RM) -rf $(BUILD)
.PHONY: clean

print-cfg:
	$(ECHO) "PY_SRC = $(PY_SRC)"
	$(ECHO) "BUILD  = $(BUILD)"
	$(ECHO) "OBJ    = $(OBJ)"
.PHONY: print-cfg

Dave Hylands's avatar
Dave Hylands committed
100
101
102
103
104
105
print-def:
	@$(ECHO) "The following defines are built into the $(CC) compiler"
	touch __empty__.c
	@$(CC) -E -Wp,-dM __empty__.c
	@$(RM) -f __empty__.c

106
-include $(OBJ:.o=.P)