makerelease-osx.mk 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. # Any copyright is dedicated to the Public Domain.
  2. # http://creativecommons.org/publicdomain/zero/1.0/
  3. # Written by Nils Maier
  4. # This make file will:
  5. # - Download a set of dependencies and verify the known-good hashes.
  6. # - Build static libraries of aria2 dependencies.
  7. # - Create a statically linked, aria2 release.
  8. # - The build will have all major features enabled, and will use
  9. # AppleTLS and GMP.
  10. # - Create a corresponding .tar.bz containing the binaries:
  11. # - Create a corresponding .pkg installer.
  12. # - Create a corresponding .dmg image containing said installer.
  13. #
  14. # This Makefile will also run all `make check` targets.
  15. #
  16. # The dependencies currently build are:
  17. # - zlib (compression, in particular web compression)
  18. # - c-ares (asynchronous DNS resolver)
  19. # - expat (XML parser, for metalinks)
  20. # - gmp (multi-precision arithmetric library, for DHKeyExchange, BitTorrent)
  21. # - sqlite3 (self-contained SQL database, for Firefox3 cookie reading)
  22. # - cppunit (unit tests for C++, framework in use by aria2 `make check`)
  23. #
  24. #
  25. # To use this Makefile, do something along the lines of
  26. # - $ mkdir build-release
  27. # - $ cd build-release
  28. # - $ virtualenv .
  29. # - $ . bin/activate
  30. # - $ pip install sphinx-build
  31. # - $ ln -s ../makerelease-os.mk Makefile
  32. # - $ make
  33. #
  34. # If you haven't checkout out a release tag, you need to specify NON_RELEASE.
  35. # $ export NON_RELEASE=1
  36. # to generate a dist with git commit
  37. # $ export NON_RELEASE=force
  38. # to force this script to behave like it was on a tag.
  39. #
  40. # Note: This Makefile expects to be called from a git clone of aria2.
  41. #
  42. # Note: In theory, everything can be build in parallel, however the sub-makes
  43. # will be called with an appropriate -j flag. Building the `deps` target in
  44. # parallel before a general make might be beneficial, as the dependencies
  45. # usually bottle-neck on the configure steps.
  46. #
  47. # Note: Of course, you need to have XCode with the command line tools
  48. # installed for this to work, aka. a working compiler...
  49. #
  50. # Note: We're locally building the dependencies here, static libraries only.
  51. # This is required, because when using brew or MacPorts, which also provide
  52. # dynamic libraries, the linker will pick up the dynamic versions, always,
  53. # with no way to instruct the linker otherwise.
  54. # If you're building aria2 just for yourself and your system, using brewed
  55. # libraries is fine as well.
  56. #
  57. # Note: This Makefile is riddled with mac-isms. It will not work on *nix.
  58. #
  59. # Note: The convoluted way to create separate arch builds and later merge them
  60. # with lipo is because of two things:
  61. # 1) Avoid patching c-ares, which hardcodes some sizes in its headers.
  62. #
  63. # Note: This Makefile uses resources from osx-package when creating the
  64. # *.pkg and *.dmg targets
  65. SHELL := bash
  66. # A bit awkward, but OSX doesn't have a proper `readlink -f`.
  67. SRCDIR := $(shell dirname $(lastword $(shell stat -f "%N %Y" $(lastword $(MAKEFILE_LIST)))))
  68. # Same as in script-helper, but a bit easier on the eye (but more error prone)
  69. # and Makefile compatible
  70. BASE_VERSION := $(shell grep AC_INIT $(SRCDIR)/configure.ac | cut -d'[' -f3 | cut -d']' -f1)
  71. ifeq ($(NON_RELEASE),)
  72. VERSION := $(BASE_VERSION)
  73. else
  74. ifeq ($(NON_RELEASE),force)
  75. VERSION := $(BASE_VERSION)
  76. else
  77. VERSION := $(subst release-,,$(shell git describe --tags))
  78. endif
  79. endif
  80. # Set up compiler.
  81. CC = cc
  82. export CC
  83. CXX = c++ -stdlib=libc++
  84. export CXX
  85. # Set up compiler/linker flags.
  86. PLATFORMFLAGS ?= -mmacosx-version-min=10.10
  87. OPTFLAGS ?= -Os
  88. CFLAGS ?= $(PLATFORMFLAGS) $(OPTFLAGS)
  89. export CFLAGS
  90. CXXFLAGS ?= $(PLATFORMFLAGS) $(OPTFLAGS)
  91. export CXXFLAGS
  92. LDFLAGS ?= -Wl,-dead_strip
  93. export LDFLAGS
  94. LTO_FLAGS = -flto -ffunction-sections -fdata-sections
  95. # Dependency versions
  96. zlib_version = 1.2.11
  97. zlib_hash = c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1
  98. zlib_url = http://zlib.net/zlib-$(zlib_version).tar.gz
  99. expat_version = 2.2.8
  100. expat_hash = bd507cba42716ca9afe46dd3687fb0d46c09347517beb9770f53a435d2c67ea0
  101. expat_url = https://github.com/libexpat/libexpat/releases/download/R_2_2_8/expat-2.2.8.tar.gz
  102. expat_cflags=$(CFLAGS) $(LTO_FLAGS)
  103. expat_ldflags=$(CFLAGS) $(LTO_FLAGS)
  104. cares_version = 1.15.0
  105. cares_hash = 6cdb97871f2930530c97deb7cf5c8fa4be5a0b02c7cea6e7c7667672a39d6852
  106. cares_url = https://c-ares.haxx.se/download/c-ares-$(cares_version).tar.gz
  107. cares_confflags = "--enable-optimize=$(OPTFLAGS)"
  108. cares_cflags=$(CFLAGS) $(LTO_FLAGS)
  109. cares_ldflags=$(CFLAGS) $(LTO_FLAGS)
  110. sqlite_version = autoconf-3300000
  111. sqlite_hash = e0a8cf4c7a87455e55e10413d16f358ca121ccec687fe1301eac95e2d340fc58
  112. sqlite_url = https://sqlite.org/2019/sqlite-$(sqlite_version).tar.gz
  113. sqlite_cflags=$(CFLAGS) $(LTO_FLAGS)
  114. sqlite_ldflags=$(CFLAGS) $(LTO_FLAGS)
  115. gmp_version = 6.1.2
  116. gmp_hash = 5275bb04f4863a13516b2f39392ac5e272f5e1bb8057b18aec1c9b79d73d8fb2
  117. gmp_url = https://ftp.gnu.org/gnu/gmp/gmp-$(gmp_version).tar.bz2
  118. gmp_confflags = --disable-cxx --enable-assembly --with-pic --enable-fat
  119. gmp_cflags=$(CFLAGS)
  120. gmp_cxxflags=$(CXXFLAGS)
  121. libgpgerror_version = 1.36
  122. libgpgerror_hash = babd98437208c163175c29453f8681094bcaf92968a15cafb1a276076b33c97c
  123. libgpgerror_url = https://gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-$(libgpgerror_version).tar.bz2
  124. libgpgerror_cflags=$(CFLAGS) $(LTO_FLAGS)
  125. libgpgerror_ldflags=$(CFLAGS) $(LTO_FLAGS)
  126. libgpgerror_confflags = --with-pic --disable-languages --disable-doc --disable-nls
  127. libgcrypt_version = 1.8.5
  128. libgcrypt_hash = 3b4a2a94cb637eff5bdebbcaf46f4d95c4f25206f459809339cdada0eb577ac3
  129. libgcrypt_url = https://gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-$(libgcrypt_version).tar.bz2
  130. libgcrypt_confflags=--with-gpg-error-prefix=$(PWD)/arch --disable-O-flag-munging --disable-asm --disable-amd64-as-feature-detection
  131. libgcrypt_cflags=$(PLATFORMFLAGS)
  132. libgcrypt_cxxflags=$(PLATFORMFLAGS)
  133. libssh2_version = 1.9.0
  134. libssh2_hash = d5fb8bd563305fd1074dda90bd053fb2d29fc4bce048d182f96eaa466dfadafd
  135. libssh2_url = https://www.libssh2.org/download/libssh2-$(libssh2_version).tar.gz
  136. libssh2_cflags=$(CFLAGS) $(LTO_FLAGS)
  137. libssh2_cxxflags=$(CXXFLAGS) $(LTO_FLAGS)
  138. libssh2_ldflags=$(CFLAGS) $(LTO_FLAGS)
  139. libssh2_confflags = --with-pic --without-openssl --with-libgcrypt=$(PWD)/arch --with-libgcrypt-prefix=$(PWD)/arch
  140. libssh2_nocheck = yes
  141. cppunit_version = 1.12.1
  142. cppunit_hash = ac28a04c8e6c9217d910b0ae7122832d28d9917fa668bcc9e0b8b09acb4ea44a
  143. cppunit_url = http://sourceforge.net/projects/cppunit/files/cppunit/$(cppunit_version)/cppunit-$(cppunit_version).tar.gz
  144. cppunit_cflags=$(CFLAGS) $(LTO_FLAGS)
  145. cppunit_cxxflags=$(CXXFLAGS) $(LTO_FLAGS)
  146. # ARCHLIBS that can be template build
  147. ARCHLIBS = expat cares sqlite gmp libgpgerror libgcrypt libssh2 cppunit
  148. # NONARCHLIBS that cannot be template build
  149. NONARCHLIBS = zlib
  150. # Tags
  151. THIS_TAG := $(shell git describe --abbrev=0 $$(git rev-list --tags --max-count=1))
  152. PREV_TAG := $(shell git describe --abbrev=0 $(THIS_TAG)~1)
  153. # Aria2 setup
  154. ARIA2 := aria2-$(VERSION)
  155. ARIA2_PREFIX := $(PWD)/$(ARIA2)
  156. ARIA2_DIST := $(PWD)/$(ARIA2)-osx-darwin$(BUILD)
  157. ARIA2_CONFFLAGS = \
  158. --enable-static \
  159. --disable-shared \
  160. --enable-metalink \
  161. --enable-bittorrent \
  162. --disable-nls \
  163. --with-appletls \
  164. --with-libgmp \
  165. --with-sqlite3 \
  166. --with-libz \
  167. --with-libexpat \
  168. --with-libcares \
  169. --with-libgcrypt \
  170. --with-libssh2 \
  171. --without-libuv \
  172. --without-gnutls \
  173. --without-openssl \
  174. --without-libnettle \
  175. --without-libxml2 \
  176. ARIA2_STATIC=yes
  177. ARIA2_DOCDIR = $(ARIA2_PREFIX)/share/doc/aria2
  178. ARIA2_DOCS = \
  179. $(ARIA2_DOCDIR)/AUTHORS \
  180. $(ARIA2_DOCDIR)/COPYING \
  181. $(ARIA2_DOCDIR)/NEWS
  182. ARIA2_CHANGELOG = $(ARIA2_DOCDIR)/Changelog
  183. # Yeah, inlined XML, go figure :p
  184. define ARIA2_DISTXML
  185. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  186. <installer-gui-script minSpecVersion="1">
  187. <title>aria1 $(VERSION)</title>
  188. <welcome file="README.html"/>
  189. <pkg-ref id="aria2"/>
  190. <pkg-ref id="aria2.paths"/>
  191. <options customize="never" require-scripts="false" rootVolumeOnly="true"/>
  192. <volume-check>
  193. <allowed-os-versions>
  194. <os-version min="10.7"/>
  195. </allowed-os-versions>
  196. </volume-check>
  197. <domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/>
  198. <choices-outline>
  199. <line choice="default">
  200. <line choice="aria2"/>
  201. <line choice="aria2.paths"/>
  202. </line>
  203. </choices-outline>
  204. <choice id="default"/>
  205. <choice id="aria2" visible="false">
  206. <pkg-ref id="aria2"/>
  207. </choice>
  208. <choice id="aria2.paths" visible="false">
  209. <pkg-ref id="aria2.paths"/>
  210. </choice>
  211. <pkg-ref id="aria2" version="$(VERSION)" onConclusion="none">out.pkg</pkg-ref>
  212. <pkg-ref id="aria2.paths" version="$(VERSION)" onConclusion="none">paths.pkg</pkg-ref>
  213. </installer-gui-script>
  214. endef
  215. export ARIA2_DISTXML
  216. # Detect numer of CPUs to be used with make -j
  217. CPUS = $(shell sysctl hw.ncpu | cut -d" " -f2)
  218. # default target
  219. all::
  220. all::
  221. @if test "x$(NON_RELEASE)" = "x" && !(git describe --tags --exact); then \
  222. echo 'Not on a release tag; override by defining NON_RELEASE!'; \
  223. exit 1; \
  224. fi
  225. # No dice without sphinx
  226. all::
  227. @if test "x$$(which sphinx-build)" = "x"; then \
  228. echo "sphinx-build not present"; \
  229. exit 1; \
  230. fi;
  231. deps::
  232. # All those .PRECIOUS files, because otherwise gmake will treat them as
  233. # intermediates and remove them when the build completes. Thanks gmake!
  234. .PRECIOUS: %.tar.gz
  235. %.tar.gz:
  236. curl -o $@ -A 'curl/0; like wget' -L \
  237. $($(basename $(basename $@))_url)
  238. .PRECIOUS: %.check
  239. %.check: %.tar.gz
  240. @if test "$$(shasum -a256 $< | awk '{print $$1}')" != "$($(basename $@)_hash)"; then \
  241. echo "Invalid $@ hash"; \
  242. rm -f $<; \
  243. exit 1; \
  244. fi;
  245. touch $@
  246. .PRECIOUS: %.stamp
  247. %.stamp: %.tar.gz %.check
  248. tar xf $<
  249. mv $(basename $@)-$($(basename $@)_version) $(basename $@)
  250. touch $@
  251. .PRECIOUS: cares.stamp
  252. cares.stamp: cares.tar.gz cares.check
  253. tar xf $<
  254. mv c-ares-$($(basename $@)_version) $(basename $@)
  255. touch $@
  256. .PRECIOUS: libgpgerror.stamp
  257. libgpgerror.stamp: libgpgerror.tar.gz libgpgerror.check
  258. tar xf $<
  259. mv libgpg-error-$($(basename $@)_version) $(basename $@)
  260. touch $@
  261. # Using (NON)ARCH_template kinda stinks, but real multi-target pattern rules
  262. # only exist in feverish dreams.
  263. define NONARCH_template
  264. $(1).build: $(1).x86_64.build
  265. deps:: $(1).build
  266. endef
  267. .PRECIOUS: zlib.%.build
  268. zlib.%.build: zlib.stamp
  269. $(eval BASE := $(basename $<))
  270. $(eval DEST := $(basename $@))
  271. $(eval ARCH := $(subst .,,$(suffix $(DEST))))
  272. rsync -a $(BASE)/ $(DEST)
  273. ( cd $(DEST) && ./configure \
  274. --static --prefix=$(PWD)/arch \
  275. )
  276. $(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH)"
  277. $(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH)" check
  278. $(MAKE) -C $(DEST) -s install
  279. touch $@
  280. $(foreach lib,$(NONARCHLIBS),$(eval $(call NONARCH_template,$(lib))))
  281. define ARCH_template
  282. .PRECIOUS: $(1).%.build
  283. $(1).%.build: $(1).stamp
  284. $$(eval DEST := $$(basename $$@))
  285. $$(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
  286. mkdir -p $$(DEST)
  287. ( cd $$(DEST) && ../$(1)/configure \
  288. --enable-static --disable-shared \
  289. --prefix=$(PWD)/arch \
  290. $$($(1)_confflags) \
  291. CFLAGS="$$($(1)_cflags) -arch $$(ARCH)" \
  292. CXXFLAGS="$$($(1)_cxxflags) -arch $$(ARCH) -std=c++11" \
  293. LDFLAGS="$(LDFLAGS) $$($(1)_ldflags)" \
  294. PKG_CONFIG_PATH=$$(PWD)/arch/lib/pkgconfig \
  295. )
  296. $$(MAKE) -C $$(DEST) -sj$(CPUS)
  297. if test -z '$$($(1)_nocheck)'; then $$(MAKE) -C $$(DEST) -sj$(CPUS) check; fi
  298. $$(MAKE) -C $$(DEST) -s install
  299. touch $$@
  300. $(1).build: $(1).x86_64.build
  301. deps:: $(1).build
  302. endef
  303. $(foreach lib,$(ARCHLIBS),$(eval $(call ARCH_template,$(lib))))
  304. .PRECIOUS: aria2.%.build
  305. aria2.%.build: zlib.%.build expat.%.build gmp.%.build cares.%.build sqlite.%.build libgpgerror.%.build libgcrypt.%.build libssh2.%.build cppunit.%.build
  306. $(eval DEST := $$(basename $$@))
  307. $(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
  308. mkdir -p $(DEST)
  309. ( cd $(DEST) && ../$(SRCDIR)/configure \
  310. --prefix=$(ARIA2_PREFIX) \
  311. --bindir=$(PWD)/$(DEST) \
  312. --sysconfdir=/etc \
  313. --with-cppunit-prefix=$(PWD)/arch \
  314. $(ARIA2_CONFFLAGS) \
  315. CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH) -I$(PWD)/arch/include" \
  316. CXXFLAGS="$(CXXFLAGS) $(LTO_FLAGS) -arch $(ARCH) -I$(PWD)/arch/include" \
  317. LDFLAGS="$(LDFLAGS) $(CXXFLAGS) $(LTO_FLAGS) -L$(PWD)/arch/lib" \
  318. PKG_CONFIG_PATH=$(PWD)/arch/lib/pkgconfig \
  319. )
  320. $(MAKE) -C $(DEST) -sj$(CPUS)
  321. $(MAKE) -C $(DEST) -sj$(CPUS) check
  322. # Check that the resulting executable is Position-independent (PIE)
  323. otool -hv $(DEST)/src/aria2c | grep -q PIE
  324. $(MAKE) -C $(DEST) -sj$(CPUS) install-strip
  325. touch $@
  326. aria2.build: aria2.x86_64.build
  327. mkdir -p $(ARIA2_PREFIX)/bin
  328. cp -f aria2.x86_64/aria2c $(ARIA2_PREFIX)/bin/aria2c
  329. arch -64 $(ARIA2_PREFIX)/bin/aria2c -v
  330. touch $@
  331. $(ARIA2_CHANGELOG): aria2.x86_64.build
  332. git log --pretty=fuller --date=short $(PREV_TAG)..HEAD > $@
  333. $(ARIA2_DOCS): aria2.x86_64.build
  334. cp -av $(SRCDIR)/$(@F) $@
  335. $(ARIA2_DIST).tar.bz2: aria2.build $(ARIA2_DOCS) $(ARIA2_CHANGELOG)
  336. find $(ARIA2_PREFIX) -exec touch "{}" \;
  337. gtar -cf $@ \
  338. --use-compress-program="bzip2 -9" \
  339. $(ARIA2)
  340. $(ARIA2_DIST).pkg: aria2.build $(ARIA2_DOCS) $(ARIA2_CHANGELOG)
  341. find $(ARIA2_PREFIX) -exec touch "{}" \;
  342. pkgbuild \
  343. --root $(ARIA2) \
  344. --identifier aria2 \
  345. --version $(VERSION) \
  346. --install-location /usr/local/aria2 \
  347. --ownership recommended \
  348. out.pkg
  349. pkgbuild \
  350. --root $(SRCDIR)/osx-package/etc \
  351. --identifier aria2.paths \
  352. --version $(VERSION) \
  353. --install-location /etc \
  354. --ownership recommended \
  355. paths.pkg
  356. echo "$$ARIA2_DISTXML" > dist.xml
  357. productbuild \
  358. --distribution dist.xml \
  359. --resources $(ARIA2_PREFIX)/share/doc/aria2 \
  360. $@
  361. rm -rf out.pkg paths.pkg dist.xml
  362. $(ARIA2_DIST).dmg: $(ARIA2_DIST).pkg
  363. -rm -rf dmg
  364. mkdir -p dmg/Docs
  365. cp -av $(ARIA2_DIST).pkg dmg/aria2.pkg
  366. find $(ARIA2_PREFIX)/share/doc/aria2 -maxdepth 1 -type f -exec cp -av "{}" dmg/Docs \;
  367. rm -rf dmg/Docs/README dmg/Docs/README.rst
  368. cp $(SRCDIR)/osx-package/DS_Store dmg/.DS_Store
  369. hdiutil create $@.uncompressed \
  370. -srcfolder dmg \
  371. -volname "aria2 $(VERSION) Intel" \
  372. -ov
  373. hdiutil convert -format UDBZ -o $@ $@.uncompressed.dmg
  374. hdiutil flatten $@
  375. rm -rf $@.uncompressed.dmg dmg
  376. dist.build: $(ARIA2_DIST).tar.bz2 $(ARIA2_DIST).pkg $(ARIA2_DIST).dmg
  377. echo 'Build success: $(ARIA2_DIST)'
  378. touch $@
  379. all:: dist.build
  380. clean-dist:
  381. rm -rf $(ARIA2_DIST).tar.bz2 $(ARIA2_DIST).pkg $(ARIA2_DIST).dmg
  382. clean: clean-dist
  383. rm -rf *aria2*
  384. cleaner: clean
  385. rm -rf *.build *.check *.stamp $(ARCHLIBS) $(NONARCHLIBS) arch *.x86_64
  386. really-clean: cleaner
  387. rm -rf *.tar.*
  388. .PHONY: all multi clean-dist clean cleaner really-clean