2014-01-24 04:05:30 -05: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
|
2016-11-14 16:15:45 -05:00
|
|
|
# and should not contain any ..'s but rather be relative to the top of the
|
2014-01-24 04:05:30 -05: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.
|
|
|
|
|
|
|
|
vpath %.S . $(TOP)
|
|
|
|
$(BUILD)/%.o: %.S
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "CC $<"
|
2014-01-24 04:05:30 -05:00
|
|
|
$(Q)$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
vpath %.s . $(TOP)
|
|
|
|
$(BUILD)/%.o: %.s
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "AS $<"
|
2014-01-24 04:05:30 -05:00
|
|
|
$(Q)$(AS) -o $@ $<
|
|
|
|
|
|
|
|
define compile_c
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "CC $<"
|
2014-01-24 04:05:30 -05:00
|
|
|
$(Q)$(CC) $(CFLAGS) -c -MD -o $@ $<
|
|
|
|
@# The following fixes the dependency file.
|
|
|
|
@# See http://make.paulandlesley.org/autodep.html for details.
|
2015-05-06 08:34:33 -04:00
|
|
|
@# Regex adjusted from the above to play better with Windows paths, etc.
|
2014-04-06 20:35:45 -04:00
|
|
|
@$(CP) $(@:.o=.d) $(@:.o=.P); \
|
2015-05-05 14:39:28 -04:00
|
|
|
$(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
|
2014-01-24 04:05:30 -05:00
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
|
2014-04-06 20:35:45 -04:00
|
|
|
$(RM) -f $(@:.o=.d)
|
2014-01-24 04:05:30 -05:00
|
|
|
endef
|
|
|
|
|
|
|
|
vpath %.c . $(TOP)
|
|
|
|
$(BUILD)/%.o: %.c
|
|
|
|
$(call compile_c)
|
|
|
|
|
2017-10-03 18:10:13 -04:00
|
|
|
# frozen.c and frozen_mpy.c are created in $(BUILD), so use our rule
|
|
|
|
# for those as well.
|
|
|
|
vpath %.c . $(BUILD)
|
|
|
|
$(BUILD)/%.o: %.c
|
|
|
|
$(call compile_c)
|
|
|
|
|
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 04:22:41 -05:00
|
|
|
# List all native flags since the current build system doesn't have
|
2017-06-30 03:22:17 -04:00
|
|
|
# the MicroPython configuration available. However, these flags are
|
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 04:22:41 -05:00
|
|
|
# needed to extract all qstrings
|
2016-12-09 00:39:39 -05:00
|
|
|
QSTR_GEN_EXTRA_CFLAGS += -DNO_QSTR -DN_X64 -DN_X86 -DN_THUMB -DN_ARM -DN_XTENSA
|
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 04:22:41 -05:00
|
|
|
QSTR_GEN_EXTRA_CFLAGS += -I$(BUILD)/tmp
|
|
|
|
|
|
|
|
vpath %.c . $(TOP)
|
|
|
|
|
2014-03-15 02:41:28 -04:00
|
|
|
$(BUILD)/%.pp: %.c
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "PreProcess $<"
|
2014-03-15 02:41:28 -04:00
|
|
|
$(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<
|
|
|
|
|
2016-04-26 05:39:28 -04:00
|
|
|
# The following rule uses | to create an order only prerequisite. Order only
|
2014-01-24 04:05:30 -05:00
|
|
|
# prerequisites only get built if they don't exist. They don't cause timestamp
|
2014-04-17 13:03:27 -04:00
|
|
|
# checking to be performed.
|
2014-01-24 04:05:30 -05:00
|
|
|
#
|
2014-11-06 03:25:44 -05: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 05:39:28 -04:00
|
|
|
# an order-only dependency to all of the .o's will cause the generated .h
|
2014-11-06 03:25:44 -05:00
|
|
|
# to get built before we try to compile any of them.
|
2015-04-22 12:38:05 -04:00
|
|
|
$(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/mpversion.h
|
2014-11-06 03:25:44 -05:00
|
|
|
|
2016-04-19 04:30:06 -04:00
|
|
|
$(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) | $(HEADER_BUILD)/mpversion.h
|
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 04:22:41 -05:00
|
|
|
$(ECHO) "GEN $@"
|
2017-05-25 07:43:01 -04:00
|
|
|
$(Q)$(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $(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 04:22:41 -05:00
|
|
|
|
2016-04-19 07:39:08 -04:00
|
|
|
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "GEN $@"
|
2016-04-19 07:39:08 -04:00
|
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
|
|
|
|
$(Q)touch $@
|
|
|
|
|
|
|
|
$(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "GEN $@"
|
2016-04-19 07:39:08 -04:00
|
|
|
$(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 04:22:41 -05:00
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
# $(sort $(var)) removes duplicates
|
|
|
|
#
|
|
|
|
# The net effect of this, is it causes the objects to depend on the
|
2014-04-17 13:03:27 -04:00
|
|
|
# object directories (but only for existence), and the object directories
|
2014-01-24 04:05:30 -05:00
|
|
|
# will be created if they don't exist.
|
|
|
|
OBJ_DIRS = $(sort $(dir $(OBJ)))
|
2014-11-06 03:25:44 -05:00
|
|
|
$(OBJ): | $(OBJ_DIRS)
|
2014-01-24 04:05:30 -05:00
|
|
|
$(OBJ_DIRS):
|
2017-02-24 09:59:59 -05:00
|
|
|
$(Q)$(MKDIR) -p $@
|
2014-01-24 04:05:30 -05:00
|
|
|
|
2014-04-16 17:10:33 -04:00
|
|
|
$(HEADER_BUILD):
|
2017-02-24 09:59:59 -05:00
|
|
|
$(Q)$(MKDIR) -p $@
|
2014-04-16 17:10:33 -04:00
|
|
|
|
2016-09-17 13:57:43 -04:00
|
|
|
ifneq ($(FROZEN_DIR),)
|
|
|
|
$(BUILD)/frozen.c: $(wildcard $(FROZEN_DIR)/*) $(HEADER_BUILD) $(FROZEN_EXTRA_DEPS)
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "Generating $@"
|
2016-09-17 13:57:43 -04:00
|
|
|
$(Q)$(MAKE_FROZEN) $(FROZEN_DIR) > $@
|
|
|
|
endif
|
|
|
|
|
2017-08-23 14:05:59 -04:00
|
|
|
ifneq ($(FROZEN_MPY_DIRS),)
|
2017-04-22 04:10:13 -04:00
|
|
|
# to build the MicroPython cross compiler
|
2017-08-23 14:05:59 -04:00
|
|
|
# Currently not used, because the wrong mpy-cross may be left over from a previous build. Build by hand to make sure.
|
2017-10-25 01:31:16 -04:00
|
|
|
$(MPY_CROSS): $(TOP)/py/*.[ch] $(TOP)/mpy-cross/*.[ch] $(TOP)/ports/windows/fmode.c
|
2017-04-22 04:10:13 -04:00
|
|
|
$(Q)$(MAKE) -C $(TOP)/mpy-cross
|
|
|
|
|
2017-08-23 14:05:59 -04:00
|
|
|
# Copy all the modules and single python files to freeze to a common area, omitting top-level dirs (the repo names).
|
2018-01-02 21:25:41 -05:00
|
|
|
# Do any preprocessing necessary: currently, this adds version information, removes examples, and
|
|
|
|
# non-library .py files in the modules (setup.py and conf.py)
|
2017-08-23 14:05:59 -04:00
|
|
|
# Then compile .mpy files from all the .py files, placing them in the same directories as the .py files.
|
|
|
|
$(BUILD)/frozen_mpy: $(FROZEN_MPY_DIRS)
|
|
|
|
$(ECHO) FREEZE $(FROZEN_MPY_DIRS)
|
|
|
|
$(Q)$(MKDIR) -p $@
|
2018-01-02 21:25:41 -05:00
|
|
|
$(Q)$(PREPROCESS_FROZEN_MODULES) -o $@ $(FROZEN_MPY_DIRS)
|
2017-08-23 14:05:59 -04:00
|
|
|
$(Q)$(CD) $@ && \
|
|
|
|
$(FIND) -L . -type f -name '*.py' | sed 's=^\./==' | \
|
|
|
|
xargs -n1 $(abspath $(MPY_CROSS)) $(MPY_CROSS_FLAGS)
|
2016-11-07 22:28:30 -05:00
|
|
|
|
|
|
|
# to build frozen_mpy.c from all .mpy files
|
2017-07-15 17:03:24 -04:00
|
|
|
# You need to define MPY_TOOL_LONGINT_IMPL in mpconfigport.mk
|
|
|
|
# if the default will not work (mpz is the default).
|
2017-08-23 14:05:59 -04:00
|
|
|
$(BUILD)/frozen_mpy.c: $(BUILD)/frozen_mpy $(BUILD)/genhdr/qstrdefs.generated.h
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "Creating $@"
|
2017-08-23 14:05:59 -04:00
|
|
|
$(Q)$(PYTHON) $(MPY_TOOL) $(MPY_TOOL_LONGINT_IMPL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(shell $(FIND) -L $(BUILD)/frozen_mpy -type f -name '*.mpy') > $@
|
2016-11-07 22:28:30 -05:00
|
|
|
endif
|
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
ifneq ($(PROG),)
|
2015-08-14 07:24:11 -04:00
|
|
|
# Build a standalone executable (unix does this)
|
2014-01-24 04:05:30 -05:00
|
|
|
|
|
|
|
all: $(PROG)
|
|
|
|
|
|
|
|
$(PROG): $(OBJ)
|
2017-02-24 09:59:59 -05:00
|
|
|
$(STEPECHO) "LINK $@"
|
2015-12-09 17:49:25 -05: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 04:05:30 -05:00
|
|
|
ifndef DEBUG
|
2017-10-31 07:01:56 -04:00
|
|
|
$(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
|
2014-01-24 04:05:30 -05:00
|
|
|
endif
|
2017-10-31 07:01:56 -04:00
|
|
|
$(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $(PROG)
|
2014-01-24 04:05:30 -05:00
|
|
|
|
|
|
|
clean: clean-prog
|
|
|
|
clean-prog:
|
2017-10-31 07:01:56 -04:00
|
|
|
$(RM) -f $(PROG)
|
2014-04-10 19:41:59 -04:00
|
|
|
$(RM) -f $(PROG).map
|
2014-01-24 04:05:30 -05:00
|
|
|
|
|
|
|
.PHONY: clean-prog
|
|
|
|
endif
|
|
|
|
|
2016-08-29 17:59:17 -04:00
|
|
|
LIBMICROPYTHON = libmicropython.a
|
2017-03-29 17:08:27 -04: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 17:59:17 -04:00
|
|
|
lib $(LIBMICROPYTHON): $(OBJ)
|
|
|
|
$(AR) rcs $(LIBMICROPYTHON) $^
|
2017-03-29 17:08:27 -04:00
|
|
|
$(LIBMICROPYTHON_EXTRA_CMD)
|
2016-06-15 18:11:24 -04:00
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
clean:
|
2016-08-04 16:40:15 -04:00
|
|
|
$(RM) -rf $(BUILD) $(CLEAN_EXTRA)
|
2014-01-24 04:05:30 -05:00
|
|
|
.PHONY: clean
|
|
|
|
|
|
|
|
print-cfg:
|
|
|
|
$(ECHO) "PY_SRC = $(PY_SRC)"
|
|
|
|
$(ECHO) "BUILD = $(BUILD)"
|
|
|
|
$(ECHO) "OBJ = $(OBJ)"
|
|
|
|
.PHONY: print-cfg
|
|
|
|
|
2014-06-16 01:33:14 -04: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
|
|
|
|
|
2017-11-14 20:00:29 -05:00
|
|
|
tags:
|
|
|
|
ctags -e -R $(TOP)
|
|
|
|
|
2014-01-24 04:05:30 -05:00
|
|
|
-include $(OBJ:.o=.P)
|
2017-11-14 20:00:29 -05:00
|
|
|
|