diff --git a/.gitignore b/.gitignore index 8031a238..aa869942 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /pkg /wip/ /tmp-* +/.ccache # generated by build-pkg /*-*.list diff --git a/Makefile b/Makefile index 4be61496..53c6f0c9 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/README.md b/README.md index 2c834007..521154e3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/index.html b/docs/index.html index ebc0c1a1..7917dc2c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -83,6 +83,10 @@ parallel builds whenever possible +
  • + bundles ccache to speed + up repeated builds +
  • integrates well with autotools, cmake, qmake, @@ -1216,6 +1220,13 @@ local-pkg-list: $(LOCAL_PKG_LIST) (short option "-j 4 -k") +
    make foo bar MXE_USE_CCACHE=
    + +
    + disables use of ccache + to eliminate potential error sources when debugging +
    +
    make EXCLUDE_PKGS='foo bar'
    diff --git a/src/ccache.mk b/src/ccache.mk new file mode 100644 index 00000000..b37fe24f --- /dev/null +++ b/src/ccache.mk @@ -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