makerelease-osx.mk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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, universal build (i386,x86_64) aria2 release.
  8. # - The build will have all major features enabled, and will use
  9. # AppleTLS.
  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. # 2) Make it easy in the future to enable -flto (currently, -flto builds crash)
  63. #
  64. # Note: This Makefile uses resources from osx-package when creating the
  65. # *.pkg and *.dmg targets
  66. SHELL := bash
  67. # A bit awkward, but OSX doesn't have a proper `readlink -f`.
  68. SRCDIR := $(shell dirname $(lastword $(shell stat -f "%N %Y" $(lastword $(MAKEFILE_LIST)))))
  69. # Same as in script-helper, but a bit easier on the eye (but more error prone)
  70. # and Makefile compatible
  71. BASE_VERSION := $(shell grep AC_INIT $(SRCDIR)/configure.ac | cut -d'[' -f3 | cut -d']' -f1)
  72. ifeq ($(NON_RELEASE),)
  73. VERSION := $(BASE_VERSION)
  74. else
  75. ifeq ($(NON_RELEASE),force)
  76. VERSION := $(BASE_VERSION)
  77. else
  78. VERSION := $(subst release-,,$(shell git describe --tags))
  79. endif
  80. endif
  81. # Set up compiler.
  82. CC ?= cc
  83. export CC
  84. CXX ?= c++
  85. export CXX
  86. # Set up compiler/linker flags.
  87. OPTFLAGS ?= -Os
  88. CFLAGS ?= -mmacosx-version-min=10.7 $(OPTFLAGS)
  89. export CFLAGS
  90. CXXFLAGS ?= -mmacosx-version-min=10.7 $(OPTFLAGS)
  91. export CXXFLAGS
  92. LDFLAGS ?= -Wl,-dead_strip
  93. export LDFLAGS
  94. # Dependency versions
  95. zlib_version = 1.2.8
  96. zlib_hash = a4d316c404ff54ca545ea71a27af7dbc29817088
  97. zlib_url = http://zlib.net/zlib-$(zlib_version).tar.gz
  98. expat_version = 2.1.0
  99. expat_hash = b08197d146930a5543a7b99e871cba3da614f6f0
  100. expat_url = http://sourceforge.net/projects/expat/files/expat/$(expat_version)/expat-$(expat_version).tar.gz
  101. cares_version = 1.10.0
  102. cares_hash = e44e6575d5af99cb3a38461486e1ee8b49810eb5
  103. cares_url = http://c-ares.haxx.se/download/c-ares-$(cares_version).tar.gz
  104. cares_confflags = "--enable-optimize=$(OPTFLAGS)"
  105. sqlite_version = autoconf-3080200
  106. sqlite_hash = 6033ef603ce221d367c665477514d972ef1dc90e
  107. sqlite_url = http://sqlite.org/2013/sqlite-$(sqlite_version).tar.gz
  108. gmp_version = 5.1.3
  109. gmp_hash = b35928e2927b272711fdfbf71b7cfd5f86a6b165
  110. gmp_url = https://ftp.gnu.org/gnu/gmp/gmp-$(gmp_version).tar.bz2
  111. gmp_confflags = --disable-cxx --enable-assembly --with-pic
  112. cppunit_version = 1.12.1
  113. cppunit_hash = f1ab8986af7a1ffa6760f4bacf5622924639bf4a
  114. cppunit_url = http://sourceforge.net/projects/cppunit/files/cppunit/$(cppunit_version)/cppunit-$(cppunit_version).tar.gz
  115. # ARCHLIBS that can be template build
  116. ARCHLIBS = expat cares sqlite gmp cppunit
  117. # NONARCHLIBS that cannot be template build
  118. NONARCHLIBS = zlib
  119. # Tags
  120. THIS_TAG := $(shell git describe --abbrev=0 $$(git rev-list --tags --max-count=1))
  121. PREV_TAG := $(shell git describe --abbrev=0 $(THIS_TAG)~1)
  122. # Aria2 setup
  123. ARIA2 := aria2-$(VERSION)
  124. ARIA2_PREFIX := $(PWD)/$(ARIA2)
  125. ARIA2_DIST := $(PWD)/$(ARIA2)-osx-darwin
  126. ARIA2_CONFFLAGS = \
  127. --enable-static \
  128. --disable-shared \
  129. --enable-metalink \
  130. --enable-bittorrent \
  131. --disable-nls \
  132. --with-appletls \
  133. --with-libgmp \
  134. --with-sqlite3 \
  135. --with-libz \
  136. --with-libexpat \
  137. --with-libcares \
  138. --without-libuv \
  139. --without-gnutls \
  140. --without-openssl \
  141. --without-libnettle \
  142. --without-libgcrypt \
  143. --without-libxml2 \
  144. ARIA2_STATIC=yes
  145. ARIA2_DOCDIR = $(ARIA2_PREFIX)/share/doc/aria2
  146. ARIA2_DOCS = \
  147. $(ARIA2_DOCDIR)/AUTHORS \
  148. $(ARIA2_DOCDIR)/COPYING \
  149. $(ARIA2_DOCDIR)/NEWS
  150. ARIA2_CHANGELOG = $(ARIA2_DOCDIR)/Changelog
  151. # Yeah, inlined XML, go figure :p
  152. define ARIA2_DISTXML
  153. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  154. <installer-gui-script minSpecVersion="1">
  155. <title>aria1 $(VERSION)</title>
  156. <welcome file="README.html"/>
  157. <pkg-ref id="aria2"/>
  158. <pkg-ref id="aria2.paths"/>
  159. <options customize="never" require-scripts="false" rootVolumeOnly="true"/>
  160. <volume-check>
  161. <allowed-os-versions>
  162. <os-version min="10.7"/>
  163. </allowed-os-versions>
  164. </volume-check>
  165. <domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/>
  166. <choices-outline>
  167. <line choice="default">
  168. <line choice="aria2"/>
  169. <line choice="aria2.paths"/>
  170. </line>
  171. </choices-outline>
  172. <choice id="default"/>
  173. <choice id="aria2" visible="false">
  174. <pkg-ref id="aria2"/>
  175. </choice>
  176. <choice id="aria2.paths" visible="false">
  177. <pkg-ref id="aria2.paths"/>
  178. </choice>
  179. <pkg-ref id="aria2" version="$(VERSION)" onConclusion="none">out.pkg</pkg-ref>
  180. <pkg-ref id="aria2.paths" version="$(VERSION)" onConclusion="none">paths.pkg</pkg-ref>
  181. </installer-gui-script>
  182. endef
  183. export ARIA2_DISTXML
  184. # Detect numer of CPUs to be used with make -j
  185. CPUS = $(shell sysctl hw.ncpu | cut -d" " -f2)
  186. # default target
  187. all::
  188. @if test "x$(NON_RELEASE)" = "x" && !(git describe --tags --exact); then \
  189. echo 'Not on a release tag; override by defining NON_RELEASE!'; \
  190. exit 1; \
  191. fi
  192. # No dice without sphinx
  193. all::
  194. @if test "x$$(which sphinx-build)" = "x"; then \
  195. echo "sphinx-build not present"; \
  196. exit 1; \
  197. fi;
  198. deps::
  199. # All those .PRECIOUS files, because otherwise gmake will treat them as
  200. # intermediates and remove them when the build completes. Thanks gmake!
  201. .PRECIOUS: %.tar.gz
  202. %.tar.gz:
  203. curl -o $@ -A 'curl/0; like wget' -L \
  204. $($(basename $(basename $@))_url)
  205. .PRECIOUS: %.check
  206. %.check: %.tar.gz
  207. @if test "$$(shasum -a1 $< | awk '{print $$1}')" != "$($(basename $@)_hash)"; then \
  208. echo "Invalid $@ hash"; \
  209. rm -f $<; \
  210. exit 1; \
  211. fi;
  212. touch $@
  213. .PRECIOUS: %.stamp
  214. %.stamp: %.tar.gz %.check
  215. tar xf $<
  216. mv $(basename $@)-$($(basename $@)_version) $(basename $@)
  217. touch $@
  218. .PRECIOUS: cares.stamp
  219. cares.stamp: cares.tar.gz cares.check
  220. tar xzf $<
  221. mv c-ares-$($(basename $@)_version) $(basename $@)
  222. touch $@
  223. # Using (NON)ARCH_template kinda stinks, but real multi-target pattern rules
  224. # only exist in feverish dreams.
  225. define NONARCH_template
  226. $(1).build: $(1).x86_64.build $(1).i686.build
  227. deps:: $(1).build
  228. endef
  229. .PRECIOUS: zlib.%.build
  230. zlib.%.build: zlib.stamp
  231. $(eval BASE := $(basename $<))
  232. $(eval DEST := $(basename $@))
  233. $(eval ARCH := $(subst .,,$(suffix $(DEST))))
  234. rsync -a $(BASE)/ $(DEST)
  235. ( cd $(DEST) && ./configure \
  236. --static --prefix=$(PWD)/$(ARCH) \
  237. )
  238. $(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) -arch $(ARCH)"
  239. $(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) -arch $(ARCH)" check
  240. $(MAKE) -C $(DEST) -s install
  241. touch $@
  242. $(foreach lib,$(NONARCHLIBS),$(eval $(call NONARCH_template,$(lib))))
  243. define ARCH_template
  244. .PRECIOUS: $(1).%.build
  245. $(1).%.build: $(1).stamp
  246. $$(eval DEST := $$(basename $$@))
  247. $$(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
  248. mkdir -p $$(DEST)
  249. ( cd $$(DEST) && ../$(1)/configure \
  250. --host=$$(ARCH)-apple-darwin11.4.2 \
  251. --build=$$(ARCH)-apple-darwin11.4.2 \
  252. --enable-static --disable-shared \
  253. --prefix=$$(PWD)/$$(ARCH) \
  254. $$($(1)_confflags) \
  255. CFLAGS="$$(CFLAGS) -arch $$(ARCH)" \
  256. CXXFLAGS="$$(CXXFLAGS) -arch $$(ARCH) -stdlib=libc++ -std=c++11" \
  257. )
  258. $$(MAKE) -C $$(DEST) -sj$(CPUS)
  259. $$(MAKE) -C $$(DEST) -sj$(CPUS) check
  260. $$(MAKE) -C $$(DEST) -s install
  261. touch $$@
  262. $(1).build: $(1).x86_64.build $(1).i686.build
  263. deps:: $(1).build
  264. endef
  265. $(foreach lib,$(ARCHLIBS),$(eval $(call ARCH_template,$(lib))))
  266. .PRECIOUS: aria2.%.build
  267. aria2.%.build: zlib.%.build expat.%.build gmp.%.build cares.%.build sqlite.%.build cppunit.%.build
  268. $(eval DEST := $$(basename $$@))
  269. $(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
  270. mkdir -p $(DEST)
  271. ( cd $(DEST) && ../$(SRCDIR)/configure \
  272. --prefix=$(ARIA2_PREFIX) \
  273. --bindir=$(ARIA2_PREFIX)/$(ARCH) \
  274. --sysconfdir=/etc \
  275. --with-cppunit-prefix=$(PWD)/$(ARCH) \
  276. $(ARIA2_CONFFLAGS) \
  277. CFLAGS="$(CFLAGS) -arch $(ARCH)" \
  278. CXXFLAGS="$(CXXFLAGS) -arch $(ARCH)" \
  279. PKG_CONFIG_PATH=$(PWD)/$(ARCH)/lib/pkgconfig \
  280. )
  281. $(MAKE) -C $(DEST) -sj$(CPUS) check
  282. # Check that the resulting executable is Position-independent (PIE)
  283. otool -hv $(DEST)/src/aria2c | grep -q PIE
  284. $(MAKE) -C $(DEST) -sj$(CPUS) install-strip
  285. touch $@
  286. aria2.build: aria2.x86_64.build aria2.i686.build
  287. mkdir -p $(ARIA2_PREFIX)/bin
  288. # Got two binaries now. Merge them into one universal binary and remove
  289. # the old ones.
  290. lipo \
  291. -arch x86_64 $(ARIA2_PREFIX)/x86_64/aria2c \
  292. -arch i686 $(ARIA2_PREFIX)/i686/aria2c \
  293. -create -output $(ARIA2_PREFIX)/bin/aria2c
  294. rm -rf $(ARIA2_PREFIX)/x86_64 $(ARIA2_PREFIX)/i686
  295. # Basic sanity check
  296. arch -64 $(ARIA2_PREFIX)/bin/aria2c -v
  297. arch -32 $(ARIA2_PREFIX)/bin/aria2c -v
  298. touch $@
  299. $(ARIA2_CHANGELOG): aria2.build
  300. git log --pretty=fuller --date=short $(PREV_TAG)..HEAD > $@
  301. $(ARIA2_DOCS): aria2.build
  302. cp -av $(SRCDIR)/$(@F) $@
  303. $(ARIA2_DIST).tar.bz2: aria2.build $(ARIA2_DOCS) $(ARIA2_CHANGELOG)
  304. find $(ARIA2_PREFIX) -exec touch "{}" \;
  305. tar -cf $(ARIA2_DIST).tar.bz2 \
  306. --use-compress-program=bzip2 \
  307. --options='compression-level=9' \
  308. $(ARIA2)
  309. $(ARIA2_DIST).pkg: aria2.build $(ARIA2_DOCS) $(ARIA2_CHANGELOG)
  310. find $(ARIA2_PREFIX) -exec touch "{}" \;
  311. pkgbuild \
  312. --root $(ARIA2) \
  313. --identifier aria2 \
  314. --version $(VERSION) \
  315. --install-location /usr/local/aria2 \
  316. --ownership recommended \
  317. out.pkg
  318. pkgbuild \
  319. --root $(SRCDIR)/osx-package/etc \
  320. --identifier aria2.paths \
  321. --version $(VERSION) \
  322. --install-location /etc \
  323. --ownership recommended \
  324. paths.pkg
  325. echo "$$ARIA2_DISTXML" > dist.xml
  326. productbuild \
  327. --distribution dist.xml \
  328. --resources $(ARIA2_PREFIX)/share/doc/aria2 \
  329. $@
  330. rm -rf out.pkg paths.pkg dist.xml
  331. $(ARIA2_DIST).dmg: $(ARIA2_DIST).pkg
  332. -rm -rf dmg
  333. mkdir -p dmg/Docs
  334. cp -av $(ARIA2_DIST).pkg dmg/aria2.pkg
  335. find $(ARIA2_PREFIX)/share/doc/aria2 -type f -depth 1 -exec cp -av "{}" dmg/Docs \;
  336. rm -rf dmg/Docs/README dmg/Docs/README.rst
  337. cp $(SRCDIR)/osx-package/DS_Store dmg/.DS_Store
  338. hdiutil create $@.uncompressed \
  339. -srcfolder dmg \
  340. -volname "aria2 $(VERSION) Intel Universal" \
  341. -ov
  342. hdiutil convert -format UDBZ -o $@ $@.uncompressed.dmg
  343. hdiutil flatten $@
  344. rm -rf $@.uncompressed.dmg dmg
  345. dist.build: $(ARIA2_DIST).tar.bz2 $(ARIA2_DIST).pkg $(ARIA2_DIST).dmg
  346. echo 'Build success: $(ARIA2_DIST)'
  347. touch $@
  348. all:: dist.build
  349. clean-dist:
  350. rm -rf $(ARIA2_DIST).tar.bz2 $(ARIA2_DIST).pkg $(ARIA2_DIST).dmg
  351. clean: clean-dist
  352. rm -rf *aria2*
  353. cleaner: clean
  354. rm -rf *.build *.check *.stamp $(ARCHLIBS) $(NONARCHLIBS) *x86_64* *i686*
  355. really-clean: cleaner
  356. rm -rf *.tar.*
  357. .PHONY: all clean-dist clean cleaner really-clean