c618f91e22
When there're C files to be (re)compiled, they're all passed first to preprocessor. QSTR references are extracted from preprocessed output and split per original C file. Then all available qstr files (including those generated previously) are catenated together. Only if the resulting content has changed, the output file is written (causing almost global rebuild to pick up potentially renumbered qstr's). Otherwise, it's not updated to not cause spurious rebuilds. Related make rules are split to minimize amount of commands executed in the interim case (when some C files were updated, but no qstrs were changed).
148 lines
4.5 KiB
Makefile
148 lines
4.5 KiB
Makefile
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.
|
|
@# Regex adjusted from the above to play better with Windows paths, etc.
|
|
@$(CP) $(@:.o=.d) $(@:.o=.P); \
|
|
$(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
|
|
$(RM) -f $(@:.o=.d)
|
|
endef
|
|
|
|
vpath %.c . $(TOP)
|
|
$(BUILD)/%.o: %.c
|
|
$(call compile_c)
|
|
|
|
# A empty qstrdefs header is needed to properly preprocess every file
|
|
EMPTY_QSTRDEFS_GENERATED_H = $(BUILD)/tmp/genhdr/qstrdefs.generated.h
|
|
|
|
# List all native flags since the current build system doesn't have
|
|
# the micropython configuration available. However, these flags are
|
|
# needed to extract all qstrings
|
|
QSTR_GEN_EXTRA_CFLAGS += -D__QSTR_EXTRACT -DN_X64 -DN_X86 -DN_THUMB -DN_ARM
|
|
QSTR_GEN_EXTRA_CFLAGS += -I$(BUILD)/tmp
|
|
|
|
vpath %.c . $(TOP)
|
|
$(HEADER_BUILD)/%.qstr: % mpconfigport.h $(PY_SRC)/mpconfig.h | $(EMPTY_QSTRDEFS_GENERATED_H) $(HEADER_BUILD)/mpversion.h $(SRC_QSTR_AUTO_DEPS)
|
|
@mkdir -p $(dir $@);
|
|
$(Q)$(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $< -o - | $(PYTHON) $(PY_SRC)/makeqstrdefs.py -s -o $@
|
|
|
|
|
|
$(BUILD)/%.pp: %.c
|
|
$(ECHO) "PreProcess $<"
|
|
$(Q)$(CC) $(CFLAGS) -E -Wp,-C,-dD,-dI -o $@ $<
|
|
|
|
$(EMPTY_QSTRDEFS_GENERATED_H):
|
|
$(ECHO) "Generate empty $@ to satisfy qstr generator"
|
|
$(Q)mkdir -p $(dir $@)
|
|
$(Q)touch $@
|
|
|
|
# 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
|
|
# checking to be performed.
|
|
#
|
|
# 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.
|
|
$(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/mpversion.h
|
|
|
|
$(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) | $(HEADER_BUILD)/mpversion.h
|
|
$(ECHO) "GEN $@"
|
|
$(Q)$(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $? >$(HEADER_BUILD)/qstr.i.last
|
|
|
|
$(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.i.last
|
|
$(ECHO) "GEN $@"
|
|
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py $(HEADER_BUILD)/qstr.i.last $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED)
|
|
|
|
# $(sort $(var)) removes duplicates
|
|
#
|
|
# The net effect of this, is it causes the objects to depend on the
|
|
# object directories (but only for existence), and the object directories
|
|
# will be created if they don't exist.
|
|
OBJ_DIRS = $(sort $(dir $(OBJ)))
|
|
$(OBJ): | $(OBJ_DIRS)
|
|
$(OBJ_DIRS):
|
|
$(MKDIR) -p $@
|
|
|
|
$(HEADER_BUILD):
|
|
$(MKDIR) -p $@
|
|
|
|
ifneq ($(PROG),)
|
|
# Build a standalone executable (unix does this)
|
|
|
|
all: $(PROG)
|
|
|
|
$(PROG): $(OBJ)
|
|
$(ECHO) "LINK $@"
|
|
# 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)
|
|
ifndef DEBUG
|
|
$(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG)
|
|
endif
|
|
$(Q)$(SIZE) $(PROG)
|
|
|
|
lib: $(OBJ)
|
|
$(AR) rcs libmicropython.a $^
|
|
|
|
clean: clean-prog
|
|
clean-prog:
|
|
$(RM) -f $(PROG)
|
|
$(RM) -f $(PROG).map
|
|
|
|
.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
|
|
|
|
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
|
|
|
|
-include $(OBJ:.o=.P)
|