Add compilation time cost for each source file in make file


Encountered an issue of extreme long time compiling days ago, so we tried to add a time cost output in the Makefile to locate what on earth happened during the compilation.

There are two Makefiles need to be modified, one is Linux based Makefile, another is Android based Makefile

Linux Makefile:

##------------------------------------------------------------------------
## Rules
## Suffix rules
$(SRC_DIR)/%.o: $(SRC_DIR)/%.s
    $(CC) -c -o $@ $(CFLAGS) $<
$(SRC_DIR)/%.o: $(SRC_DIR)/%.cpp
    @now=`date`; echo "==========compile at $${now}"
    $(CC) -c -o $@ $(CFLAGS) $<

or

@echo "Compilation begin at `date`"
@echo Compilation in progress, please wait ...
@sleep 1
@now=`date`; echo "Compilation end at $${now}"

Test Makefile: http://rg4.net/p/tools/add-time-output-to-makefile/common.mk

Android Makefile:
You need to modify NDK common make file, definitions.mk, to archive this, it’s locating at /path-to-ndk/android-ndk-r7c/build/core/definitions.mk

_CC   := $$(NDK_CCACHE) $$($$(my)CXX)

# Jacky, add timestamp to the compile output
# 1) for linux
# NOW := `date`
# 2) for windows
NOW        := %TIME:~0,10%

_TEXT := "Compile++ $$(call get-src-file-text,$1), start at: $$(NOW)"

$$(eval $$(call ev-build-source-file))
endef

Test Makefile: http://rg4.net/p/tools/add-time-output-to-makefile/definitions.mk

Leave a comment

Your email address will not be published. Required fields are marked *