Browse Source

add ccache and enable by default

tags/build-2019-06-02
Tony Theodore 5 months ago
parent
commit
ea56b37696
5 changed files with 123 additions and 1 deletions
  1. 1
    0
      .gitignore
  2. 16
    1
      Makefile
  3. 1
    0
      README.md
  4. 11
    0
      docs/index.html
  5. 94
    0
      src/ccache.mk

+ 1
- 0
.gitignore View File

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

+ 16
- 1
Makefile View File

@@ -69,6 +69,11 @@ STRIP_TOOLCHAIN := $(true)
69 69
 STRIP_LIB       := $(false)
70 70
 STRIP_EXE       := $(true)
71 71
 
72
+# disable by setting MXE_USE_CCACHE
73
+MXE_USE_CCACHE      := mxe
74
+MXE_CCACHE_DIR      := $(PWD)/.ccache
75
+MXE_CCACHE_BASE_DIR := $(PWD)
76
+
72 77
 # define some whitespace variables
73 78
 define newline
74 79
 
@@ -431,7 +436,13 @@ $(PREFIX)/installed/print-git-oneline-$(GIT_HEAD): | $(PREFIX)/installed/.gitkee
431 436
 # cross libraries depend on virtual toolchain package, variable used
432 437
 # in `cleanup-deps-style` rule below
433 438
 CROSS_COMPILER := cc
434
-MXE_REQS_PKGS   =
439
+
440
+# set reqs and bootstrap variables to recursive so pkgs can add themselves
441
+# CROSS_COMPILER depends (order-only) on MXE_REQS_PKGS
442
+# all depend (order-only) on BOOTSTRAP_PKGS
443
+# BOOTSTRAP_PKGS may be prefixed with $(BUILD)~
444
+MXE_REQS_PKGS  =
445
+BOOTSTRAP_PKGS =
435 446
 
436 447
 # warning about switching from `gcc` to `cc`
