2014-01-24 09:05:30 +00:00
|
|
|
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.
|
2015-05-06 13:34:33 +01:00
|
|
|
@# Regex adjusted from the above to play better with Windows paths, etc.
|
2014-04-07 01:35:45 +01:00
|
|
|
@$(CP) $(@:.o=.d) $(@:.o=.P); \
|
2015-05-05 19:39:28 +01:00
|
|
|
$(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
|
2014-01-24 09:05:30 +00:00
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
|
2014-04-07 01:35:45 +01:00
|
|
|
$(RM) -f $(@:.o=.d)
|
2014-01-24 09:05:30 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
vpath %.c . $(TOP)
|
|
|
|
$(BUILD)/%.o: %.c
|
|
|
|
$(call compile_c)
|
|
|
|
|
2014-03-15 06:41:28 +00:00
|
|
|
$(BUILD)/%.pp: %.c
|
|
|
|
$(ECHO) "PreProcess $<"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<
|
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
# 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
|
2014-04-17 18:03:27 +01:00
|
|
|
# checking to be performed.
|
2014-01-24 09:05:30 +00:00
|
|
|
#
|
2014-11-06 08:25:44 +00:00
|
|
|
# We don't know which source files actually need the generated.h (since
|
|
|
|
# it is #included from str.h). The compiler generated dependencies will cause
|
|
|
|
# the right .o's to get recompiled if the generated.h file changes. Adding
|
|
|
|
# an order-only dependendency to all of the .o's will cause the generated .h
|
|
|
|
# to get built before we try to compile any of them.
|
2015-04-22 17:38:05 +01:00
|
|
|
$(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/mpversion.h
|
2014-11-06 08:25:44 +00:00
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
# $(sort $(var)) removes duplicates
|
|
|
|
#
|
|
|
|
# The net effect of this, is it causes the objects to depend on the
|
2014-04-17 18:03:27 +01:00
|
|
|
# object directories (but only for existence), and the object directories
|
2014-01-24 09:05:30 +00:00
|
|
|
# will be created if they don't exist.
|
|
|
|
OBJ_DIRS = $(sort $(dir $(OBJ)))
|
2014-11-06 08:25:44 +00:00
|
|
|
$(OBJ): | $(OBJ_DIRS)
|
2014-01-24 09:05:30 +00:00
|
|
|
$(OBJ_DIRS):
|
2014-04-07 01:35:45 +01:00
|
|
|
$(MKDIR) -p $@
|
2014-01-24 09:05:30 +00:00
|
|
|
|
2014-04-16 22:10:33 +01:00
|
|
|
$(HEADER_BUILD):
|
|
|
|
$(MKDIR) -p $@
|
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
ifneq ($(PROG),)
|
2015-08-14 12:24:11 +01:00
|
|
|
# Build a standalone executable (unix does this)
|
2014-01-24 09:05:30 +00:00
|
|
|
|
|
|
|
all: $(PROG)
|
|
|
|
|
|
|
|
$(PROG): $(OBJ)
|
2014-01-25 16:55:31 +00:00
|
|
|
$(ECHO) "LINK $@"
|
2015-12-09 22:49:25 +00:00
|
|
|
# Do not pass COPT here - it's *C* compiler optimizations. For example,
|
|
|
|
# we may want to compile using Thumb, but link with non-Thumb libc.
|
|
|
|
$(Q)$(CC) -o $@ $^ $(LIB) $(LDFLAGS)
|
2014-01-24 09:05:30 +00:00
|
|
|
ifndef DEBUG
|
2014-06-20 18:25:35 +01:00
|
|
|
$(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
|
2014-01-24 09:05:30 +00:00
|
|
|
endif
|
2014-04-07 01:35:45 +01:00
|
|
|
$(Q)$(SIZE) $(PROG)
|
2014-01-24 09:05:30 +00:00
|
|
|
|
2015-10-12 12:42:05 +01:00
|
|
|
lib: $(OBJ)
|
2015-10-24 00:26:10 +01:00
|
|
|
$(AR) rcs libmicropython.a $^
|
2015-10-12 12:42:05 +01:00
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
clean: clean-prog
|
|
|
|
clean-prog:
|
|
|
|
$(RM) -f $(PROG)
|
2014-04-11 00:41:59 +01:00
|
|
|
$(RM) -f $(PROG).map
|
2014-01-24 09:05:30 +00:00
|
|
|
|
|
|
|
.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
|
|
|
|
|
2014-06-16 06:33:14 +01:00
|
|
|
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
|
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
-include $(OBJ:.o=.P)
|