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. |
| 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) |
| 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 |
| 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. |
| 61 | OBJ_DIRS = $(sort $(dir $(OBJ))) |
| 62 | $(OBJ): | $(OBJ_DIRS) |
| 63 | $(OBJ_DIRS): |
| 64 | mkdir -p $@ |
| 65 | |
| 66 | ifneq ($(PROG),) |
| 67 | # Build a standalone executable (unix and unix-cpy do this) |
| 68 | |
| 69 | all: $(PROG) |
| 70 | |
| 71 | $(PROG): $(OBJ) |
Dave Hylands | 1a3b0d5 | 2014-01-25 08:55:31 -0800 | [diff] [blame] | 72 | $(ECHO) "LINK $@" |
Dave Hylands | c89c681 | 2014-01-24 01:05:30 -0800 | [diff] [blame] | 73 | $(Q)$(CC) -o $@ $(OBJ) $(LIB) $(LDFLAGS) |
| 74 | ifndef DEBUG |
| 75 | $(Q)strip $(PROG) |
| 76 | endif |
| 77 | $(Q)size $(PROG) |
| 78 | |
| 79 | clean: clean-prog |
| 80 | clean-prog: |
| 81 | $(RM) -f $(PROG) |
| 82 | |
| 83 | .PHONY: clean-prog |
| 84 | endif |
| 85 | |
| 86 | clean: |
| 87 | $(RM) -rf $(BUILD) |
| 88 | .PHONY: clean |
| 89 | |
| 90 | print-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) |