makerelease-osx.mk 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. gmp_confflags_x86_64 = --enable-fat
  113. cppunit_version = 1.12.1
  114. cppunit_hash = f1ab8986af7a1ffa6760f4bacf5622924639bf4a
  115. cppunit_url = http://sourceforge.net/projects/cppunit/files/cppunit/$(cppunit_version)/cppunit-$(cppunit_version).tar.gz
  116. # ARCHLIBS that can be template build
  117. ARCHLIBS = expat cares sqlite gmp cppunit
  118. # NONARCHLIBS that cannot be template build
  119. NONARCHLIBS = zlib
  120. # Tags
  121. THIS_TAG := $(shell git describe --abbrev=0 $$(git rev-list --tags --max-count=1))
  122. PREV_TAG := $(shell git describe --abbrev=0 $(THIS_TAG)~1)
  123. # Aria2 setup
  124. ARIA2 := aria2-$(VERSION)
  125. ARIA2_PREFIX := $(PWD)/$(ARIA2)
  126. ARIA2_DIST := $(PWD)/$(ARIA2)-osx-darwin
  127. ARIA2_CONFFLAGS = \
  128. --enable-static \
  129. --disable-shared \
  130. --enable-metalink \
  131. --enable-bittorrent \
  132. --disable-nls \
  133. --with-appletls \
  134. --with-libgmp \
  135. --with-sqlite3 \
  136. --with-libz \
  137. --with-libexpat \
  138. --with-libcares \
  139. --without-libuv \
  140. --without-gnutls \
  141. --without-openssl \
  142. --without-libnettle \
  143. --without-libgcrypt \
  144. --without-libxml2 \
  145. ARIA2_STATIC=yes
  146. ARIA2_DOCDIR = $(ARIA2_PREFIX)/share/doc/aria2
  147. ARIA2_DOCS = \
  148. $(ARIA2_DOCDIR)/AUTHORS \
  149. $(ARIA2_DOCDIR)/COPYING \
  150. $(ARIA2_DOCDIR)/NEWS
  151. ARIA2_CHANGELOG = $(ARIA2_DOCDIR)/Changelog
  152. # Yeah, inlined XML, go figure :p
  153. define ARIA2_DISTXML
  154. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  155. <installer-gui-script minSpecVersion="1">
  156. <title>aria1 $(VERSION)</title>
  157. <welcome file="README.html"/>
  158. <pkg-ref id="aria2"/>
  159. <pkg-ref id="aria2.paths"/>
  160. <options customize="never" require-scripts="false" rootVolumeOnly="true"/>
  161. <volume-check>
  162. <allowed-os-versions>
  163. <os-version min="10.7"/>
  164. </allowed-os-versions>
  165. </volume-check>
  166. <domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/>
  167. <choices-outline>
  168. <line choice="default">
  169. <line choice="aria2"/>
  170. <line choice="aria2.paths"/>
  171. </line>
  172. </choices-outline>
  173. <choice id="default"/>
  174. <choice id="aria2" visible="false">
  175. <pkg-ref id="aria2"/>
  176. </choice>
  177. <choice id="aria2.paths" visible="false">
  178. <pkg-ref id="aria2.paths"/>
  179. </choice>
  180. <pkg-ref id="aria2" version="$(VERSION)" onConclusion="none">out.pkg</pkg-ref>
  181. <pkg-ref id="aria2.paths" version="$(VERSION)" onConclusion="none">paths.pkg</pkg-ref>
  182. </installer-gui-script>
  183. endef
  184. export ARIA2_DISTXML
  185. # Detect numer of CPUs to be used with make -j
  186. CPUS = $(shell sysctl hw.ncpu | cut -d" " -f2)
  187. # default target
  188. all::
  189. @if test "x$(NON_RELEASE)" = "x" && !(git describe --tags --exact); then \
  190. echo 'Not on a release tag; override by defining NON_RELEASE!'; \
  191. exit 1; \
  192. fi
  193. # No dice without sphinx
  194. all::
  195. @if test "x$$(which sphinx-build)" = "x"; then \
  196. echo "sphinx-build not present"; \
  197. exit 1; \
  198. fi;
  199. deps::
  200. # All those .PRECIOUS files, because otherwise gmake will treat them as
  201. # intermediates and remove them when the build completes. Thanks gmake!
  202. .PRECIOUS: %.tar.gz
  203. %.tar.gz:
  204. curl -o $@ -A 'curl/0; like wget' -L \
  205. $($(basename $(basename $@))_url)
  206. .PRECIOUS: %.check
  207. %.check: %.tar.gz
  208. @if test "$$(shasum -a1 $< | awk '{print $$1}')" != "$($(basename $@)_hash)"; then \
  209. echo "Invalid $@ hash"; \
  210. rm -f $<; \
  211. exit 1; \
  212. fi;
  213. touch $@
  214. .PRECIOUS: %.stamp
  215. %.stamp: %.tar.gz %.check
  216. tar xf $<
  217. mv $(basename $@)-$($(basename $@)_version) $(basename $@)
  218. touch $@
  219. .PRECIOUS: cares.stamp
  220. cares.stamp: cares.tar.gz cares.check
  221. tar xzf $<
  222. mv c-ares-$($(basename $@)_version) $(basename $@)
  223. touch $@
  224. # Using (NON)ARCH_template kinda stinks, but real multi-target pattern rules
  225. # only exist in feverish dreams.
  226. define NONARCH_template
  227. $(1).build: $(1).x86_64.build $(1).i686.build
  228. deps:: $(1).build
  229. endef
  230. .PRECIOUS: zlib.%.build
  231. zlib.%.build: zlib.stamp
  232. $(eval BASE := $(basename $<))
  233. $(eval DEST := $(basename $@))
  234. $(eval ARCH := $(subst .,,$(suffix $(DEST))))
  235. rsync -a $(BASE)/ $(DEST)
  236. ( cd $(DEST) && ./configure \
  237. --static --prefix=$(PWD)/$(ARCH) \
  238. )
  239. $(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) -arch $(ARCH)"
  240. $(MAKE) -C $(DEST) -sj$(CPUS) CFLAGS="$(CFLAGS) -arch $(ARCH)" check
  241. $(MAKE) -C $(DEST) -s install
  242. touch $@
  243. $(foreach lib,$(NONARCHLIBS),$(eval $(call NONARCH_template,$(lib))))
  244. define ARCH_template
  245. .PRECIOUS: $(1).%.build
  246. $(1).%.build: $(1).stamp
  247. $$(eval DEST := $$(basename $$@))
  248. $$(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
  249. mkdir -p $$(DEST)
  250. ( cd $$(DEST) && ../$(1)/configure \
  251. --host=$$(ARCH)-apple-darwin11.4.2 \
  252. --build=$$(ARCH)-apple-darwin11.4.2 \
  253. --enable-static --disable-shared \
  254. --prefix=$$(PWD)/$$(ARCH) \
  255. $$($(1)_confflags) $$($(1)_confflags_$$(ARCH)) \
  256. CFLAGS="$$(CFLAGS) -arch $$(ARCH)" \
  257. CXXFLAGS="$$(CXXFLAGS) -arch $$(ARCH) -stdlib=libc++ -std=c++11" \
  258. )
  259. $$(MAKE) -C $$(DEST) -sj$(CPUS)
  260. $$(MAKE) -C $$(DEST) -sj$(CPUS) check
  261. $$(MAKE) -C $$(DEST) -s install
  262. touch $$@
  263. $(1).build: $(1).x86_64.build $(1).i686.build
  264. deps:: $(1).build
  265. endef
  266. $(foreach lib,$(ARCHLIBS),$(eval $(call ARCH_template,$(lib))))
  267. .PRECIOUS: aria2.%.build
  268. aria2.%.build: zlib.%.build expat.%.build gmp.%.build cares.%.build sqlite.%.build cppunit.%.build
  269. $(eval DEST := $$(basename $$@))
  270. $(eval ARCH := $$(subst .,,$$(suffix $$(DEST))))
  271. mkdir -p $(DEST)
  272. ( cd $(DEST) && ../$(SRCDIR)/configure \
  273. --prefix=$(ARIA2_PREFIX) \
  274. --bindir=$(ARIA2_PREFIX)/$(ARCH) \
  275. --sysconfdir=/etc \
  276. --with-cppunit-prefix=$(PWD)/$(ARCH) \
  277. $(ARIA2_CONFFLAGS) \
  278. CFLAGS="$(CFLAGS) -arch $(ARCH) -I$(PWD)/$(ARCH)/include" \
  279. CXXFLAGS="$(CXXFLAGS) -arch $(ARCH) -I$(PWD)/$(ARCH)/include" \
  280. LDFLAGS="$(LDFLAGS) -L$(PWD)/$(ARCH)/lib" \
  281. PKG_CONFIG_PATH=$(PWD)/$(ARCH)/lib/pkgconfig \
  282. )
  283. $(MAKE) -C $(DEST) -sj$(CPUS) check
  284. # Check that the resulting executable is Position-independent (PIE)
  285. otool -hv $(DEST)/src/aria2c | grep -q PIE
  286. $(MAKE) -C $(DEST) -sj$(CPUS) install-strip
  287. touch $@
  288. aria2.build: aria2.x86_64.build aria2.i686.build
  289. mkdir -p $(ARIA2_PREFIX)/bin
  290. # Got two binaries now. Merge them into one universal binary and remove
  291. # the old ones.
  292. lipo \
  293. -arch x86_64 $(ARIA2_PREFIX)/x86_64/aria2c \
  294. -arch i686 $(ARIA2_PREFIX)/i686/aria2c \
  295. -create -output $(ARIA2_PREFIX)/bin/aria2c
  296. rm -rf $(ARIA2_PREFIX)/x86_64 $(ARIA2_PREFIX)/i686
  297. # Basic sanity check
  298. arch -64 $(ARIA2_PREFIX)/bin/aria2c -v
  299. arch -32 $(ARIA2_PREFIX)/bin/aria2c -v
  300. touch $@
  301. $(ARIA2_CHANGELOG): aria2.build
  302. git log --pretty=fuller --date=short $(PREV_TAG)..HEAD > $@
  303. $(ARIA2_DOCS): aria2.build
  304. cp -av $(SRCDIR)/$(@F) $@
  305. $(ARIA2_DIST).tar.bz2: aria2.build $(ARIA2_DOCS) $(ARIA2_CHANGELOG)
  306. find $(ARIA2_PREFIX) -exec touch "{}" \;
  307. tar -cf $(ARIA2_DIST).tar.bz2 \
  308. --use-compress-program=bzip2 \
  309. --options='compression-level=9' \
  310. $(ARIA2)
  311. $(ARIA2_DIST).pkg: aria2.build $(ARIA2_DOCS) $(ARIA2_CHANGELOG)
  312. find $(ARIA2_PREFIX) -exec touch "{}" \;
  313. pkgbuild \
  314. --root $(ARIA2) \
  315. --identifier aria2 \
  316. --version $(VERSION) \
  317. --install-location /usr/local/aria2 \
  318. --ownership recommended \
  319. out.pkg
  320. pkgbuild \
  321. --root $(SRCDIR)/osx-package/etc \
  322. --identifier aria2.paths \
  323. --version $(VERSION) \
  324. --install-location /etc \
  325. --ownership recommended \
  326. paths.pkg
  327. echo "$$ARIA2_DISTXML" > dist.xml
  328. productbuild \
  329. --distribution dist.xml \
  330. --resources $(ARIA2_PREFIX)/share/doc/aria2 \
  331. $@
  332. rm -rf out.pkg paths.pkg dist.xml
  333. $(ARIA2_DIST).dmg: $(ARIA2_DIST).pkg
  334. -rm -rf dmg
  335. mkdir -p dmg/Docs
  336. cp -av $(ARIA2_DIST).pkg dmg/aria2.pkg
  337. find $(ARIA2_PREFIX)/share/doc/aria2 -type f -depth 1 -exec cp -av "{}" dmg/Docs \;
  338. rm -rf dmg/Docs/README dmg/Docs/README.rst
  339. cp $(SRCDIR)/osx-package/DS_Store dmg/.DS_Store
  340. hdiutil create $@.uncompressed \
  341. -srcfolder dmg \
  342. -volname "aria2 $(VERSION) Intel Universal" \
  343. -ov
  344. hdiutil convert -format UDBZ -o $@ $@.uncompressed.dmg
  345. hdiutil flatten $@
  346. rm -rf $@.uncompressed.dmg dmg
  347. dist.build: $(ARIA2_DIST).tar.bz2 $(ARIA2_DIST).pkg $(ARIA2_DIST).dmg
  348. echo 'Build success: $(ARIA2_DIST)'
  349. touch $@
  350. all:: dist.build
  351. clean-dist:
  352. rm -rf $(ARIA2_DIST).tar.bz2 $(ARIA2_DIST).pkg $(ARIA2_DIST).dmg
  353. clean: clean-dist
  354. rm -rf *aria2*
  355. cleaner: clean
  356. rm -rf *.build *.check *.stamp $(ARCHLIBS) $(NONARCHLIBS) *x86_64* *i686*
  357. really-clean: cleaner
  358. rm -rf *.tar.*
  359. .PHONY: all clean-dist clean cleaner really-clean