Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 1 | ifneq ($(MKENV_INCLUDED),1) |
| 2 | # We assume that mkenv is in the same directory as this file. |
| 3 | THIS_MAKEFILE = $(lastword $(MAKEFILE_LIST)) |
| 4 | include $(dir $(THIS_MAKEFILE))mkenv.mk |
| 5 | endif |
| 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 | |
| 23 | vpath %.S . $(TOP) |
| 24 | $(BUILD)/%.o: %.S |
| 25 | $(ECHO) "CC $<" |
| 26 | $(Q)$(CC) $(CFLAGS) -c -o $@ $< |
| 27 | |
| 28 | vpath %.s . $(TOP) |
| 29 | $(BUILD)/%.o: %.s |
| 30 | $(ECHO) "AS $<" |
| 31 | $(Q)$(AS) -o $@ $< |
| 32 | |
| 33 | define 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 Scheller | 902d955 | 2014-04-07 01:35:45 +0100 | [diff] [blame] | 38 | @$(CP) $(@:.o=.d) $(@:.o=.P); \ |
| 39 | $(SED) -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 40 | -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \ |
Andrew Scheller | 902d955 | 2014-04-07 01:35:45 +0100 | [diff] [blame] | 41 | $(RM) -f $(@:.o=.d) |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 42 | endef |
| 43 | |
| 44 | vpath %.c . $(TOP) |
| 45 | $(BUILD)/%.o: %.c |
| 46 | $(call compile_c) |
| 47 | |
Dave Hylands | ca5444e | 2014-03-14 23:41:28 -0700 | [diff] [blame] | 48 | $(BUILD)/%.pp: %.c |
| 49 | $(ECHO) "PreProcess $<" |
| 50 | $(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $< |
| 51 | |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 52 | # 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 George | d553be5 | 2014-04-17 18:03:27 +0100 | [diff] [blame] | 54 | # checking to be performed. |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 55 | # |
Sven Wegener | b98c162 | 2014-11-06 09:25:44 +0100 | [diff] [blame] | 56 | # 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 Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 63 | # $(sort $(var)) removes duplicates |
| 64 | # |
| 65 | # The net effect of this, is it causes the objects to depend on the |
Damien George | d553be5 | 2014-04-17 18:03:27 +0100 | [diff] [blame] | 66 | # object directories (but only for existence), and the object directories |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 67 | # will be created if they don't exist. |
| 68 | OBJ_DIRS = $(sort $(dir $(OBJ))) |
Sven Wegener | b98c162 | 2014-11-06 09:25:44 +0100 | [diff] [blame] | 69 | $(OBJ): | $(OBJ_DIRS) |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 70 | $(OBJ_DIRS): |
Andrew Scheller | 902d955 | 2014-04-07 01:35:45 +0100 | [diff] [blame] | 71 | $(MKDIR) -p $@ |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 72 | |
Andrew Scheller | 70a7d7a | 2014-04-16 22:10:33 +0100 | [diff] [blame] | 73 | $(HEADER_BUILD): |
| 74 | $(MKDIR) -p $@ |
| 75 | |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 76 | ifneq ($(PROG),) |
| 77 | # Build a standalone executable (unix and unix-cpy do this) |
| 78 | |
| 79 | all: $(PROG) |
| 80 | |
| 81 | $(PROG): $(OBJ) |
Dave Hylands | 1a3b0d5 | 2014-01-25 08:55:31 -0800 | [diff] [blame] | 82 | $(ECHO) "LINK $@" |
Paul Sokolovsky | 4c4b9d1 | 2014-06-20 20:33:20 +0300 | [diff] [blame] | 83 | $(Q)$(CC) $(COPT) -o $@ $(OBJ) $(LIB) $(LDFLAGS) |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 84 | ifndef DEBUG |
Paul Sokolovsky | 0fc7efb | 2014-06-20 20:25:35 +0300 | [diff] [blame] | 85 | $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG) |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 86 | endif |
Andrew Scheller | 902d955 | 2014-04-07 01:35:45 +0100 | [diff] [blame] | 87 | $(Q)$(SIZE) $(PROG) |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 88 | |
| 89 | clean: clean-prog |
| 90 | clean-prog: |
| 91 | $(RM) -f $(PROG) |
Andrew Scheller | 8334674 | 2014-04-11 00:41:59 +0100 | [diff] [blame] | 92 | $(RM) -f $(PROG).map |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 93 | |
| 94 | .PHONY: clean-prog |
| 95 | endif |
| 96 | |
| 97 | clean: |
| 98 | $(RM) -rf $(BUILD) |
| 99 | .PHONY: clean |
| 100 | |
| 101 | print-cfg: |
| 102 | $(ECHO) "PY_SRC = $(PY_SRC)" |
| 103 | $(ECHO) "BUILD = $(BUILD)" |
| 104 | $(ECHO) "OBJ = $(OBJ)" |
| 105 | .PHONY: print-cfg |
| 106 | |
Dave Hylands | 4f1b7fe | 2014-06-15 22:33:14 -0700 | [diff] [blame] | 107 | print-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 Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 113 | -include $(OBJ:.o=.P) |