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
|
2017-07-19 04:12:10 +01:00
|
|
|
# and should not contain any ..'s but rather be relative to the top of the
|
2014-01-24 09:05:30 +00:00
|
|
|
# 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.
|
|
|
|
|
2018-12-12 05:50:55 +00:00
|
|
|
vpath %.S . $(TOP) $(USER_C_MODULES)
|
2014-01-24 09:05:30 +00:00
|
|
|
$(BUILD)/%.o: %.S
|
|
|
|
$(ECHO) "CC $<"
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
|
2018-12-12 05:50:55 +00:00
|
|
|
vpath %.s . $(TOP) $(USER_C_MODULES)
|
2014-01-24 09:05:30 +00:00
|
|
|
$(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
|
|
|
|
|
2018-12-12 05:50:55 +00:00
|
|
|
vpath %.c . $(TOP) $(USER_C_MODULES)
|
2014-01-24 09:05:30 +00:00
|
|
|
$(BUILD)/%.o: %.c
|
|
|
|
$(call compile_c)
|
|
|
|
|
2018-04-10 06:06:47 +01:00
|
|
|
QSTR_GEN_EXTRA_CFLAGS += -DNO_QSTR
|
py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file
- add special rule for generating a central header that contains all
extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
variable. Each platform appends a list of sources that may contain
qstrings into a new build variable: SRC_QSTR. Any autogenerated
prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.
- remove most qstrings from py/qstrdefs, keep only qstrings that
contain special characters - these cannot be easily detected in the
sources without additional annotations
- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
stmhal, teensy, unix, windows, pic16bit:
- remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
- remove all port specific qstrdefs except for special strings
- append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-03-10 09:22:41 +00:00
|
|
|
QSTR_GEN_EXTRA_CFLAGS += -I$(BUILD)/tmp
|
|
|
|
|
2018-12-12 05:50:55 +00:00
|
|
|
vpath %.c . $(TOP) $(USER_C_MODULES)
|
py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file
- add special rule for generating a central header that contains all
extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
variable. Each platform appends a list of sources that may contain
qstrings into a new build variable: SRC_QSTR. Any autogenerated
prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.
- remove most qstrings from py/qstrdefs, keep only qstrings that
contain special characters - these cannot be easily detected in the
sources without additional annotations
- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
stmhal, teensy, unix, windows, pic16bit:
- remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
- remove all port specific qstrdefs except for special strings
- append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-03-10 09:22:41 +00:00
|
|
|
|
2014-03-15 06:41:28 +00:00
|
|
|
$(BUILD)/%.pp: %.c
|
|
|
|
$(ECHO) "PreProcess $<"
|
2019-06-24 13:11:56 +01:00
|
|
|
$(Q)$(CPP) $(CFLAGS) -Wp,-C,-dD,-dI -o $@ $<
|
2014-03-15 06:41:28 +00:00
|
|
|
|
2016-04-26 10:39:28 +01:00
|
|
|
# The following rule uses | to create an order only prerequisite. Order only
|
2014-01-24 09:05:30 +00:00
|
|
|
# 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
|
2016-04-26 10:39:28 +01:00
|
|
|
# an order-only dependency to all of the .o's will cause the generated .h
|
2014-11-06 08:25:44 +00:00
|
|
|
# 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
|
|
|
|
2018-06-09 06:23:13 +01:00
|
|
|
# The logic for qstr regeneration is:
|
|
|
|
# - if anything in QSTR_GLOBAL_DEPENDENCIES is newer, then process all source files ($^)
|
|
|
|
# - else, if list of newer prerequisites ($?) is not empty, then process just these ($?)
|
|
|
|
# - else, process all source files ($^) [this covers "make -B" which can set $? to empty]
|
2019-09-26 11:25:39 +01:00
|
|
|
# See more information about this process in docs/develop/qstr.rst.
|
2019-09-11 06:47:52 +01:00
|
|
|
$(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(QSTR_GLOBAL_DEPENDENCIES) | $(QSTR_GLOBAL_REQUIREMENTS)
|
py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file
- add special rule for generating a central header that contains all
extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
variable. Each platform appends a list of sources that may contain
qstrings into a new build variable: SRC_QSTR. Any autogenerated
prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.
- remove most qstrings from py/qstrdefs, keep only qstrings that
contain special characters - these cannot be easily detected in the
sources without additional annotations
- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
stmhal, teensy, unix, windows, pic16bit:
- remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
- remove all port specific qstrdefs except for special strings
- append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-03-10 09:22:41 +00:00
|
|
|
$(ECHO) "GEN $@"
|
2019-05-21 13:27:05 +01:00
|
|
|
$(Q)$(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $(if $(filter $?,$(QSTR_GLOBAL_DEPENDENCIES)),$^,$(if $?,$?,$^)) >$(HEADER_BUILD)/qstr.i.last
|
py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file
- add special rule for generating a central header that contains all
extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
variable. Each platform appends a list of sources that may contain
qstrings into a new build variable: SRC_QSTR. Any autogenerated
prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.
- remove most qstrings from py/qstrdefs, keep only qstrings that
contain special characters - these cannot be easily detected in the
sources without additional annotations
- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
stmhal, teensy, unix, windows, pic16bit:
- remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
- remove all port specific qstrdefs except for special strings
- append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-03-10 09:22:41 +00:00
|
|
|
|
2016-04-19 12:39:08 +01:00
|
|
|
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last
|
2016-04-19 09:30:06 +01:00
|
|
|
$(ECHO) "GEN $@"
|
2016-04-19 12:39:08 +01:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
|
2019-05-21 10:35:09 +01:00
|
|
|
$(Q)$(TOUCH) $@
|
2016-04-19 12:39:08 +01:00
|
|
|
|
|
|
|
$(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split
|
|
|
|
$(ECHO) "GEN $@"
|
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
|
py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file
- add special rule for generating a central header that contains all
extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
variable. Each platform appends a list of sources that may contain
qstrings into a new build variable: SRC_QSTR. Any autogenerated
prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.
- remove most qstrings from py/qstrdefs, keep only qstrings that
contain special characters - these cannot be easily detected in the
sources without additional annotations
- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
stmhal, teensy, unix, windows, pic16bit:
- remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
- remove all port specific qstrdefs except for special strings
- append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-03-10 09:22:41 +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 $@
|
|
|
|
|
2019-09-09 15:49:02 +01:00
|
|
|
ifneq ($(FROZEN_MANIFEST),)
|
|
|
|
# to build frozen_content.c from a manifest
|
|
|
|
$(BUILD)/frozen_content.c: FORCE $(BUILD)/genhdr/qstrdefs.generated.h
|
2019-10-16 05:12:39 +01:00
|
|
|
$(Q)$(MAKE_MANIFEST) -o $@ -v "MPY_DIR=$(TOP)" -v "MPY_LIB_DIR=$(MPY_LIB_DIR)" -v "PORT_DIR=$(shell pwd)" -v "BOARD_DIR=$(BOARD_DIR)" -b "$(BUILD)" $(if $(MPY_CROSS_FLAGS),-f"$(MPY_CROSS_FLAGS)",) $(FROZEN_MANIFEST)
|
2019-10-18 14:38:35 +01:00
|
|
|
|
|
|
|
ifneq ($(FROZEN_DIR),)
|
|
|
|
$(error FROZEN_DIR cannot be used in conjunction with FROZEN_MANIFEST)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(FROZEN_MPY_DIR),)
|
|
|
|
$(error FROZEN_MPY_DIR cannot be used in conjunction with FROZEN_MANIFEST)
|
|
|
|
endif
|
2019-09-09 15:49:02 +01:00
|
|
|
endif
|
|
|
|
|
2016-09-17 18:57:43 +01:00
|
|
|
ifneq ($(FROZEN_DIR),)
|
2019-10-18 14:38:35 +01:00
|
|
|
$(info Warning: FROZEN_DIR is deprecated in favour of FROZEN_MANIFEST)
|
2016-09-17 18:57:43 +01:00
|
|
|
$(BUILD)/frozen.c: $(wildcard $(FROZEN_DIR)/*) $(HEADER_BUILD) $(FROZEN_EXTRA_DEPS)
|
2018-02-22 00:35:53 +00:00
|
|
|
$(ECHO) "GEN $@"
|
2016-09-17 18:57:43 +01:00
|
|
|
$(Q)$(MAKE_FROZEN) $(FROZEN_DIR) > $@
|
|
|
|
endif
|
|
|
|
|
2016-11-08 03:28:30 +00:00
|
|
|
ifneq ($(FROZEN_MPY_DIR),)
|
2019-10-18 14:38:35 +01:00
|
|
|
$(info Warning: FROZEN_MPY_DIR is deprecated in favour of FROZEN_MANIFEST)
|
2016-11-08 03:28:30 +00:00
|
|
|
# make a list of all the .py files that need compiling and freezing
|
2016-11-15 05:09:43 +00:00
|
|
|
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)/==')
|
2016-11-08 03:36:06 +00:00
|
|
|
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/frozen_mpy/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
|
2016-11-08 03:28:30 +00:00
|
|
|
|
|
|
|
# to build .mpy files from .py files
|
2019-05-31 05:37:11 +01:00
|
|
|
$(BUILD)/frozen_mpy/%.mpy: $(FROZEN_MPY_DIR)/%.py
|
2016-11-08 03:28:30 +00:00
|
|
|
@$(ECHO) "MPY $<"
|
|
|
|
$(Q)$(MKDIR) -p $(dir $@)
|
2017-04-22 09:10:13 +01:00
|
|
|
$(Q)$(MPY_CROSS) -o $@ -s $(<:$(FROZEN_MPY_DIR)/%=%) $(MPY_CROSS_FLAGS) $<
|
2016-11-08 03:28:30 +00:00
|
|
|
|
|
|
|
# to build frozen_mpy.c from all .mpy files
|
|
|
|
$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h
|
2018-02-22 00:35:53 +00:00
|
|
|
@$(ECHO) "GEN $@"
|
2017-10-31 16:19:12 +00:00
|
|
|
$(Q)$(MPY_TOOL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(FROZEN_MPY_MPY_FILES) > $@
|
2016-11-08 03:28:30 +00:00
|
|
|
endif
|
|
|
|
|
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
|
2017-10-31 11:01:56 +00:00
|
|
|
$(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
|
2014-01-24 09:05:30 +00:00
|
|
|
endif
|
2017-10-31 11:01:56 +00:00
|
|
|
$(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $(PROG)
|
2014-01-24 09:05:30 +00:00
|
|
|
|
|
|
|
clean: clean-prog
|
|
|
|
clean-prog:
|
2017-10-31 11:01:56 +00:00
|
|
|
$(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
|
|
|
|
|
2019-10-14 02:09:06 +01:00
|
|
|
submodules:
|
|
|
|
$(ECHO) "Updating submodules: $(GIT_SUBMODULES)"
|
|
|
|
ifneq ($(GIT_SUBMODULES),)
|
|
|
|
$(Q)git submodule update --init $(addprefix $(TOP)/,$(GIT_SUBMODULES))
|
|
|
|
endif
|
|
|
|
.PHONY: submodules
|
|
|
|
|
2016-08-29 22:59:17 +01:00
|
|
|
LIBMICROPYTHON = libmicropython.a
|
2017-03-29 22:08:27 +01:00
|
|
|
|
|
|
|
# We can execute extra commands after library creation using
|
|
|
|
# LIBMICROPYTHON_EXTRA_CMD. This may be needed e.g. to integrate
|
|
|
|
# with 3rd-party projects which don't have proper dependency
|
|
|
|
# tracking. Then LIBMICROPYTHON_EXTRA_CMD can e.g. touch some
|
|
|
|
# other file to cause needed effect, e.g. relinking with new lib.
|
2016-08-29 22:59:17 +01:00
|
|
|
lib $(LIBMICROPYTHON): $(OBJ)
|
|
|
|
$(AR) rcs $(LIBMICROPYTHON) $^
|
2017-03-29 22:08:27 +01:00
|
|
|
$(LIBMICROPYTHON_EXTRA_CMD)
|
2016-06-15 23:11:24 +01:00
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
clean:
|
2016-08-04 21:40:15 +01:00
|
|
|
$(RM) -rf $(BUILD) $(CLEAN_EXTRA)
|
2014-01-24 09:05:30 +00:00
|
|
|
.PHONY: clean
|
|
|
|
|
2017-12-09 23:05:29 +00:00
|
|
|
# Clean every non-git file from FROZEN_DIR/FROZEN_MPY_DIR, but making a backup.
|
|
|
|
# We run rmdir below to avoid empty backup dir (it will silently fail if backup
|
|
|
|
# is non-empty).
|
|
|
|
clean-frozen:
|
|
|
|
if [ -n "$(FROZEN_MPY_DIR)" ]; then \
|
|
|
|
backup_dir=$(FROZEN_MPY_DIR).$$(date +%Y%m%dT%H%M%S); mkdir $$backup_dir; \
|
|
|
|
cd $(FROZEN_MPY_DIR); git status --ignored -u all -s . | awk ' {print $$2}' \
|
|
|
|
| xargs --no-run-if-empty cp --parents -t ../$$backup_dir; \
|
|
|
|
rmdir ../$$backup_dir 2>/dev/null || true; \
|
|
|
|
git clean -d -f .; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$(FROZEN_DIR)" ]; then \
|
|
|
|
backup_dir=$(FROZEN_DIR).$$(date +%Y%m%dT%H%M%S); mkdir $$backup_dir; \
|
|
|
|
cd $(FROZEN_DIR); git status --ignored -u all -s . | awk ' {print $$2}' \
|
|
|
|
| xargs --no-run-if-empty cp --parents -t ../$$backup_dir; \
|
|
|
|
rmdir ../$$backup_dir 2>/dev/null || true; \
|
|
|
|
git clean -d -f .; \
|
|
|
|
fi
|
|
|
|
.PHONY: clean-frozen
|
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
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"
|
2019-05-21 10:35:09 +01:00
|
|
|
$(TOUCH) __empty__.c
|
2014-06-16 06:33:14 +01:00
|
|
|
@$(CC) -E -Wp,-dM __empty__.c
|
|
|
|
@$(RM) -f __empty__.c
|
|
|
|
|
2014-01-24 09:05:30 +00:00
|
|
|
-include $(OBJ:.o=.P)
|