add ccache and enable by default

This commit is contained in:
Tony Theodore 2019-01-20 20:50:15 +11:00
parent 1d4ac62006
commit ea56b37696
5 changed files with 123 additions and 1 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
/pkg
/wip/
/tmp-*
/.ccache
# generated by build-pkg
/*-*.list

View File

@ -69,6 +69,11 @@ STRIP_TOOLCHAIN := $(true)
STRIP_LIB := $(false)
STRIP_EXE := $(true)
# disable by setting MXE_USE_CCACHE
MXE_USE_CCACHE := mxe
MXE_CCACHE_DIR := $(PWD)/.ccache
MXE_CCACHE_BASE_DIR := $(PWD)
# define some whitespace variables
define newline
@ -431,7 +436,13 @@ $(PREFIX)/installed/print-git-oneline-$(GIT_HEAD): | $(PREFIX)/installed/.gitkee
# cross libraries depend on virtual toolchain package, variable used
# in `cleanup-deps-style` rule below
CROSS_COMPILER := cc
MXE_REQS_PKGS =
# set reqs and bootstrap variables to recursive so pkgs can add themselves
# CROSS_COMPILER depends (order-only) on MXE_REQS_PKGS
# all depend (order-only) on BOOTSTRAP_PKGS
# BOOTSTRAP_PKGS may be prefixed with $(BUILD)~
MXE_REQS_PKGS =
BOOTSTRAP_PKGS =
# warning about switching from `gcc` to `cc`
$(if $(and $(filter gcc,$(LOCAL_PKG_LIST)$(MAKECMDGOALS)),\
@ -521,6 +532,7 @@ $(foreach PKG,$(PKGS), \
$(eval $(PKG)_OO_DEPS += $(BUILD)~autotools)) \
$(if $(filter $(PKG),$(CMAKE_PKGS)),$(eval $(PKG)_OO_DEPS += cmake-conf)) \
$(if $(filter $(PKG),$(MXE_CONF_PKGS)),,$(eval $(PKG)_OO_DEPS += mxe-conf)) \
$(if $(filter %$(PKG),$(MXE_CONF_PKGS) $(BOOTSTRAP_PKGS)),,$(eval $(PKG)_OO_DEPS += $(BOOTSTRAP_PKGS))) \
$(eval $(PKG)_TARGETS := $(sort $($(PKG)_TARGETS))) \
$(if $($(PKG)_TARGETS),,$(eval $(PKG)_TARGETS := $(CROSS_TARGETS))) \
$(foreach TARGET,$(filter $($(PKG)_TARGETS),$(CROSS_TARGETS) $(BUILD)), \
@ -918,6 +930,9 @@ BUILD_PKG_TMP_FILES := *-*.list mxe-*.tar.xz mxe-*.deb* wheezy jessie
clean:
rm -rf $(call TMP_DIR,*) $(PREFIX) \
$(addprefix $(TOP_DIR)/, $(BUILD_PKG_TMP_FILES))
@echo
@echo 'review ccache size with:'
@echo '$(MXE_CCACHE_DIR)/bin/ccache -s'
.PHONY: clean-pkg
clean-pkg:

View File

@ -18,6 +18,7 @@ various target platforms, which:
* is able to update the version numbers of all packages automatically
* directly uses source packages, thus ensuring the whole build mechanism is transparent
* allows inter-package and intra-package parallel builds whenever possible
* bundles [ccache](https://ccache.samba.org) to speed up repeated builds
* integrates well with autotools, cmake, qmake, and hand-written makefiles.
* has been in continuous development since 2007 and is used by several projects

View File

@ -83,6 +83,10 @@
<a href="#usage">parallel builds</a>
whenever possible
</li>
<li>
bundles <a href="https://ccache.samba.org">ccache</a> to speed
up repeated builds
</li>
<li>
integrates well with <a href="#tutorial-5a">autotools</a>,
<a href="#tutorial-5b">cmake</a>, <a href="#tutorial-5c">qmake</a>,
@ -1216,6 +1220,13 @@ local-pkg-list: $(LOCAL_PKG_LIST)</pre>
(short option "-j 4 -k")
</dd>
<dt>make foo bar MXE_USE_CCACHE=</dt>
<dd>
disables use of <a href="https://ccache.samba.org">ccache</a>
to eliminate potential error sources when debugging
</dd>
<dt>make EXCLUDE_PKGS='foo bar'</dt>
<dd>

94
src/ccache.mk Normal file
View File

@ -0,0 +1,94 @@
# This file is part of MXE. See LICENSE.md for licensing information.
PKG := ccache
$(PKG)_WEBSITE := https://ccache.samba.org
$(PKG)_DESCR := ccache a fast compiler cache
$(PKG)_IGNORE :=
$(PKG)_VERSION := 3.6
$(PKG)_CHECKSUM := a6b129576328fcefad00cb72035bc87bc98b6a76aec0f4b59bed76d67a399b1f
$(PKG)_SUBDIR := ccache-$($(PKG)_VERSION)
$(PKG)_FILE := ccache-$($(PKG)_VERSION).tar.xz
$(PKG)_URL := https://www.samba.org/ftp/ccache/ccache-$($(PKG)_VERSION).tar.xz
$(PKG)_DEPS := $(BUILD)~$(PKG)
$(PKG)_TARGETS := $(BUILD) $(MXE_TARGETS)
$(PKG)_DEPS_$(BUILD) :=
define $(PKG)_UPDATE
$(call GET_LATEST_VERSION, https://www.samba.org/ftp/ccache)
endef
BOOTSTRAP_PKGS += ccache
$(PKG)_SYS_CONF := $(MXE_CCACHE_DIR)/etc/$(PKG).conf
$(PKG)_USR_CONF := $(MXE_CCACHE_DIR)/$(PKG).conf
ifeq (mxe,$(MXE_USE_CCACHE))
define $(PKG)_BUILD_$(BUILD)
# remove any previous symlinks
rm -fv '$(PREFIX)/$(BUILD)/bin/$(BUILD_CC)' '$(PREFIX)/$(BUILD)/bin/$(BUILD_CXX)'
# minimal reqs build with bundled zlib
cd '$(BUILD_DIR)' && $(SOURCE_DIR)/configure \
$(MXE_CONFIGURE_OPTS) \
--with-bundled-zlib \
--disable-man \
--prefix='$(MXE_CCACHE_DIR)' \
--sysconfdir='$(dir $($(PKG)_SYS_CONF))'
$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' $(MXE_DISABLE_DOCS)
$(MAKE) -C '$(BUILD_DIR)' -j 1 install $(MXE_DISABLE_DOCS)
# setup symlinks
ln -sf '$(MXE_CCACHE_DIR)/bin/ccache' '$(PREFIX)/$(BUILD)/bin/$(BUILD_CC)'
ln -sf '$(MXE_CCACHE_DIR)/bin/ccache' '$(PREFIX)/$(BUILD)/bin/$(BUILD_CXX)'
# https://ccache.samba.org/manual/latest.html#_configuration_settings
# always set/replace mxe `system` config
mkdir -p '$(dir $($(PKG)_SYS_CONF))'
(echo '# ccache system config'; \
echo '# this file is controlled by mxe, user config is in:'; \
echo '# $($(PKG)_USR_CONF)'; \
echo; \
echo 'base_dir = $(MXE_CCACHE_BASE_DIR)'; \
echo 'cache_dir = $(MXE_CCACHE_DIR)'; \
echo 'compiler_check = %compiler% -v'; \
) > '$($(PKG)_SYS_CONF)'
# leave user config alone if set
[ -f '$($(PKG)_USR_CONF)' ] || \
(mkdir -p '$(dir $($(PKG)_USR_CONF))' && \
(echo '# ccache user config'; \
echo '# https://ccache.samba.org/manual/latest.html#_configuration_settings'; \
echo '# system config: $($(PKG)_SYS_CONF)'; \
echo; \
echo 'max_size = 20.0G'; \
) > '$($(PKG)_USR_CONF)')
endef
define $(PKG)_BUILD
# setup symlinks
ln -sf '$(MXE_CCACHE_DIR)/bin/ccache' '$(PREFIX)/$(BUILD)/bin/$(TARGET)-gcc'
ln -sf '$(MXE_CCACHE_DIR)/bin/ccache' '$(PREFIX)/$(BUILD)/bin/$(TARGET)-g++'
# setup cmake toolchain to allow runtime override
# CMAKE_CXX_COMPILER_LAUNCHER shows original cc and isn't clear in logs etc.
mkdir -p '$(CMAKE_TOOLCHAIN_DIR)'
(echo 'option(MXE_USE_CCACHE "Enable ccache by default" ON)'; \
echo 'if(MXE_USE_CCACHE)'; \
echo ' set(CMAKE_C_COMPILER $(PREFIX)/$(BUILD)/bin/$(TARGET)-gcc)'; \
echo ' set(CMAKE_CXX_COMPILER $(PREFIX)/$(BUILD)/bin/$(TARGET)-g++)'; \
echo 'endif()'; \
) > '$(CMAKE_TOOLCHAIN_DIR)/$(PKG).cmake'
endef
else
define $(PKG)_BUILD_$(BUILD)
# remove symlinks
rm -fv '$(PREFIX)/$(BUILD)/bin/$(BUILD_CC)' '$(PREFIX)/$(BUILD)/bin/$(BUILD_CXX)'
endef
define $(PKG)_BUILD
# remove symlinks and cmake toolchain
rm -fv '$(PREFIX)/$(BUILD)/bin/$(TARGET)-'*
rm -fv '$(CMAKE_TOOLCHAIN_DIR)/$(PKG).cmake'
endef
endif