437 448
 $(if $(and $(filter gcc,$(LOCAL_PKG_LIST)$(MAKECMDGOALS)),\
@@ -521,6 +532,7 @@ $(foreach PKG,$(PKGS), \
521 532
         $(eval $(PKG)_OO_DEPS += $(BUILD)~autotools)) \
522 533
     $(if $(filter $(PKG),$(CMAKE_PKGS)),$(eval $(PKG)_OO_DEPS += cmake-conf)) \
523 534
     $(if $(filter $(PKG),$(MXE_CONF_PKGS)),,$(eval $(PKG)_OO_DEPS += mxe-conf)) \
535
+    $(if $(filter %$(PKG),$(MXE_CONF_PKGS) $(BOOTSTRAP_PKGS)),,$(eval $(PKG)_OO_DEPS += $(BOOTSTRAP_PKGS))) \
524 536
     $(eval $(PKG)_TARGETS := $(sort $($(PKG)_TARGETS))) \
525 537
     $(if $($(PKG)_TARGETS),,$(eval $(PKG)_TARGETS := $(CROSS_TARGETS))) \
526 538
     $(foreach TARGET,$(filter $($(PKG)_TARGETS),$(CROSS_TARGETS) $(BUILD)), \
@@ -918,6 +930,9 @@ BUILD_PKG_TMP_FILES := *-*.list mxe-*.tar.xz mxe-*.deb* wheezy jessie
918 930
 clean:
919 931
 	rm -rf $(call TMP_DIR,*) $(PREFIX) \
920 932
 	       $(addprefix $(TOP_DIR)/, $(BUILD_PKG_TMP_FILES))
933
+	@echo
934
+	@echo 'review ccache size with:'
935
+	@echo '$(MXE_CCACHE_DIR)/bin/ccache -s'
921 936
 
922 937
 .PHONY: clean-pkg
923 938
 clean-pkg:

+ 1
- 0
README.md View File

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

+ 11
- 0
docs/index.html View File

@@ -84,6 +84,10 @@
84 84
         whenever possible
85 85
     </li>
86 86
     <li>
87
+        bundles <a href="https://ccache.samba.org">ccache</a> to speed
88
+        up repeated builds
89
+    </li>
90
+    <li>
87 91
         integrates well with <a href="#tutorial-5a">autotools</a>,
88 92
         <a href="#tutorial-5b">cmake</a>, <a href="#tutorial-5c">qmake</a>,
89 93
         and <a href="#tutorial-5d">hand-written makefiles</a>
@@ -1216,6 +1220,13 @@ local-pkg-list: $(LOCAL_PKG_LIST)</pre>
1216 1220
         (short option "-j 4 -k")
1217 1221
         </dd>
1218 1222
 
1223
+    <dt>make foo bar MXE_USE_CCACHE=</dt>
1224
+
1225
+        <dd>
1226
+        disables use of <a href="https://ccache.samba.org">ccache</a>
1227
+        to eliminate potential error sources when debugging
1228
+        </dd>
1229
+
1219 1230
     <dt>make EXCLUDE_PKGS='foo bar'</dt>
1220 1231
 
1221 1232
         <dd>

+ 94
- 0
src/ccache.mk View File

@@ -0,0 +1,94 @@
1
+# This file is part of MXE. See LICENSE.md for licensing information.
2
+
3
+PKG             := ccache
4
+$(PKG)_WEBSITE  := https://ccache.samba.org
5
+$(PKG)_DESCR    := ccache – a fast compiler cache
6
+$(PKG)_IGNORE   :=
7
+$(PKG)_VERSION  := 3.6
8
+$(PKG)_CHECKSUM := a6b129576328fcefad00cb72035bc87bc98b6a76aec0f4b59bed76d67a399b1f
9
+$(PKG)_SUBDIR   := ccache-$($(PKG)_VERSION)
10
+$(PKG)_FILE     := ccache-$($(PKG)_VERSION).tar.xz
11
+$(PKG)_URL      := https://www.samba.org/ftp/ccache/ccache-$($(PKG)_VERSION).tar.xz
12
+$(PKG)_DEPS     := $(BUILD)~$(PKG)
13
+$(PKG)_TARGETS  := $(BUILD) $(MXE_TARGETS)
14
+
15
+$(PKG)_DEPS_$(BUILD) :=
16
+
17
+define $(PKG)_UPDATE
18
+    $(call GET_LATEST_VERSION, https://www.samba.org/ftp/ccache)
19
+endef
20
+
21
+BOOTSTRAP_PKGS += ccache
22
+
23
+$(PKG)_SYS_CONF := $(MXE_CCACHE_DIR)/etc/$(PKG).conf
24
+$(PKG)_USR_CONF := $(MXE_CCACHE_DIR)/$(PKG).conf
25
+
26
+ifeq (mxe,$(MXE_USE_CCACHE))
27
+define $(PKG)_BUILD_$(BUILD)
28
+    # remove any previous symlinks
29
+    rm -fv '$(PREFIX)/$(BUILD)/bin/$(BUILD_CC)' '$(PREFIX)/$(BUILD)/bin/$(BUILD_CXX)'
30
+
31
+    # minimal reqs build with bundled zlib
32
+    cd '$(BUILD_DIR)' && $(SOURCE_DIR)/configure \
33
+        $(MXE_CONFIGURE_OPTS) \
34
+        --with-bundled-zlib \
35
+        --disable-man \
36
+        --prefix='$(MXE_CCACHE_DIR)' \
37
+        --sysconfdir='$(dir $($(PKG)_SYS_CONF))'
38
+    $(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' $(MXE_DISABLE_DOCS)
39
+    $(MAKE) -C '$(BUILD_DIR)' -j 1 install $(MXE_DISABLE_DOCS)
40
+
41
+    # setup symlinks
42
+    ln -sf '$(MXE_CCACHE_DIR)/bin/ccache' '$(PREFIX)/$(BUILD)/bin/$(BUILD_CC)'
43
+    ln -sf '$(MXE_CCACHE_DIR)/bin/ccache' '$(PREFIX)/$(BUILD)/bin/$(BUILD_CXX)'
44
+
45
+    # https://ccache.samba.org/manual/latest.html#_configuration_settings
46
+    # always set/replace mxe `system` config
47
+    mkdir -p '$(dir $($(PKG)_SYS_CONF))'
48
+    (echo '# ccache system config'; \
49
+     echo '# this file is controlled by mxe, user config is in:'; \
50
+     echo '# $($(PKG)_USR_CONF)'; \
51
+     echo; \
52
+     echo 'base_dir = $(MXE_CCACHE_BASE_DIR)'; \
53
+     echo 'cache_dir = $(MXE_CCACHE_DIR)'; \
54
+     echo 'compiler_check = %compiler% -v'; \
55
+     ) > '$($(PKG)_SYS_CONF)'
56
+
57
+    # leave user config alone if set
58
+    [ -f '$($(PKG)_USR_CONF)' ] || \
59
+    (mkdir -p '$(dir $($(PKG)_USR_CONF))' && \
60
+    (echo '# ccache user config'; \
61
+     echo '# https://ccache.samba.org/manual/latest.html#_configuration_settings'; \
62
+     echo '# system config: $($(PKG)_SYS_CONF)'; \
63
+     echo; \
64
+     echo 'max_size = 20.0G'; \
65
+     ) > '$($(PKG)_USR_CONF)')
66
+endef
67
+
68
+define $(PKG)_BUILD
69
+    # setup symlinks
70
+    ln -sf '$(MXE_CCACHE_DIR)/bin/ccache' '$(PREFIX)/$(BUILD)/bin/$(TARGET)-gcc'
71
+    ln -sf '$(MXE_CCACHE_DIR)/bin/ccache' '$(PREFIX)/$(BUILD)/bin/$(TARGET)-g++'
72
+
73
+    # setup cmake toolchain to allow runtime override
74
+    # CMAKE_CXX_COMPILER_LAUNCHER shows original cc and isn't clear in logs etc.
75
+    mkdir -p '$(CMAKE_TOOLCHAIN_DIR)'
76
+    (echo 'option(MXE_USE_CCACHE "Enable ccache by default" ON)'; \
77
+     echo 'if(MXE_USE_CCACHE)'; \
78
+     echo '  set(CMAKE_C_COMPILER $(PREFIX)/$(BUILD)/bin/$(TARGET)-gcc)'; \
79
+     echo '  set(CMAKE_CXX_COMPILER $(PREFIX)/$(BUILD)/bin/$(TARGET)-g++)'; \
80
+     echo 'endif()'; \
81
+     ) > '$(CMAKE_TOOLCHAIN_DIR)/$(PKG).cmake'
82
+endef
83
+else
84
+define $(PKG)_BUILD_$(BUILD)
85
+    # remove symlinks
86
+    rm -fv '$(PREFIX)/$(BUILD)/bin/$(BUILD_CC)' '$(PREFIX)/$(BUILD)/bin/$(BUILD_CXX)'
87
+endef
88
+
89
+define $(PKG)_BUILD
90
+    # remove symlinks and cmake toolchain
91
+    rm -fv '$(PREFIX)/$(BUILD)/bin/$(TARGET)-'*
92
+    rm -fv '$(CMAKE_TOOLCHAIN_DIR)/$(PKG).cmake'
93
+endef
94
+endif

Loading…
Cancel
Save