makerelease-osx.mk 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. OPTFLAGS ?= -Os
  87. CFLAGS ?= -mmacosx-version-min=10.10 $(OPTFLAGS)
  88. export CFLAGS
  89. CXXFLAGS ?= -mmacosx-version-min=10.10 $(OPTFLAGS)
  90. export CXXFLAGS
  91. LDFLAGS ?= -Wl,-dead_strip
  92. export LDFLAGS
  93. LTO_FLAGS = -flto -ffunction-sections -fdata-sections
  94. # Dependency versions
  95. zlib_version = 1.2.11
  96. zlib_hash = e6d119755acdf9104d7ba236b1242696940ed6dd
  97. zlib_url = http://zlib.net/zlib-$(zlib_version).tar.gz
  98. expat_version = 2.2.0
  99. expat_hash = 8453bc52324be4c796fd38742ec48470eef358b3
  100. expat_url = http://sourceforge.net/projects/expat/files/expat/$(expat_version)/expat-$(expat_version).tar.bz2
  101. expat_cflags=$(LTO_FLAGS)
  102. expat_ldflags=$(CFLAGS) $(LTO_FLAGS)
  103. cares_version = 1.13.0
  104. cares_hash = dde50284cc3d505fb2463ff6276e61d5531b1d68
  105. cares_url = https://c-ares.haxx.se/download/c-ares-$(cares_version).tar.gz
  106. cares_confflags = "--enable-optimize=$(OPTFLAGS)"
  107. cares_cflags=$(LTO_FLAGS)
  108. cares_ldflags=$(CFLAGS) $(LTO_FLAGS)
  109. sqlite_version = autoconf-3190300
  110. sqlite_hash = 58f2cabffb3ff4761a3ac7f834d9db7b46307c1f
  111. sqlite_url = https://sqlite.org/2017/sqlite-$(sqlite_version).tar.gz
  112. sqlite_cflags=$(LTO_FLAGS)
  113. sqlite_ldflags=$(CFLAGS) $(LTO_FLAGS)
  114. gmp_version = 6.1.2
  115. gmp_hash = 366ded6a44cd108ba6b3f5b9a252eab3f3a95cdf
  116. gmp_url = https://ftp.gnu.org/gnu/gmp/gmp-$(gmp_version).tar.bz2
  117. gmp_confflags = --disable-cxx --enable-assembly --with-pic --enable-fat
  118. libgpgerror_version = 1.21
  119. libgpgerror_hash = ef1dfb2f8761f019091180596e9e638d8cc37513
  120. libgpgerror_url = https://gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-$(libgpgerror_version).tar.bz2
  121. libgpgerror_cflags=$(LTO_FLAGS)
  122. libgpgerror_ldflags=$(CFLAGS) $(LTO_FLAGS)
  123. libgpgerror_confflags = --with-pic --disable-languages --disable-doc --disable-nls
  124. libgcrypt_version = 1.6.5
  125. libgcrypt_hash = c3a5a13e717f7b3e3895650afc1b6e0d3fe9c726
  126. libgcrypt_url = https://gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-$(libgcrypt_version).tar.bz2
  127. libgcrypt_confflags=--with-gpg-error-prefix=$(PWD)/arch --disable-O-flag-munging --disable-asm --disable-amd64-as-feature-detection
  128. libssh2_version = 1.8.0
  129. libssh2_hash = baf2d1fb338eee531ba9b6b121c64235e089e0f5
  130. libssh2_url = https://www.libssh2.org/download/libssh2-$(libssh2_version).tar.gz
  131. libssh2_cflags=$(LTO_FLAGS)
  132. libssh2_ldflags=$(CFLAGS) $(LTO_FLAGS)
  133. libssh2_confflags = --with-pic --without-openssl --with-libgcrypt=$(PWD)/arch --with-libgcrypt-prefix=$(PWD)/arch
  134. libssh2_nocheck = yes
  135. cppunit_version = 1.12.1
  136. cppunit_hash = f1ab8986af7a1ffa6760f4bacf5622924639bf4a
  137. cppunit_url = http://sourceforge.net/projects/cppunit/files/cppunit/$(cppunit_version)/cppunit-$(cppunit_version).tar.gz
  138. # ARCHLIBS that can be template build
  139. ARCHLIBS = expat cares sqlite gmp libgpgerror libgcrypt libssh2 cppunit
  140. # NONARCHLIBS that cannot be template build
  141. NONARCHLIBS = zlib
  142. # Tags
  143. THIS_TAG := $(shell git describe --abbrev=0 $$(git rev-list --tags --max-count=1))
  144. PREV_TAG := $(shell git describe --abbrev=0 $(THIS_TAG)~1)
  145. # Aria2 setup
  146. ARIA2 := aria2-$(VERSION)
  147. ARIA2_PREFIX := $(PWD)/$(ARIA2)
  148. ARIA2_DIST := $(PWD)/$(ARIA2)-osx-darwin$(BUILD)
  149. ARIA2_CONFFLAGS = \
  150. --enable-static \
  151. --disable-shared \
  152. --enable-metalink \
  153. --enable-bittorrent \
  154. --disable-nls \
  155. --with-appletls \
  156. --with-libgmp \
  157. --with-sqlite3 \
  158. --with-libz \
  159. --with-libexpat \
  160. --with-libcares \
  161. --with-libgcrypt \
  162. --with-libssh2 \
  163. --without-libuv \
  164. --without-gnutls \
  165. --without-openssl \
  166. --without-libnettle \
  167. --without-libxml2 \
  168. ARIA2_STATIC=yes
  169. ARIA2_DOCDIR = $(ARIA2_PREFIX)/share/doc/aria2
  170. ARIA2_DOCS = \
  171. $(ARIA2_DOCDIR)/AUTHORS \
  172. $(ARIA2_DOCDIR)/COPYING \
  173. $(ARIA2_DOCDIR)/NEWS
  174. ARIA2_CHANGELOG = $(ARIA2_DOCDIR)/Changelog
  175. # Yeah, inlined XML, go figure :p
  176. define ARIA2_DISTXML
  177. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  178. <installer-gui-script minSpecVersion="1">
  179. <title>aria1 $(VERSION)</title>
  180. <welcome file="README.html"/>
  181. <pkg-ref id="aria2"/>
  182. <pkg-ref id="aria2.paths"/>
  183. <options customize="never" require-scripts="false" rootVolumeOnly="true"/>
  184. <volume-check>
  185. <allowed-os-versions>
  186. <os-version min="10.7"/>
  187. </allowed-os-versions>
  188. </volume-check>
  189. <domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/>
  190. <choices-outline>
  191. <line choice="default">
  192. <line choice="aria2"/>
  193. <line choice="aria2.paths"/>
  194. </line>
  195. </choices-outline>
  196. <choice id="default"/>
  197. <choice id="aria2" visible="false">
  198. <pkg-ref id="aria2"/>
  199. </choice>
  200. <choice id="aria2.paths" visible="false">
  201. <pkg-ref id="aria2.paths"/>
  202. </choice>
  203. <pkg-ref id="aria2" version="$(VERSION)" onConclusion="none">out.pkg</pkg-ref>
  204. <pkg-ref id="aria2.paths" version="$(VERSION)" onConclusion="none">paths.pkg</pkg-ref>
  205. </installer-gui-script>
  206. endef
  207. export ARIA2_DISTXML
  208. # Detect numer of CPUs to be used with make -j
  209. CPUS = $(shell sysctl hw.ncpu | cut -d" " -f2)
  210. # default target
  211. all::
  212. all::
  213. @if test "x$(NON_RELEASE)" = "x" && !(git describe --tags --exact); then \
  214. echo 'Not on a release tag; override by defining NON_RELEASE!'; \
  215. exit 1; \
  216. fi
  217. # No dice without sphinx
  218. all::
  219. @if test "x$$(which sphinx-build)" = "x"; then \
  220. echo "sphinx-build not present"; \
  221. exit 1; \
  222. fi;
  223. deps::
  224. # All those .PRECIOUS files, because otherwise gmake will treat them as
  225. # intermediates and remove them when the build completes. Thanks gmake!
  226. .PRECIOUS: %.tar.gz
  227. %.tar.gz:
  228. curl -o $@ -A 'curl/0; like wget' -L \
  229. $($(basename $(basename $@))_url)
  230. .PRECIOUS: %.check
  231. %.check: %.tar.gz
  232. @if test "$$(shasum -a1 $< | awk '{print $$1}')" != "$($(basename $@)_hash)"; then \
  233. echo "Invalid $@ hash"; \
  234. rm -f $<; \
  235. exit 1; \
  236. fi;
  237. touch $@
  238. .PRECIOUS: %.stamp
  239. %.stamp: %.tar.gz %.check
  240. tar xf $<
  241. mv $(basename $@)-$($(basename $@)_version) $(basename $@)
  242. touch $@
  243. .PRECIOUS: cares.stamp
  244. cares.stamp: cares.tar.gz cares.check
  245. tar xf $<
  246. mv c-ares-$($(basename $@)_version) $(basename $@)
  247. touch $@
  248. .PRECIOUS: libgpgerror.stamp
  249. libgpgerror.stamp: libgpgerror.tar.gz libgpgerror.check
  250. tar xf $<
  251. mv libgpg-error-$($(basename $@)_version) $(basename $@)
  252. touch $@
  253. # Using (NON)ARCH_template kinda stinks, but real multi-target pattern rules
  254. # only exist in feverish dreams.
  255. define NONARCH_template
  256. $(1).build: $(1).x86_64.build
  257. deps:: $(1).build
  258. endef
  259. .PRECIOUS: zlib.%.build
  260. zlib.%.build: zlib.stamp
  261. $(eval BASE := $(basename $<))
  262. $(eval DEST := $(basename $@))
  263. $(eval ARCH := $(subst .,,$(suffix $(DEST))))
  264. rsync -a $(BASE)/ $(DEST)
  265. ( cd $(DEST) && ./configure \
  266. --static --prefix=$(PWD)/arch \
  267. )
  268. $(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH)"
  269. $(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH)" check
  270. $(MAKE) -C $(DEST) -s install
  271. touch $@
  272. $(foreach lib,$(NONARCHLIBS),$(eval $(call NONARCH_template,$(lib))))
  273. define ARCH_template
  274. .PRECIOUS: $(1).%.build
  275. $(1).%.build: $(1).stamp
  276. $$(eval DEST := $$(basename $$@))
  277. $$(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
  278. mkdir -p $$(DEST)
  279. ( cd $$(DEST) && ../$(1)/configure \
  280. --enable-static --disable-shared \
  281. --prefix=$(PWD)/arch \
  282. $$($(1)_confflags) \
  283. CFLAGS="$$(CFLAGS) $$($(1)_cflags) -arch $$(ARCH)" \
  284. CXXFLAGS="$$(CXXFLAGS) $$($(1)_cxxflags) -arch $$(ARCH) -std=c++11" \
  285. LDFLAGS="$(LDFLAGS) $$($(1)_ldflags)" \
  286. PKG_CONFIG_PATH=$$(PWD)/arch/lib/pkgconfig \
  287. )
  288. $$(MAKE) -C $$(DEST) -sj$(CPUS)
  289. if test -z '$$($(1)_nocheck)'; then $$(MAKE) -C $$(DEST) -sj$(CPUS) check; fi
  290. $$(MAKE) -C $$(DEST) -s install
  291. touch $$@
  292. $(1).build: $(1).x86_64.build
  293. deps:: $(1).build
  294. endef
  295. $(foreach lib,$(ARCHLIBS),$(eval $(call ARCH_template,$(lib))))
  296. .PRECIOUS: aria2.%.build
  297. aria2.%.build: zlib.%.build expat.%.build gmp.%.build cares.%.build sqlite.%.build libgpgerror.%.build libgcrypt.%.build libssh2.%.build cppunit.%.build
  298. $(eval DEST := $$(basename $$@))
  299. $(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
  300. mkdir -p $(DEST)
  301. ( cd $(DEST) && ../$(SRCDIR)/configure \
  302. --prefix=$(ARIA2_PREFIX) \
  303. --bindir=$(PWD)/$(DEST) \
  304. --sysconfdir=/etc \
  305. --with-cppunit-prefix=$(PWD)/arch \
  306. $(ARIA2_CONFFLAGS) \
  307. CFLAGS="$(CFLAGS) $(LTO_FLAGS) -arch $(ARCH) -I$(PWD)/arch/include" \
  308. CXXFLAGS="$(CXXFLAGS) $(LTO_FLAGS) -arch $(ARCH) -I$(PWD)/arch/include" \
  309. LDFLAGS="$(LDFLAGS) $(CXXFLAGS) $(LTO_FLAGS) -L$(PWD)/arch/lib" \
  310. PKG_CONFIG_PATH=$(PWD)/arch/lib/pkgconfig \
  311. )
  312. $(MAKE) -C $(DEST) -sj$(CPUS)
  313. $(MAKE) -C $(DEST) -sj$(CPUS) check
  314. # Check that the resulting executable is Position-independent (PIE)
  315. otool -hv $(DEST)/src/aria2c | grep -q PIE
  316. $(MAKE) -C $(DEST) -sj$(CPUS) install-strip
  317. touch $@
  318. aria2.build: aria2.x86_64.build
  319. mkdir -p $(ARIA2_PREFIX)/bin
  320. cp -f aria2.x86_64/aria2c $(ARIA2_PREFIX)/bin/aria2c
  321. arch -64 $(ARIA2_PREFIX)/bin/aria2c -v
  322. touch $@
  323. $(ARIA2_CHANGELOG): aria2.x86_64.build
  324. git log --pretty=fuller --date=short $(PREV_TAG)..HEAD > $@
  325. $(ARIA2_DOCS): aria2.x86_64.build
  326. cp -av $(SRCDIR)/$(@F) $@
  327. $(ARIA2_DIST).tar.bz2: aria2.build $(ARIA2_DOCS) $(ARIA2_CHANGELOG)
  328. find $(ARIA2_PREFIX) -exec touch "{}" \;
  329. tar -cf $@ \
  330. --use-compress-program="bzip2 -9" \
  331. $(ARIA2)
  332. $(ARIA2_DIST).pkg: aria2.build $(ARIA2_DOCS) $(ARIA2_CHANGELOG)
  333. find $(ARIA2_PREFIX) -exec touch "{}" \;
  334. pkgbuild \
  335. --root $(ARIA2) \
  336. --identifier aria2 \
  337. --version $(VERSION) \
  338. --install-location /usr/local/aria2 \
  339. --ownership recommended \
  340. out.pkg
  341. pkgbuild \
  342. --root $(SRCDIR)/osx-package/etc \
  343. --identifier aria2.paths \
  344. --version $(VERSION) \
  345. --install-location /etc \
  346. --ownership recommended \
  347. paths.pkg
  348. echo "$$ARIA2_DISTXML" > dist.xml
  349. productbuild \
  350. --distribution dist.xml \
  351. --resources $(ARIA2_PREFIX)/share/doc/aria2 \
  352. $@
  353. rm -rf out.pkg paths.pkg dist.xml
  354. $(ARIA2_DIST).dmg: $(ARIA2_DIST).pkg
  355. -rm -rf dmg
  356. mkdir -p dmg/Docs
  357. cp -av $(ARIA2_DIST).pkg dmg/aria2.pkg
  358. find $(ARIA2_PREFIX)/share/doc/aria2 -maxdepth 1 -type f -exec cp -av "{}" dmg/Docs \;
  359. rm -rf dmg/Docs/README dmg/Docs/README.rst
  360. cp $(SRCDIR)/osx-package/DS_Store dmg/.DS_Store
  361. hdiutil create $@.uncompressed \
  362. -srcfolder dmg \
  363. -volname "aria2 $(VERSION) Intel" \
  364. -ov
  365. hdiutil convert -format UDBZ -o $@ $@.uncompressed.dmg
  366. hdiutil flatten $@
  367. rm -rf $@.uncompressed.dmg dmg
  368. dist.build: $(ARIA2_DIST).tar.bz2 $(ARIA2_DIST).pkg $(ARIA2_DIST).dmg
  369. echo 'Build success: $(ARIA2_DIST)'
  370. touch $@
  371. all:: dist.build
  372. clean-dist:
  373. rm -rf $(ARIA2_DIST).tar.bz2 $(ARIA2_DIST).pkg $(ARIA2_DIST).dmg
  374. clean: clean-dist
  375. rm -rf *aria2*
  376. cleaner: clean
  377. rm -rf *.build *.check *.stamp $(ARCHLIBS) $(NONARCHLIBS) arch *.x86_64
  378. really-clean: cleaner
  379. rm -rf *.tar.*
  380. .PHONY: all multi clean-dist clean cleaner really-clean