You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. # This file is part of MXE. See LICENSE.md for licensing information.
  2. MAKEFILE := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
  3. TOP_DIR := $(patsubst %/,%,$(dir $(MAKEFILE)))
  4. EXT_DIR := $(TOP_DIR)/ext
  5. # GNU Make Standard Library (https://gmsl.sourceforge.io/)
  6. # See docs/gmsl.html for further information
  7. include $(EXT_DIR)/gmsl
  8. MXE_TRIPLETS := i686-w64-mingw32 x86_64-w64-mingw32
  9. MXE_LIB_TYPES := static shared
  10. MXE_TARGET_LIST := $(strip $(foreach TRIPLET,$(MXE_TRIPLETS),\
  11. $(addprefix $(TRIPLET).,$(MXE_LIB_TYPES))))
  12. MXE_TARGETS := i686-w64-mingw32.static
  13. .DEFAULT_GOAL := all-filtered
  14. DEFAULT_MAX_JOBS := 6
  15. PRINTF_COL_1_WIDTH := 13
  16. SOURCEFORGE_MIRROR := downloads.sourceforge.net
  17. MXE_MIRROR := https://mirror.mxe.cc/pkg
  18. PKG_MIRROR := https://mxe-pkg.s3.amazonaws.com
  19. PKG_CDN := http://d1yihgixbnrglp.cloudfront.net
  20. # reorder as required, ensuring final one is a http fallback
  21. MIRROR_SITES := MXE_MIRROR PKG_MIRROR PKG_CDN
  22. PWD := $(shell pwd)
  23. SHELL := bash
  24. MXE_TMP := $(PWD)
  25. BUILD_CC := $(shell (gcc --help >/dev/null 2>&1 && echo gcc) || (clang --help >/dev/null 2>&1 && echo clang))
  26. BUILD_CXX := $(shell (g++ --help >/dev/null 2>&1 && echo g++) || (clang++ --help >/dev/null 2>&1 && echo clang++))
  27. DATE := $(shell gdate --help >/dev/null 2>&1 && echo g)date
  28. INSTALL := $(shell ginstall --help >/dev/null 2>&1 && echo g)install
  29. LIBTOOL := $(shell glibtool --help >/dev/null 2>&1 && echo g)libtool
  30. LIBTOOLIZE := $(shell glibtoolize --help >/dev/null 2>&1 && echo g)libtoolize
  31. OPENSSL := openssl
  32. PATCH := $(shell gpatch --help >/dev/null 2>&1 && echo g)patch
  33. PYTHON2 := $(or $(shell ([ `python -c "import sys; print('{0[0]}'.format(sys.version_info))"` == 2 ] && echo python) 2>/dev/null || \
  34. which python2 2>/dev/null || \
  35. which python2.7 2>/dev/null), \
  36. $(warning Warning: python v2 not found (or default python changed to v3))\
  37. $(shell touch check-requirements-failed))
  38. SED := $(shell gsed --help >/dev/null 2>&1 && echo g)sed
  39. SORT := $(shell gsort --help >/dev/null 2>&1 && echo g)sort
  40. DEFAULT_UA := $(shell wget --version | $(SED) -n 's,GNU \(Wget\) \([0-9.]*\).*,\1/\2,p')
  41. WGET_TOOL = wget
  42. WGET = $(WGET_TOOL) --user-agent='$(or $($(1)_UA),$(DEFAULT_UA))'
  43. REQUIREMENTS := autoconf automake autopoint bash bison bzip2 flex \
  44. $(BUILD_CC) $(BUILD_CXX) gperf intltoolize $(LIBTOOL) \
  45. $(LIBTOOLIZE) lzip $(MAKE) $(OPENSSL) $(PATCH) $(PERL) python \
  46. ruby $(SED) $(SORT) unzip wget xz 7za gdk-pixbuf-csource
  47. PREFIX := $(PWD)/usr
  48. LOG_DIR := $(PWD)/log
  49. GITS_DIR := $(PWD)/gits
  50. GIT_HEAD := $(shell git rev-parse HEAD)
  51. TIMESTAMP := $(shell date +%Y%m%d_%H%M%S)
  52. PKG_DIR := $(PWD)/pkg
  53. TMP_DIR = $(MXE_TMP)/tmp-$(1)
  54. BUILD := $(shell '$(EXT_DIR)/config.guess')
  55. PATH := $(PREFIX)/$(BUILD)/bin:$(PREFIX)/bin:$(shell echo $$PATH | $(SED) -e 's,:\.$$,,' -e 's,\.:,,g')
  56. # set to empty or $(false) to disable stripping
  57. STRIP_TOOLCHAIN := $(true)
  58. STRIP_LIB := $(false)
  59. STRIP_EXE := $(true)
  60. # disable by setting MXE_USE_CCACHE
  61. MXE_USE_CCACHE := mxe
  62. MXE_CCACHE_DIR := $(PWD)/.ccache
  63. MXE_CCACHE_BASE_DIR := $(PWD)
  64. # define some whitespace variables
  65. define newline
  66. endef
  67. \n := $(newline)
  68. comma := ,
  69. null :=
  70. space := $(null) $(null)
  71. repeat = $(subst x,$(1),$(subst $(space),,$(call int_encode,$(2))))
  72. PLUGIN_HEADER = $(info $(shell printf '%-$(PRINTF_COL_1_WIDTH)s %s\n' [plugin] $(dir $(lastword $(MAKEFILE_LIST)))))
  73. MXE_DISABLE_DOC_OPTS = \
  74. ac_cv_prog_HAVE_DOXYGEN="false" \
  75. --enable-doc=no \
  76. --enable-gtk-doc=no \
  77. --enable-gtk-doc-html=no \
  78. --enable-gtk-doc-pdf=no \
  79. --{docdir,infodir,mandir,with-html-dir}='$(BUILD_DIR).sink' \
  80. --disable-doxygen
  81. MXE_CONFIGURE_OPTS = \
  82. --host='$(TARGET)' \
  83. --build='$(BUILD)' \
  84. --prefix='$(PREFIX)/$(TARGET)' \
  85. $(if $(BUILD_STATIC), \
  86. --enable-static --disable-shared , \
  87. --disable-static --enable-shared ) \
  88. $(MXE_DISABLE_DOC_OPTS)
  89. PKG_CONFIGURE_OPTS = \
  90. $(_$(PKG)_CONFIGURE_OPTS) \
  91. $($(PKG)_CONFIGURE_OPTS)
  92. # GCC threads and exceptions
  93. MXE_GCC_THREADS = \
  94. $(if $(findstring win32,$(or $(TARGET),$(1))),win32,posix)
  95. # allowed exception handling for targets
  96. # default (first item) and alternate, revisit if gcc/mingw-w64 change defaults
  97. i686-w64-mingw32_EH := sjlj dw2
  98. x86_64-w64-mingw32_EH := seh sjlj
  99. # functions to determine exception handling from user-specified target
  100. # $(or $(TARGET),$(1)) allows use as both function and inline snippet
  101. TARGET_EH_LIST = $($(firstword $(call split,.,$(or $(TARGET),$(1))))_EH)
  102. DEFAULT_EH = $(firstword $(TARGET_EH_LIST))
  103. GCC_EXCEPTIONS = \
  104. $(lastword $(DEFAULT_EH) \
  105. $(filter $(TARGET_EH_LIST),$(call split,.,$(or $(TARGET),$(1)))))
  106. MXE_GCC_EXCEPTION_OPTS = \
  107. $(if $(call seq,sjlj,$(GCC_EXCEPTIONS)),--enable-sjlj-exceptions) \
  108. $(if $(call seq,dw2,$(GCC_EXCEPTIONS)),--disable-sjlj-exceptions)
  109. # Append these to the "make" and "make install" steps of autotools packages
  110. # in order to neither build nor install unwanted binaries, manpages,
  111. # infopages and API documentation (reduces build time and disk space usage).
  112. # NOTE: We don't include bin_SCRIPTS (and variations), since many packages
  113. # install files such as pcre-config (which we do want to be installed).
  114. MXE_DISABLE_PROGRAMS = \
  115. dist_bin_SCRIPTS= \
  116. bin_PROGRAMS= \
  117. sbin_PROGRAMS= \
  118. noinst_PROGRAMS= \
  119. check_PROGRAMS=
  120. MXE_DISABLE_DOCS = \
  121. man_MANS= \
  122. man1_MANS= \
  123. man2_MANS= \
  124. man3_MANS= \
  125. man4_MANS= \
  126. man5_MANS= \
  127. man6_MANS= \
  128. man7_MANS= \
  129. man8_MANS= \
  130. man9_MANS= \
  131. dist_man_MANS= \
  132. dist_man1_MANS= \
  133. dist_man2_MANS= \
  134. dist_man3_MANS= \
  135. dist_man4_MANS= \
  136. dist_man5_MANS= \
  137. dist_man6_MANS= \
  138. dist_man7_MANS= \
  139. dist_man8_MANS= \
  140. dist_man9_MANS= \
  141. nodist_man_MANS= \
  142. nodist_man1_MANS= \
  143. nodist_man2_MANS= \
  144. nodist_man3_MANS= \
  145. nodist_man4_MANS= \
  146. nodist_man5_MANS= \
  147. nodist_man6_MANS= \
  148. nodist_man7_MANS= \
  149. nodist_man8_MANS= \
  150. nodist_man9_MANS= \
  151. notrans_dist_man_MANS= \
  152. MANLINKS= \
  153. info_TEXINFOS= \
  154. doc_DATA= \
  155. dist_doc_DATA= \
  156. html_DATA= \
  157. dist_html_DATA=
  158. MXE_DISABLE_CRUFT = $(MXE_DISABLE_PROGRAMS) $(MXE_DISABLE_DOCS)
  159. MAKE_SHARED_FROM_STATIC = \
  160. '$(TOP_DIR)/tools/make-shared-from-static' \
  161. $(if $(findstring mingw,$(TARGET)),--windowsdll) \
  162. --ar '$(TARGET)-ar' \
  163. --ld '$(TARGET)-gcc' \
  164. --install '$(INSTALL)' \
  165. --libdir '$(PREFIX)/$(TARGET)/lib' \
  166. --bindir '$(PREFIX)/$(TARGET)/bin'
  167. define AUTOTOOLS_CONFIGURE
  168. cd '$(BUILD_DIR)' && $(SOURCE_DIR)/configure \
  169. $(MXE_CONFIGURE_OPTS)
  170. endef
  171. define AUTOTOOLS_MAKE
  172. $(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' $(MXE_DISABLE_DOCS)
  173. $(MAKE) -C '$(BUILD_DIR)' -j 1 install $(MXE_DISABLE_DOCS)
  174. endef
  175. define AUTOTOOLS_BUILD
  176. $(AUTOTOOLS_CONFIGURE)
  177. $(AUTOTOOLS_MAKE)
  178. endef
  179. # include github related functions
  180. include $(PWD)/mxe.github.mk
  181. # shared lib preload to disable networking, enable faketime etc
  182. PRELOAD_VARS := LD_PRELOAD DYLD_FORCE_FLAT_NAMESPACE DYLD_INSERT_LIBRARIES
  183. # use a minimal whitelist of safe environment variables
  184. # basic working shell environment and mxe variables
  185. # see http://www.linuxfromscratch.org/lfs/view/stable/chapter04/settingenvironment.html
  186. ENV_WHITELIST := EDITOR HOME LANG LC_% PATH %PROXY %proxy PS1 TERM
  187. ENV_WHITELIST += MAKE% MXE% $(PRELOAD_VARS) WINEPREFIX
  188. # OS/Distro related issues - "unsafe" but practical
  189. # 1. https://github.com/mxe/mxe/issues/697
  190. ENV_WHITELIST += ACLOCAL_PATH LD_LIBRARY_PATH
  191. unexport $(filter-out $(ENV_WHITELIST),$(shell env | cut -d '=' -f1))
  192. SHORT_PKG_VERSION = \
  193. $(word 1,$(subst ., ,$($(1)_VERSION))).$(word 2,$(subst ., ,$($(1)_VERSION)))
  194. UNPACK_ARCHIVE = \
  195. $(if $(filter %.tgz, $(1)),tar xzf '$(1)', \
  196. $(if $(filter %.tar.gz, $(1)),tar xzf '$(1)', \
  197. $(if $(filter %.tar.Z, $(1)),tar xzf '$(1)', \
  198. $(if $(filter %.tbz2, $(1)),tar xjf '$(1)', \
  199. $(if $(filter %.tar.bz2, $(1)),tar xjf '$(1)', \
  200. $(if $(filter %.tar.lz, $(1)),lzip -dc '$(1)'| tar xf -, \
  201. $(if $(filter %.tar.lzma,$(1)),xz -dc -F lzma '$(1)' | tar xf -, \
  202. $(if $(filter %.txz, $(1)),xz -dc '$(1)' | tar xf -, \
  203. $(if $(filter %.tar.xz, $(1)),xz -dc '$(1)' | tar xf -, \
  204. $(if $(filter %.7z, $(1)),7za x '$(1)', \
  205. $(if $(filter %.zip, $(1)),unzip -q '$(1)', \
  206. $(if $(filter %.deb, $(1)),ar x '$(1)' && tar xf data.tar*, \
  207. $(error Unknown archive format: $(1))))))))))))))
  208. UNPACK_PKG_ARCHIVE = \
  209. $(call UNPACK_ARCHIVE,$(PKG_DIR)/$($(1)_FILE))
  210. # some shortcuts for awareness of MXE_PLUGIN_DIRS
  211. # all files for extension plugins will be considered for outdated checks
  212. PKG_MAKEFILES = $(realpath $(sort $(wildcard $(addsuffix /$(1).mk, $(MXE_PLUGIN_DIRS)))))
  213. PKG_TESTFILES = $(realpath $(sort $(wildcard $(addsuffix /$(1)-test*, $(MXE_PLUGIN_DIRS)))))
  214. # allow packages to specify a list of zero or more patches
  215. PKG_PATCHES = $(if $(findstring undefined,$(origin $(1)_PATCHES)), \
  216. $(realpath $(sort $(wildcard $(addsuffix /$(1)-[0-9]*.patch, $(MXE_PLUGIN_DIRS))))) \
  217. $(else), \
  218. $($(1)_PATCHES))
  219. define PREPARE_PKG_SOURCE
  220. $(if $($(1)_SOURCE_TREE),\
  221. ln -si '$(realpath $($(1)_SOURCE_TREE))' '$(2)/$($(1)_SUBDIR)'
  222. $(else),\
  223. cd '$(2)' && $(call UNPACK_PKG_ARCHIVE,$(1))
  224. cd '$(2)/$($(1)_SUBDIR)'
  225. $(foreach PKG_PATCH,$($(1)_PATCHES),
  226. (cd '$(2)/$($(1)_SUBDIR)' && $(PATCH) -p1 -u) < $(PKG_PATCH))
  227. )
  228. endef
  229. PKG_CHECKSUM = \
  230. $(OPENSSL) dgst -sha256 '$(or $(2),$(PKG_DIR)/$($(1)_FILE))' 2>/dev/null | $(SED) -n 's,^.*\([0-9a-f]\{64\}\)$$,\1,p'
  231. CHECK_PKG_ARCHIVE = \
  232. $(if $($(1)_SOURCE_TREE),\
  233. $(PRINTF_FMT) '[local]' '$(1)' '$($(1)_SOURCE_TREE)' | $(RTRIM)\
  234. $(else),$(if $(SKIP_CHECHSUM),true, \
  235. [ '$($(1)_CHECKSUM)' == "`$$(call PKG_CHECKSUM,$(1),$(2))`" ]\
  236. ))
  237. ESCAPE_PKG = \
  238. echo '$($(1)_FILE)' | perl -lpe 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($$$$1))/seg'
  239. BACKUP_DOWNLOAD = \
  240. (echo "MXE Warning! Downloading $(1) from backup." >&2 && \
  241. ($(foreach SITE,$(MIRROR_SITES), \
  242. $(WGET) -O '$(TMP_FILE)' $($(SITE))/`$(call ESCAPE_PKG,$(1))`_$($(1)_CHECKSUM) || ) false))
  243. DOWNLOAD_PKG_ARCHIVE = \
  244. $(eval TMP_FILE := $(PKG_DIR)/.tmp-$($(1)_FILE)) \
  245. $(if $($(1)_SOURCE_TREE),\
  246. true\
  247. $(else),\
  248. mkdir -p '$(PKG_DIR)' && ( \
  249. ($(WGET) -T 30 -t 3 -O '$(TMP_FILE)' '$($(1)_URL)' && \
  250. $(call CHECK_PKG_ARCHIVE,$(1),'$(TMP_FILE)')) \
  251. $(if $($(1)_URL_2), \
  252. || (echo "MXE Warning! Downloading $(1) from second URL." >&2 && \
  253. $(WGET) -T 30 -t 3 -O '$(TMP_FILE)' '$($(1)_URL_2)' && \
  254. $(call CHECK_PKG_ARCHIVE,$(1),'$(TMP_FILE)'))) \
  255. $(if $(MXE_NO_BACKUP_DL),, \
  256. || $(BACKUP_DOWNLOAD)) \
  257. ) && cat '$(TMP_FILE)' \
  258. $(if $($(1)_FIX_GZIP), \
  259. | gzip -d | gzip -9n, \
  260. ) \
  261. > '$(PKG_DIR)/$($(1)_FILE)' && \
  262. $(if $(CREATE_SUFFIXED_ARCHIVE),cp '$(PKG_DIR)/$($(1)_FILE)' '$(PKG_DIR)/$($(1)_FILE)_$($(1)_CHECKSUM)' &&) \
  263. rm '$(TMP_FILE)' || \
  264. ( echo; \
  265. echo 'Download failed!'; \
  266. echo; \
  267. rm -f '$(PKG_DIR)/$($(1)_FILE)' '$(TMP_FILE)'; )\
  268. )
  269. # open issue from 2002:
  270. # https://savannah.gnu.org/bugs/?712
  271. ifneq ($(words $(PWD)),1)
  272. $(error GNU Make chokes on paths with spaces)
  273. endif
  274. # dollar signs also cause troubles
  275. ifneq (,$(findstring $$,$(PWD)))
  276. $(error GNU Make chokes on paths with dollar signs)
  277. endif
  278. ifeq ($(IGNORE_SETTINGS),yes)
  279. $(info [ignore settings.mk])
  280. else ifeq ($(wildcard $(PWD)/settings.mk),$(PWD)/settings.mk)
  281. include $(PWD)/settings.mk
  282. else
  283. $(info [create settings.mk])
  284. $(shell { \
  285. echo '# This is a template of configuration file for MXE. See'; \
  286. echo '# docs/index.html for more extensive documentations.'; \
  287. echo; \
  288. echo '# This variable controls the number of compilation processes'; \
  289. echo '# within one package ("intra-package parallelism").'; \
  290. echo '#JOBS := $(JOBS)'; \
  291. echo; \
  292. echo '# This variable controls where intermediate files are created'; \
  293. echo '# this is necessary when compiling inside a virtualbox shared'; \
  294. echo '# directory. Some commands like strip fail in there with Protocol error'; \
  295. echo '# default is the current directory'; \
  296. echo '#MXE_TMP := /tmp'; \
  297. echo; \
  298. echo '# This variable controls the targets that will build.'; \
  299. echo '#MXE_TARGETS := $(MXE_TARGET_LIST)'; \
  300. echo; \
  301. echo '# This variable controls which plugins are in use.'; \
  302. echo '# See plugins/README.md for further information.'; \
  303. echo '#override MXE_PLUGIN_DIRS += plugins/apps plugins/native'; \
  304. echo; \
  305. echo '# This variable controls the download mirror for SourceForge,'; \
  306. echo '# when it is used. Enabling the value below means auto.'; \
  307. echo '#SOURCEFORGE_MIRROR := downloads.sourceforge.net'; \
  308. echo; \
  309. echo '# The three lines below makes `make` build these "local'; \
  310. echo '# packages" instead of all packages.'; \
  311. echo '#LOCAL_PKG_LIST := boost curl file flac lzo pthreads vorbis wxwidgets'; \
  312. echo '#.DEFAULT_GOAL := local-pkg-list'; \
  313. echo '#local-pkg-list: $$(LOCAL_PKG_LIST)'; \
  314. } >'$(PWD)/settings.mk')
  315. endif
  316. ifneq ($(LOCAL_PKG_LIST),)
  317. .DEFAULT_GOAL := local-pkg-list
  318. $(info [pkg-list] $(LOCAL_PKG_LIST))
  319. endif
  320. # Numeric min and max list functions
  321. LIST_NMAX = $(shell echo '$(strip $(1))' | tr ' ' '\n' | sort -n | tail -1)
  322. LIST_NMIN = $(shell echo '$(strip $(1))' | tr ' ' '\n' | sort -n | head -1)
  323. NPROCS := $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
  324. JOBS := $(call LIST_NMIN, $(DEFAULT_MAX_JOBS) $(NPROCS))
  325. # Core packages.
  326. override MXE_PLUGIN_DIRS := $(realpath $(TOP_DIR)/src) $(MXE_PLUGIN_DIRS)
  327. # Build native requirements for certain systems
  328. OS_SHORT_NAME := $(call lc,$(shell lsb_release -sc 2>/dev/null || uname -s))
  329. override MXE_PLUGIN_DIRS += $(realpath $(TOP_DIR)/plugins/native/$(OS_SHORT_NAME))
  330. .PHONY: check-requirements
  331. define CHECK_REQUIREMENT
  332. @if ! ( $(1) --help || $(1) help ) &>/dev/null; then \
  333. echo 'Missing requirement: $(1)'; \
  334. touch check-requirements-failed; \
  335. fi
  336. endef
  337. define CHECK_REQUIREMENT_VERSION
  338. @if ! $(1) --version | head -1 | grep ' \($(2)\)$$' >/dev/null; then \
  339. echo 'Wrong version of requirement: $(1)'; \
  340. touch check-requirements-failed; \
  341. fi
  342. endef
  343. %/.gitkeep:
  344. +@mkdir -p '$(dir $@)'
  345. @touch '$@'
  346. check-requirements: $(PREFIX)/installed/check-requirements
  347. $(PREFIX)/installed/check-requirements: $(MAKEFILE) | $(PREFIX)/installed/.gitkeep
  348. @echo '[check reqs]'
  349. $(foreach REQUIREMENT,$(REQUIREMENTS),$(call CHECK_REQUIREMENT,$(REQUIREMENT)))
  350. $(call CHECK_REQUIREMENT_VERSION,autoconf,2\.6[8-9]\|2\.[7-9][0-9])
  351. $(call CHECK_REQUIREMENT_VERSION,automake,1\.11\.[3-9]\|1\.[1-9][2-9]\(\.[0-9]\+\)\?)
  352. @if [ -e check-requirements-failed ]; then \
  353. echo; \
  354. echo 'Please have a look at "docs/index.html" to ensure'; \
  355. echo 'that your system meets all requirements.'; \
  356. echo; \
  357. rm check-requirements-failed; \
  358. exit 1; \
  359. fi
  360. @touch '$@'
  361. .PHONY: print-git-oneline
  362. print-git-oneline: $(PREFIX)/installed/print-git-oneline-$(GIT_HEAD)
  363. $(PREFIX)/installed/print-git-oneline-$(GIT_HEAD): | $(PREFIX)/installed/.gitkeep
  364. @git log --pretty=tformat:'[git-log] %h %s' -1 | cat
  365. @rm -f '$(PREFIX)/installed/print-git-oneline-'*
  366. @touch '$@'
  367. # Common dependency lists for `make` prerequisites and `build-pkg`
  368. # - `make` considers only explicit normal deps to trigger rebuilds
  369. # - packages can add themselves to implicit MXE_REQS_PKGS in the case
  370. # of a tool like `patch` which may be outdated on some systems
  371. # - downloads and `build-pkg` use both explicit and implicit deps
  372. # - don't depend on `disabled` rules but do depend on virtual pkgs
  373. # cross libraries depend on virtual toolchain package, variable used
  374. # in `cleanup-deps-style` rule below
  375. CROSS_COMPILER := cc
  376. # set reqs and bootstrap variables to recursive so pkgs can add themselves
  377. # CROSS_COMPILER depends (order-only) on MXE_REQS_PKGS
  378. # all depend (order-only) on BOOTSTRAP_PKGS
  379. # BOOTSTRAP_PKGS may be prefixed with $(BUILD)~
  380. MXE_REQS_PKGS =
  381. BOOTSTRAP_PKGS =
  382. # warning about switching from `gcc` to `cc`
  383. $(if $(and $(filter gcc,$(LOCAL_PKG_LIST)$(MAKECMDGOALS)),\
  384. $(call seq,1,$(words $(LOCAL_PKG_LIST)$(MAKECMDGOALS)))),\
  385. $(info == gcc is now a dependency of virtual toolchain package cc) \
  386. $(info $(call repeat,$(space),6)- cc will build gcc, pkgconf, and other core toolchain packages)\
  387. $(info $(call repeat,$(space),6)- please update scripts accordingly (ignore if you are building gcc alone))\
  388. $(info ))
  389. # distinguish between deliberately empty rules and disabled ones
  390. # used in build-matrix
  391. VIRTUAL_PKG_TYPES := source-only meta
  392. # used in deps rules and build-pkg
  393. BUILD_PKG_TYPES := meta
  394. # used to avoid unpacking archives when $(PKG)_FILE can't be unset
  395. SCRIPT_PKG_TYPES := script
  396. # all pkgs have (implied) order-only dependencies on MXE_CONF_PKGS.
  397. MXE_CONF_PKGS := mxe-conf
  398. # autotools/cmake are generally always required, but separate them
  399. # for the case of `make gcc` which should only build real deps.
  400. AUTOTOOLS_PKGS := $(filter-out $(MXE_CONF_PKGS) %autotools autoconf automake libtool, \
  401. $(sort $(basename $(notdir \
  402. $(shell grep -l 'auto[conf\|reconf\|gen\|make]\|aclocal\|LIBTOOL' \
  403. $(addsuffix /*.mk,$(MXE_PLUGIN_DIRS)))))))
  404. CMAKE_PKGS := $(filter-out $(MXE_CONF_PKGS) cmake-conf cmake, \
  405. $(sort $(basename $(notdir \
  406. $(shell grep -l '(TARGET)-cmake' \
  407. $(addsuffix /*.mk,$(MXE_PLUGIN_DIRS)))))))
  408. # all other packages should list their deps explicitly, if tools become
  409. # universally used, we can add them to the toolchain deps (e.g. pkgconf)
  410. # or add new implicit `${TOOL}_PKGS` rules
  411. # $(PKG) and $(TARGET) are in scope from the calling loop so reference
  412. # variables by name instead of position
  413. # explicit normal package deps
  414. PKG_DEPS = \
  415. $(foreach DEP,$(value $(call LOOKUP_PKG_RULE,$(PKG),DEPS,$(TARGET))), \
  416. $(if $(filter $(DEP),$(PKGS)), \
  417. $(if $(or $(value $(call LOOKUP_PKG_RULE,$(DEP),BUILD,$(TARGET))), \
  418. $(filter $($(DEP)_TYPE),$(BUILD_PKG_TYPES))), \
  419. $(TARGET)/installed/$(DEP)) \
  420. $(else), \
  421. $(if $(or $(value $(call LOOKUP_PKG_RULE,$($(DEP)_PKG),BUILD,$($(DEP)_TGT))), \
  422. $(filter $($($(DEP)_PKG)_TYPE),$(BUILD_PKG_TYPES))), \
  423. $($(DEP)_TGT)/installed/$($(DEP)_PKG))))
  424. # order-only package deps unlikely to need target lookup
  425. PKG_OO_DEPS = \
  426. $(foreach DEP,$($(PKG)_OO_DEPS), \
  427. $(if $(filter $(DEP),$(PKGS)), \
  428. $(if $(or $(value $(call LOOKUP_PKG_RULE,$(DEP),BUILD,$(TARGET))), \
  429. $(filter $($(DEP)_TYPE),$(BUILD_PKG_TYPES))), \
  430. $(TARGET)/installed/$(DEP)) \
  431. $(else), \
  432. $(if $(or $(value $(call LOOKUP_PKG_RULE,$($(DEP)_PKG),BUILD,$($(DEP)_TGT))), \
  433. $(filter $($($(DEP)_PKG)_TYPE),$(BUILD_PKG_TYPES))), \
  434. $($(DEP)_TGT)/installed/$($(DEP)_PKG))))
  435. # all deps for download rules (includes source-only pkgs)
  436. PKG_ALL_DEPS = \
  437. $(foreach DEP,$($(PKG)_OO_DEPS) $(value $(call LOOKUP_PKG_RULE,$(PKG),DEPS,$(TARGET))), \
  438. $(if $(filter $(DEP),$(PKGS)), \
  439. $(TARGET)~$(DEP), \
  440. $(DEP)))
  441. # include files from MXE_PLUGIN_DIRS, set base filenames and `all-<plugin>` target
  442. PLUGIN_FILES := $(realpath $(wildcard $(addsuffix /*.mk,$(MXE_PLUGIN_DIRS))))
  443. PKGS := $(sort $(basename $(notdir $(PLUGIN_FILES))))
  444. $(foreach FILE,$(PLUGIN_FILES),\
  445. $(eval $(basename $(notdir $(FILE)))_MAKEFILE ?= $(FILE)) \
  446. $(eval $(basename $(notdir $(FILE)))_TEST_FILE ?= $(filter-out %.cmake,$(wildcard $(basename $(FILE))-test.*))) \
  447. $(eval all-$(lastword $(call split,/,$(dir $(FILE)))): $(basename $(notdir $(FILE)))))
  448. include $(PLUGIN_FILES)
  449. # create target sets for PKG_TARGET_RULE loop to avoid creating empty rules
  450. # and having to explicitly disable $(BUILD) for most packages
  451. # add autotools, cmake, mxe-conf implicit order-only deps
  452. CROSS_TARGETS := $(filter-out $(BUILD),$(MXE_TARGETS))
  453. $(foreach PKG,$(PKGS), \
  454. $(if $(filter $(PKG),$(filter-out $(autotools_DEPS),$(AUTOTOOLS_PKGS))),\
  455. $(eval $(PKG)_OO_DEPS += $(BUILD)~autotools)) \
  456. $(if $(filter $(PKG),$(CMAKE_PKGS)),$(eval $(PKG)_OO_DEPS += cmake-conf)) \
  457. $(if $(filter $(PKG),$(MXE_CONF_PKGS)),,$(eval $(PKG)_OO_DEPS += mxe-conf)) \
  458. $(if $(filter %$(PKG),$(MXE_CONF_PKGS) $(BOOTSTRAP_PKGS)),,$(eval $(PKG)_OO_DEPS += $(BOOTSTRAP_PKGS))) \
  459. $(eval $(PKG)_TARGETS := $(sort $($(PKG)_TARGETS))) \
  460. $(if $($(PKG)_TARGETS),,$(eval $(PKG)_TARGETS := $(CROSS_TARGETS))) \
  461. $(foreach TARGET,$(filter $($(PKG)_TARGETS),$(CROSS_TARGETS) $(BUILD)), \
  462. $(eval $(TARGET)~$(PKG)_PKG := $(PKG)) \
  463. $(eval $(TARGET)~$(PKG)_TGT := $(TARGET)) \
  464. $(eval $(TARGET)_PKGS += $(PKG))))
  465. # always add $(BUILD) to our targets
  466. override MXE_TARGETS := $(CROSS_TARGETS) $(BUILD)
  467. # cache some target string manipulation functions with normal make variables
  468. CHOP_TARGETS = \
  469. $(if $(1),\
  470. $(eval CHOPPED := $(call merge,.,$(call chop,$(call split,.,$(1)))))\
  471. $(eval $(1)_CHOPPED := $(CHOPPED))\
  472. $(call CHOP_TARGETS,$(CHOPPED)))
  473. $(foreach TARGET,$(MXE_TARGETS),\
  474. $(call CHOP_TARGETS,$(TARGET))\
  475. $(eval $(TARGET)_UC_LIB_TYPE := $(if $(findstring shared,$(TARGET)),SHARED,STATIC)))
  476. # finds a package rule defintion
  477. RULE_TYPES := BUILD DEPS FILE MESSAGE URL
  478. # by truncating the target elements then looking for STAIC|SHARED rules:
  479. #
  480. # foo_BUILD_i686-w64-mingw32.static.win32.dw2
  481. # foo_BUILD_i686-w64-mingw32.static.win32
  482. # foo_BUILD_i686-w64-mingw32.static
  483. # foo_BUILD_i686-w64-mingw32
  484. # foo_BUILD_SHARED
  485. # foo_BUILD
  486. # return the pre-populated rule if defined
  487. LOOKUP_PKG_RULE = $(or $(LOOKUP_PKG_RULE_$(1)_$(2)_$(3)),$(1)_$(2))
  488. # $(call _LOOKUP_PKG_RULE, package, rule type, target [, lib type])
  489. # returns variable name for use with $(value). PKG_RULE below will
  490. # populate LOOKUP_PKG_RULE_* variables for rules that require lookups
  491. _LOOKUP_PKG_RULE = $(strip \
  492. $(if $(findstring undefined, $(flavor $(PKG)_$(RULE)_$(3))),\
  493. $(if $(3),\
  494. $(call _LOOKUP_PKG_RULE,$(PKG),$(RULE),$($(3)_CHOPPED),$(or $(4),$($(3)_UC_LIB_TYPE)))\
  495. $(else),\
  496. $(if $(4),\
  497. $(call _LOOKUP_PKG_RULE,$(PKG),$(RULE),$(4))\
  498. $(else),\
  499. $(PKG)_$(RULE)))\
  500. $(else),\
  501. $(PKG)_$(RULE)_$(3)))
  502. # set column widths for build status messages
  503. PKG_COL_WIDTH := $(call plus,2,$(call LIST_NMAX, $(sort $(call map, strlen, $(PKGS)))))
  504. MAX_TARGET_WIDTH := $(call LIST_NMAX, $(sort $(call map, strlen, $(MXE_TARGETS))))
  505. TARGET_COL_WIDTH := $(call subtract,100,$(call plus,$(PKG_COL_WIDTH),$(MAX_TARGET_WIDTH)))
  506. PRINTF_FMT := printf '%-$(PRINTF_COL_1_WIDTH)s %-$(PKG_COL_WIDTH)s %-$(TARGET_COL_WIDTH)s %-15s %s\n'
  507. RTRIM := $(SED) 's, \+$$$$,,'
  508. WRAP_MESSAGE = $(\n)$(\n)$(call repeat,-,60)$(\n)$(1)$(and $(2),$(\n)$(\n)$(2))$(\n)$(call repeat,-,60)$(\n)
  509. define TARGET_RULE
  510. $(if $(findstring i686-pc-mingw32,$(1)),\
  511. $(error $(call WRAP_MESSAGE,\
  512. Obsolete target specified: "$(1)",\
  513. Please use i686-w64-mingw32.[$(subst $(space),|,$(MXE_LIB_TYPES))]$(\n)\
  514. i686-pc-mingw32 removed 2014-10-14 (https://github.com/mxe/mxe/pull/529)\
  515. )))\
  516. $(if $(filter $(addsuffix %,$(MXE_TARGET_LIST) $(BUILD) $(MXE_TRIPLETS)),$(1)),,\
  517. $(error $(call WRAP_MESSAGE,\
  518. Invalid target specified: "$(1)",\
  519. Please use:$(\n)\
  520. $(subst $(space),$(\n) ,$(MXE_TARGET_LIST))\
  521. )))\
  522. $(if $(findstring 1,$(words $(subst ., ,$(filter-out $(BUILD),$(1))))),\
  523. $(warning $(call WRAP_MESSAGE,\
  524. Warning: Deprecated target specified "$(1)",\
  525. Please use $(1).[$(subst $(space),|,$(MXE_LIB_TYPES))]$(\n) \
  526. )))
  527. endef
  528. $(foreach TARGET,$(MXE_TARGETS),$(call TARGET_RULE,$(TARGET)))
  529. define PKG_RULE
  530. # configure GitHub metadata if GH_CONF is set
  531. $(if $($(PKG)_GH_CONF),$(eval $(MXE_SETUP_GITHUB)))
  532. $(eval $(PKG)_PATCHES := $(PKG_PATCHES))
  533. .PHONY: download-only-$(1)
  534. # Packages can share a source archive to build different sets of features
  535. # or dependencies (see bfd/binutils openscenegraph/openthreads qwt/qwt_qt4).
  536. # Use a double-colon rule to allow multiple definitions:
  537. # https://www.gnu.org/software/make/manual/html_node/Double_002dColon.html
  538. # N.B. the `::` rule will use values from first lexical definition e.g.:
  539. # $ make download-only-binutils
  540. # [download] bfd
  541. .PHONY: download-only-$($(1)_FILE)
  542. download-only-$(1): download-only-$($(1)_FILE)
  543. download-only-$($(1)_FILE)::
  544. $(and $($(1)_URL),
  545. @$$(if $$(REMOVE_DOWNLOAD),rm -f '$(PKG_DIR)/$($(1)_FILE)')
  546. @if ! $(call CHECK_PKG_ARCHIVE,$(1)); then \
  547. $(PRINTF_FMT) '[download]' '$($(1)_FILE)' | $(RTRIM); \
  548. [ -d '$(LOG_DIR)/$(TIMESTAMP)' ] || mkdir -p '$(LOG_DIR)/$(TIMESTAMP)'; \
  549. ($(call DOWNLOAD_PKG_ARCHIVE,$(1))) &> '$(LOG_DIR)/$(TIMESTAMP)/$(1)-download'; \
  550. grep 'MXE Warning' '$(LOG_DIR)/$(TIMESTAMP)/$(1)-download'; \
  551. ln -sf '$(TIMESTAMP)/$(1)-download' '$(LOG_DIR)/$(1)-download'; \
  552. if ! $(call CHECK_PKG_ARCHIVE,$(1)); then \
  553. echo; \
  554. echo 'Download failed or wrong checksum of package $(1)!'; \
  555. echo '------------------------------------------------------------'; \
  556. $(if $(findstring undefined, $(origin MXE_VERBOSE)),\
  557. tail -n 10 '$(LOG_DIR)/$(1)-download' | $(SED) -n '/./p';, \
  558. $(SED) -n '/./p' '$(LOG_DIR)/$(1)-download';) \
  559. echo '------------------------------------------------------------'; \
  560. echo '[log] $(LOG_DIR)/$(1)-download'; \
  561. echo; \
  562. exit 1; \
  563. fi; \
  564. fi)
  565. .PHONY: prepare-pkg-source-$(1)
  566. prepare-pkg-source-$(1): download-only-$(1)
  567. rm -rf '$(2)'
  568. mkdir -p '$(2)'
  569. $$(call PREPARE_PKG_SOURCE,$(1),$(2))
  570. # populate LOOKUP_PKG_RULE_ variables where there are multiple defined
  571. $(foreach RULE,$(RULE_TYPES),\
  572. $(if $(filter-out %_URL_2,$(filter-out $(PKG)_$(RULE),$(filter $(PKG)_$(RULE)%,$(.VARIABLES)))),\
  573. $(foreach TARGET,$(MXE_TARGETS),\
  574. $(eval LOOKUP_PKG_RULE_$(PKG)_$(RULE)_$(TARGET) := $(call _LOOKUP_PKG_RULE,$(PKG),$(RULE),$(TARGET))))))
  575. endef
  576. $(foreach PKG,$(PKGS),$(eval $(call PKG_RULE,$(PKG),$(call TMP_DIR,$(PKG)))))
  577. # disable networking during build-only rules for reproducibility
  578. ifeq ($(findstring darwin,$(BUILD)),)
  579. NONET_LIB := $(PREFIX)/$(BUILD)/lib/nonetwork.so
  580. PRELOAD := LD_PRELOAD='$(NONET_LIB)'
  581. else
  582. NONET_LIB := $(PREFIX)/$(BUILD)/lib/nonetwork.dylib
  583. PRELOAD := DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES='$(NONET_LIB)'
  584. NONET_CFLAGS := -arch x86_64
  585. endif
  586. $(NONET_LIB): $(TOP_DIR)/tools/nonetwork.c | $(PREFIX)/$(BUILD)/lib/.gitkeep
  587. @$(PRINTF_FMT) '[nonet lib]' '$@'
  588. +@$(BUILD_CC) -shared -fPIC $(NONET_CFLAGS) -o $@ $<
  589. .PHONY: nonet-lib
  590. nonet-lib: $(NONET_LIB)
  591. .PHONY: shell
  592. shell: $(NONET_LIB)
  593. $(PRELOAD) $(SHELL)
  594. define PKG_TARGET_RULE
  595. .PHONY: download-$(1)
  596. download-$(1): download-$(3)~$(1) download-only-$(1)
  597. .PHONY: download-$(3)~$(1)
  598. download-$(3)~$(1): download-only-$(1) \
  599. $(addprefix download-,$(PKG_ALL_DEPS))
  600. .PHONY: $(1) $(1)~$(3)
  601. # requested pkgs should not build their native version unless
  602. # explicitly set in DEPS or they only have a single target
  603. $(if $(filter-out $(BUILD),$(3))$(call not,$(word 2,$($(1)_TARGETS))),$(1)) \
  604. $(1)~$(3): $(PREFIX)/$(3)/installed/$(1)
  605. $(PREFIX)/$(3)/installed/$(1): $(PKG_MAKEFILES) \
  606. $($(PKG)_PATCHES) \
  607. $(PKG_TESTFILES) \
  608. $($(1)_FILE_DEPS) \
  609. $(addprefix $(PREFIX)/,$(PKG_DEPS)) \
  610. | $(if $(DONT_CHECK_REQUIREMENTS),,check-requirements) \
  611. $(if $(value $(call LOOKUP_PKG_RULE,$(1),URL,$(3))),download-only-$(1)) \
  612. $(addprefix $(PREFIX)/,$(PKG_OO_DEPS)) \
  613. $(addprefix download-,$(PKG_ALL_DEPS)) \
  614. $(NONET_LIB) \
  615. $(PREFIX)/$(3)/installed/.gitkeep \
  616. print-git-oneline
  617. $(if $(value $(call LOOKUP_PKG_RULE,$(1),MESSAGE,$(3))),
  618. @$(PRINTF_FMT) '[message]' '$(1)' '$(3) $($(call LOOKUP_PKG_RULE,$(1),MESSAGE,$(3)))' \
  619. | $(RTRIM)
  620. )
  621. $(if $(value $(call LOOKUP_PKG_RULE,$(1),BUILD,$(3))),
  622. $(if $(BUILD_DRY_RUN)$(MXE_BUILD_DRY_RUN), \
  623. @$(PRINTF_FMT) '[dry-run]' '$(1)' '$(3)' | $(RTRIM)
  624. @[ -d '$(PREFIX)/$(3)/lib' ] || mkdir -p '$(PREFIX)/$(3)/lib'
  625. @echo $(1)~$(3) > '$(PREFIX)/$(3)/lib/$(1).dry-run'
  626. @touch '$(PREFIX)/$(3)/installed/$(1)'
  627. $(else),
  628. @$(PRINTF_FMT) '[build]' '$(1)' '$(3)' | $(RTRIM)
  629. @[ -d '$(LOG_DIR)/$(TIMESTAMP)' ] || mkdir -p '$(LOG_DIR)/$(TIMESTAMP)'
  630. @touch '$(LOG_DIR)/$(TIMESTAMP)/$(1)_$(3)'
  631. @ln -sf '$(TIMESTAMP)/$(1)_$(3)' '$(LOG_DIR)/$(1)_$(3)'
  632. @if ! (time $(PRELOAD) WINEPREFIX='$(2)/readonly' \
  633. $(MAKE) -f '$(MAKEFILE)' \
  634. 'build-only-$(1)_$(3)' \
  635. WGET=false \
  636. ) &> '$(LOG_DIR)/$(TIMESTAMP)/$(1)_$(3)'; then \
  637. echo; \
  638. echo 'Failed to build package $(1) for target $(3)!'; \
  639. echo '------------------------------------------------------------'; \
  640. $(if $(findstring undefined, $(origin MXE_VERBOSE)),\
  641. tail -n 10 '$(LOG_DIR)/$(1)_$(3)' | $(SED) -n '/./p';, \
  642. $(SED) -n '/./p' '$(LOG_DIR)/$(1)_$(3)';) \
  643. echo '------------------------------------------------------------'; \
  644. echo '[log] $(LOG_DIR)/$(1)_$(3)'; \
  645. echo; \
  646. exit 1; \
  647. fi
  648. @$(PRINTF_FMT) '[done]' '$(1)' '$(3)' "`grep -a '^du:.*KiB$$\' '$(LOG_DIR)/$(TIMESTAMP)/$(1)_$(3)' | cut -d ':' -f2 | tail -1`" \
  649. "`grep -a '^real.*m.*s$$\' '$(LOG_DIR)/$(TIMESTAMP)/$(1)_$(3)' | tr '\t' ' ' | cut -d ' ' -f2 | tail -1`"
  650. )
  651. $(else),
  652. @$(PRINTF_FMT) '[$(or $($(PKG)_TYPE),disabled)]' '$(1)' '$(3)' | $(RTRIM)
  653. @touch '$(PREFIX)/$(3)/installed/$(1)'
  654. )
  655. .PHONY: build-only-$(1)_$(3)
  656. # target-specific variables provide an extra level of scoping so that named
  657. # variables can be used in package build rules:
  658. # https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html
  659. build-only-$(1)_$(3): PKG = $(1)
  660. build-only-$(1)_$(3): TARGET = $(3)
  661. build-only-$(1)_$(3): BUILD_$(if $(findstring shared,$(3)),SHARED,STATIC) = TRUE
  662. build-only-$(1)_$(3): BUILD_$(if $(call seq,$(TARGET),$(BUILD)),NATIVE,CROSS) = TRUE
  663. build-only-$(1)_$(3): $(if $(findstring win32,$(TARGET)),WIN32,POSIX)_THREADS = TRUE
  664. build-only-$(1)_$(3): LIB_SUFFIX = $(if $(findstring shared,$(3)),dll,a)
  665. build-only-$(1)_$(3): BITS = $(if $(findstring x86_64,$(3)),64,32)
  666. build-only-$(1)_$(3): PROCESSOR = $(firstword $(call split,-,$(3)))
  667. build-only-$(1)_$(3): BUILD_TYPE = $(if $(findstring debug,$(3) $($(1)_CONFIGURE_OPTS)),debug,release)
  668. build-only-$(1)_$(3): BUILD_TYPE_SUFFIX = $(if $(findstring debug,$(3) $($(1)_CONFIGURE_OPTS)),d)
  669. build-only-$(1)_$(3): INSTALL_STRIP_TOOLCHAIN = install$(if $(STRIP_TOOLCHAIN),-strip)
  670. build-only-$(1)_$(3): INSTALL_STRIP_LIB = install$(if $(STRIP_LIB),-strip)
  671. build-only-$(1)_$(3): SOURCE_DIR = $(or $(realpath $($(1)_SOURCE_TREE)),$(2)/$($(1)_SUBDIR))
  672. build-only-$(1)_$(3): BUILD_DIR = $(2)/$(if $($(1)_SOURCE_TREE),local,$($(1)_SUBDIR)).build_
  673. build-only-$(1)_$(3): TEST_FILE = $($(1)_TEST_FILE)
  674. build-only-$(1)_$(3): CMAKE_RUNRESULT_FILE = $(PREFIX)/share/cmake/modules/TryRunResults.cmake
  675. build-only-$(1)_$(3): CMAKE_TOOLCHAIN_FILE = $(PREFIX)/$(3)/share/cmake/mxe-conf.cmake
  676. build-only-$(1)_$(3): CMAKE_TOOLCHAIN_DIR = $(PREFIX)/$(3)/share/cmake/mxe-conf.d
  677. build-only-$(1)_$(3): CMAKE_STATIC_BOOL = $(if $(findstring shared,$(3)),OFF,ON)
  678. build-only-$(1)_$(3): CMAKE_SHARED_BOOL = $(if $(findstring shared,$(3)),ON,OFF)
  679. build-only-$(1)_$(3):
  680. $(if $(value $(call LOOKUP_PKG_RULE,$(1),BUILD,$(3))),
  681. uname -a
  682. - git log --pretty=tformat:"%H - %s [%ar] [%d]" -1
  683. lsb_release -a 2>/dev/null || sw_vers 2>/dev/null || true
  684. autoconf --version 2>/dev/null | head -1
  685. automake --version 2>/dev/null | head -1
  686. $(BUILD_CC) --version
  687. $(BUILD_CXX) --version
  688. python --version
  689. perl --version 2>&1 | head -3
  690. rm -rf '$(2)'
  691. mkdir -p '$(2)'
  692. mkdir -p '$$(SOURCE_DIR)'
  693. mkdir -p '$$(BUILD_DIR)'
  694. # disable wine with readonly directory
  695. # see https://github.com/mxe/mxe/issues/841
  696. mkdir -p '$(2)/readonly'
  697. chmod 0555 '$(2)/readonly'
  698. $$(if $(and $(value $(call LOOKUP_PKG_RULE,$(1),FILE,$(3))),\
  699. $(call not,$(filter $(SCRIPT_PKG_TYPES),$($(PKG)_TYPE)))),\
  700. $$(call PREPARE_PKG_SOURCE,$(1),$(2)))
  701. $$(call $(call LOOKUP_PKG_RULE,$(1),BUILD,$(3)),$(2)/$($(1)_SUBDIR))
  702. @echo
  703. @find '$(2)' -name 'config.log' -print -exec cat {} \;
  704. @echo
  705. @echo 'settings.mk'
  706. @cat '$(TOP_DIR)/settings.mk'
  707. $(if $(STRIP_EXE),-$(TARGET)-strip '$(PREFIX)/$(TARGET)/bin/test-$(PKG).exe')
  708. (du -k -d 0 '$(2)' 2>/dev/null || du -k --max-depth 0 '$(2)') | $(SED) -n 's/^\(\S*\).*/du: \1 KiB/p'
  709. rm -rfv '$(2)'
  710. )
  711. touch '$(PREFIX)/$(3)/installed/$(1)'
  712. endef
  713. $(foreach TARGET,$(MXE_TARGETS), \
  714. $(foreach PKG,$($(TARGET)_PKGS), \
  715. $(eval $(call PKG_TARGET_RULE,$(PKG),$(call TMP_DIR,$(PKG)-$(TARGET)),$(TARGET)))))
  716. # convenience set-like functions for unique lists
  717. SET_APPEND = \
  718. $(eval $(1) := $(sort $($(1)) $(2)))
  719. SET_CLEAR = \
  720. $(eval $(1) := )
  721. # WALK functions accept a list of pkgs and/or wildcards
  722. # use PKG_ALL_DEPS and strip target prefixes to get
  723. # global package level deps
  724. WALK_UPSTREAM = \
  725. $(strip \
  726. $(foreach PKG,$(filter $(1),$(PKGS)),\
  727. $(foreach TARGET,$($(PKG)_TARGETS), \
  728. $(foreach DEP,$(sort $(subst $(BUILD)~,,$(subst $(TARGET)~,,$(PKG_ALL_DEPS)))),\
  729. $(if $(filter-out $(PKGS_VISITED),$(DEP)),\
  730. $(call SET_APPEND,PKGS_VISITED,$(DEP))\
  731. $(call WALK_UPSTREAM,$(DEP))\
  732. $(DEP))))))
  733. # not really walking downstream - that seems to be quadratic, so take
  734. # a linear approach and filter the fully expanded upstream for each pkg
  735. WALK_DOWNSTREAM = \
  736. $(strip \
  737. $(foreach PKG,$(PKGS),\
  738. $(call SET_CLEAR,PKGS_VISITED)\
  739. $(eval ALL_$(PKG)_DEPS := $(call WALK_UPSTREAM,$(PKG))))\
  740. $(foreach PKG,$(PKGS),\
  741. $(if $(filter $(1),$(ALL_$(PKG)_DEPS)),$(PKG))))
  742. # list of direct downstream deps
  743. DIRECT_DOWNSTREAM = \
  744. $(strip \
  745. $(foreach PKG,$(PKGS),\
  746. $(if $(filter $(1),$($(PKG)_DEPS)),$(PKG))))
  747. # EXCLUDE_PKGS can be a list of pkgs and/or wildcards
  748. RECURSIVELY_EXCLUDED_PKGS = \
  749. $(sort \
  750. $(filter $(EXCLUDE_PKGS),$(PKGS))\
  751. $(call SET_CLEAR,PKGS_VISITED)\
  752. $(call WALK_DOWNSTREAM,$(EXCLUDE_PKGS)))
  753. # INCLUDE_PKGS can be a list of pkgs and/or wildcards
  754. # only used by build-pkg
  755. INCLUDE_PKGS := $(MXE_BUILD_PKG_PKGS)
  756. RECURSIVELY_INCLUDED_PKGS = \
  757. $(sort \
  758. $(filter $(INCLUDE_PKGS),$(PKGS))\
  759. $(call SET_CLEAR,PKGS_VISITED)\
  760. $(call WALK_UPSTREAM,$(INCLUDE_PKGS)))
  761. REQUIRED_PKGS = \
  762. $(filter-out $(and $(EXCLUDE_PKGS),$(RECURSIVELY_EXCLUDED_PKGS)),\
  763. $(or $(and $(INCLUDE_PKGS),$(strip $(RECURSIVELY_INCLUDED_PKGS))),$(PKGS)))
  764. .PHONY: all-filtered
  765. all-filtered: $(REQUIRED_PKGS)
  766. .PHONY: download
  767. download: $(addprefix download-,$(REQUIRED_PKGS))
  768. # print a list of upstream dependencies and downstream dependents
  769. show-deps-%:
  770. $(if $(call set_is_member,$*,$(PKGS)),\
  771. $(call SET_CLEAR,PKGS_VISITED)\
  772. $(info $* upstream dependencies:$(newline)\
  773. $(call WALK_UPSTREAM,$*)\
  774. $(newline)$(newline)$* direct downstream dependents:$(newline)\
  775. $(call DIRECT_DOWNSTREAM,$*)\
  776. $(newline)$(newline)$* recursive downstream dependents:$(newline)\
  777. $(call WALK_DOWNSTREAM,$*))\
  778. @echo,\
  779. $(error Package $* not found))
  780. # show upstream dependencies and downstream dependents separately
  781. # suitable for usage in shell with: `make show-downstream-deps-foo`
  782. # @echo -n suppresses the "Nothing to be done" without an eol
  783. show-downstream-deps-%:
  784. $(if $(call set_is_member,$*,$(PKGS)),\
  785. $(call SET_CLEAR,PKGS_VISITED)\
  786. $(info $(call WALK_DOWNSTREAM,$*))\
  787. @echo -n,\
  788. $(error Package $* not found))
  789. show-direct-downstream-deps-%:
  790. $(if $(call set_is_member,$*,$(PKGS)),\
  791. $(info $(call DIRECT_DOWNSTREAM,$*))\
  792. @echo -n,\
  793. $(error Package $* not found))
  794. show-upstream-deps-%:
  795. $(if $(call set_is_member,$*,$(PKGS)),\
  796. $(call SET_CLEAR,PKGS_VISITED)\
  797. $(info $(call WALK_UPSTREAM,$*))\
  798. @echo -n,\
  799. $(error Package $* not found))
  800. # print first level pkg deps for use in build-pkg.lua
  801. .PHONY: print-deps-for-build-pkg
  802. print-deps-for-build-pkg:
  803. $(foreach TARGET,$(sort $(MXE_TARGETS)), \
  804. $(foreach PKG,$(filter $(REQUIRED_PKGS),$(sort $($(TARGET)_PKGS))), \
  805. $(if $(or $(value $(call LOOKUP_PKG_RULE,$(PKG),BUILD,$(TARGET))), \
  806. $(filter $($(PKG)_TYPE),$(BUILD_PKG_TYPES))), \
  807. $(info $(strip for-build-pkg $(TARGET)~$(PKG) \
  808. $(subst $(space),-,$($(PKG)_VERSION)-$(OS_SHORT_NAME)) \
  809. $(subst /installed/,~,$(PKG_DEPS) $(PKG_OO_DEPS)))))))
  810. @echo -n
  811. BUILD_PKG_TMP_FILES := *-*.list mxe-*.tar.xz mxe-*.deb* wheezy jessie
  812. .PHONY: clean
  813. clean:
  814. rm -rf $(call TMP_DIR,*) $(PREFIX) \
  815. $(addprefix $(TOP_DIR)/, $(BUILD_PKG_TMP_FILES))
  816. @echo
  817. @echo 'review ccache size with:'
  818. @echo '$(MXE_CCACHE_DIR)/bin/ccache -s'
  819. .PHONY: clean-pkg
  820. clean-pkg:
  821. rm -f $(patsubst %,'%', \
  822. $(filter-out \
  823. $(foreach PKG,$(PKGS),$(PKG_DIR)/$($(PKG)_FILE) $(PKG_DIR)/$($(PKG)_FILE)_$($(PKG)_CHECKSUM)), \
  824. $(wildcard $(PKG_DIR)/*)))
  825. .PHONY: clean-junk
  826. clean-junk: clean-pkg
  827. rm -rf $(LOG_DIR) $(call TMP_DIR,*)
  828. .PHONY: cleanup-style
  829. define CLEANUP_STYLE
  830. @$(SED) ' \
  831. s/\r//g; \
  832. s/[ \t]\+$$//; \
  833. s,^#!/bin/bash$$,#!/usr/bin/env bash,; \
  834. $(if $(filter %Makefile,$(1)),,\
  835. s/\t/ /g; \
  836. ) \
  837. ' < $(1) > $(TOP_DIR)/tmp-cleanup-style
  838. @diff -u $(1) $(TOP_DIR)/tmp-cleanup-style >/dev/null \
  839. || { echo '[cleanup] $(1)'; \
  840. cp $(TOP_DIR)/tmp-cleanup-style $(1); }
  841. @rm -f $(TOP_DIR)/tmp-cleanup-style
  842. endef
  843. cleanup-style:
  844. $(foreach FILE,$(wildcard $(addprefix $(TOP_DIR)/,Makefile docs/index.html docs/CNAME src/*.mk src/*test.* tools/*)),$(call CLEANUP_STYLE,$(FILE)))
  845. .PHONY: cleanup-deps-style
  846. cleanup-deps-style:
  847. @grep '(PKG)_DEPS.*\\' $(foreach 1,$(PKGS),$(PKG_MAKEFILES)) > $(TOP_DIR)/tmp-$@-pre
  848. @$(foreach PKG,$(PKGS), \
  849. $(if $(call lne,$(sort $(filter-out $(CROSS_COMPILER),$($(PKG)_DEPS))),$(filter-out $(CROSS_COMPILER),$($(PKG)_DEPS))), \
  850. $(info [cleanup] $(PKG)) \
  851. $(SED) -i 's/^\([^ ]*_DEPS *:=\)[^$$]*$$/\1 '"$(strip $(filter $(CROSS_COMPILER),$($(PKG)_DEPS)) $(sort $(filter-out $(CROSS_COMPILER),$($(PKG)_DEPS))))"'/' '$(call PKG_MAKEFILES,$(PKG))'; \
  852. ))
  853. @grep '(PKG)_DEPS.*\\' $(foreach 1,$(PKGS),$(PKG_MAKEFILES)) > $(TOP_DIR)/tmp-$@-post
  854. @diff -u $(TOP_DIR)/tmp-$@-pre $(TOP_DIR)/tmp-$@-post >/dev/null \
  855. || echo '*** Multi-line deps are mangled ***' && comm -3 tmp-$@-pre tmp-$@-post
  856. @rm -f $(TOP_DIR)/tmp-$@-*
  857. .PHONY: docs/build-matrix.html
  858. docs/build-matrix.html: $(foreach 1,$(PKGS),$(PKG_MAKEFILES))
  859. @echo '<!DOCTYPE html>' > $@
  860. @echo '<html>' >> $@
  861. @echo '<head>' >> $@
  862. @echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">' >> $@
  863. @echo '<title>MXE Build Matrix</title>' >> $@
  864. @echo '<link rel="stylesheet" href="assets/common.css">' >> $@
  865. @echo '<link rel="stylesheet" href="assets/build-matrix.css">' >> $@
  866. @echo '</head>' >> $@
  867. @echo '<body>' >> $@
  868. @echo '<h2>MXE Build Matrix</h2>' >> $@
  869. @echo '<p>' >> $@
  870. @echo 'This is a table of all supported package/target' >> $@
  871. @echo 'matrix. Being supported means that this specific' >> $@
  872. @echo 'combination is working to the best of our knowledge,' >> $@
  873. @echo 'but does not mean that it is tested daily.' >> $@
  874. @echo '</p>' >> $@
  875. @echo '<p>' >> $@
  876. @echo 'If you found that some package is not working properly,'>> $@
  877. @echo 'please file a ticket on GitHub. If you figured out a' >> $@
  878. @echo 'way to make the package work for unsupported targets,' >> $@
  879. @echo 'feel free to submit a pull request.' >> $@
  880. @echo '</p>' >> $@
  881. @echo '<table class="fullscreen">' >> $@
  882. @echo '<thead>' >> $@
  883. @echo '<tr>' >> $@
  884. @echo '<th rowspan="2">Package</th>' >> $@
  885. @echo '<th rowspan="2">Version</th>' >> $@
  886. @$(foreach TRIPLET,$(MXE_TRIPLETS), \
  887. echo '<th colspan="$(words $(MXE_LIB_TYPES))">$(TRIPLET)</th>' >> $@;)
  888. @echo '<th rowspan="2">Native</th>' >> $@
  889. @echo '</tr>' >> $@
  890. @echo '<tr>' >> $@
  891. @$(foreach TRIPLET,$(MXE_TRIPLETS), \
  892. $(foreach LIB, $(MXE_LIB_TYPES), \
  893. echo '<th>$(LIB)</th>' >> $@;))
  894. @echo '</tr>' >> $@
  895. @echo '</thead>' >> $@
  896. @echo '<tbody>' >> $@
  897. # It is important to remember that the PKGCOUNT variables
  898. # are expressed in unary terms. So, after 5 virtual packages,
  899. # the content of $(VIRTUAL_PKGCOUNT) would be "x x x x x" and not "5".
  900. # Therefore, when using the PKGCOUNT, you have to use
  901. # $(words $(VIRTUAL_PKGCOUNT))
  902. # The same operations are included in GMSL "Integer Arithmetic Functions."
  903. # I chose not to use most of them because their names are too long.
  904. # $(eval $(VIRTUAL_PKGCOUNT += x))
  905. # vs
  906. # $(eval $(VIRTUAL_PKGCOUNT := $(call int_inc,$(VIRTUAL_PKGCOUNT))))
  907. @$(foreach PKG,$(PKGS), \
  908. $(eval $(PKG)_VIRTUAL := $(true)) \
  909. $(eval $(PKG)_BUILD_ONLY := $(true)) \
  910. echo -e '<tr>\n \
  911. <th class="row" \
  912. title="$($(PKG)_MESSAGE)"> \
  913. $(PKG) \
  914. $(if $($(PKG)_TYPE), [$($(PKG)_TYPE)-pkg]) \
  915. $(if $($(PKG)_MESSAGE), **)\
  916. </th>\n \
  917. <td>$(call substr,$($(PKG)_VERSION),1,12) \
  918. $(if $(call gt,$(call strlen,$($(PKG)_VERSION)),12),&hellip;)</td>\n\
  919. $(foreach TARGET,$(MXE_TARGET_LIST), \
  920. $(if $(filter $(VIRTUAL_PKG_TYPES),$($(PKG)_TYPE)), \
  921. $(if $(filter $(TARGET),$($(PKG)_TARGETS)), \
  922. <td class="neutral">&bull;</td>, \
  923. <td></td>), \
  924. $(if $(filter $(TARGET),$($(PKG)_TARGETS)), \
  925. $(if $(value $(call LOOKUP_PKG_RULE,$(PKG),BUILD,$(TARGET))), \
  926. $(eval $(TARGET)_PKGCOUNT += x) \
  927. <td class="supported">&#x2713;</td>, \
  928. <td class="unsupported">&#215;</td>),\
  929. <td></td>))\n) \
  930. $(if $(filter $(VIRTUAL_PKG_TYPES),$($(PKG)_TYPE)), \
  931. $(eval VIRTUAL_PKGCOUNT += x) \
  932. $(if $(filter $(BUILD),$($(PKG)_TARGETS)), \
  933. <td class="neutral">&bull;</td>, \
  934. <td></td>), \
  935. $(if $(filter $(BUILD),$($(PKG)_TARGETS)), \
  936. $(if $(value $(call LOOKUP_PKG_RULE,$(PKG),BUILD,$(BUILD))), \
  937. <td class="supported">&#x2713;</td>, \
  938. <td class="unsupported">&#215;</td>), \
  939. <td></td>))\n \
  940. </tr>\n' >> $@ $(newline) \
  941. $(if $(call seq,$(BUILD),$($(PKG)_TARGETS)), \
  942. $(eval BUILD_ONLY_PKGCOUNT += x)))
  943. @echo '<tr>' >> $@
  944. @echo '<th class="row" colspan="2">' >> $@
  945. # TOTAL_PKGCOUNT = PKGS - (VIRTUAL + BUILD_ONLY)
  946. @echo 'Total: $(call subtract, \
  947. $(words $(PKGS)), \
  948. $(words $(VIRTUAL_PKGCOUNT) $(BUILD_ONLY_PKGCOUNT)))'\
  949. >> $@
  950. @echo '<br>(+$(words $(VIRTUAL_PKGCOUNT)) virtual' >> $@
  951. @echo '+$(words $(BUILD_ONLY_PKGCOUNT)) native-only)' >> $@
  952. @echo '</th>' >> $@
  953. @$(foreach TARGET,$(MXE_TARGET_LIST), \
  954. echo '<th>$(words $($(TARGET)_PKGCOUNT))</th>' >> $@;)
  955. @echo '<th>$(words $($(BUILD)_PKGS))</th>' >> $@
  956. @echo '</tr>' >> $@
  957. @echo '</tbody>' >> $@
  958. @echo '</table>' >> $@
  959. @echo '</body>' >> $@
  960. @echo '</html>' >> $@
  961. .PHONY: docs/packages.json
  962. docs/packages.json: $(foreach 1,$(PKGS),$(PKG_MAKEFILES))
  963. @echo '{' > $@
  964. @{$(foreach PKG,$(PKGS), \
  965. echo ' "$(PKG)": \
  966. {"version": "$($(PKG)_VERSION)", \
  967. "website": "$($(PKG)_WEBSITE)", \
  968. "description": "$($(PKG)_DESCR)"},';)} >> $@
  969. @echo ' "": null' >> $@
  970. @echo '}' >> $@
  971. # for other mxe functions
  972. include mxe.patch.mk
  973. include mxe.updates.mk