makerelease-osx.mk 15 KB

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