makerelease-osx.mk 14 KB

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