1 # Makefile to auto build tarball's with patches etc
2 # see Documentation/automake.txt for more info on using this file
3 # Copyright (C) 2009 David McCullough <davidm@uclinux.org>
13 # You can override the downloads cache dir in case you would prefer
14 # have all the files in tree or elsewhere. The default is ~/.downloads
17 UC_DOWNLOADS = $(HOME)/.downloads
21 # these config options apply to all things we build
24 ifdef CONFIG_USER_FLATFSD_FLATFSD
25 ifeq ($(findstring --sysconfdir,$(CONFOPTS)),)
26 CONFOPTS += --sysconfdir=/etc/config
30 CONFOPTS += --with-vendor-name=$(CONFIG_VENDOR)
31 CONFOPTS += --with-vendor-name-short=$(CONFIG_VENDOR)
32 CONFOPTS += --with-os-name=uClinux-dist
33 CONFOPTS += --with-os-vendor=uClinux
34 CONFOPTS += --disable-static
37 # for uClibc without glibc compat
39 CONFOPTS += --enable-malloc0returnsnull
42 # make sure LD does the right thing during configure if invoked directly
44 LDFLAGS += -Wl,-L$(STAGEDIR)/lib -Wl,-rpath-link -Wl,$(STAGEDIR)/lib
45 LDFLAGS += -Wl,-L$(STAGEDIR)/lib64 -Wl,-rpath-link -Wl,$(STAGEDIR)/lib64
48 # where our pkgconfig stuff will go
50 PKG_CONFIG_PATH = $(STAGEDIR)/lib/pkgconfig:$(STAGEDIR)/lib:$(STAGEDIR)/share/pkgconfig
51 PKG_CONFIG_LIBDIR = $(STAGEDIR)/lib/pkgconfig
54 # its generally a bad idea to fail on linker warnings for packages we
55 # aren't fully controlling, though we could put this back conditionally
57 LDFLAGS := $(LDFLAGS:-Wl,--fatal-warnings=)
62 HOST_RANLIB = $(shell which ranlib || echo :)
65 # we use wget to download
72 # force using our special libtool
74 MAKEVARS ?= LIBTOOL="$(LIBTOOL)"
77 # remap directories in a build to ensure that only uClinux-dist files
80 UCFRONT_MAPDIRS = /lib/=$(STAGEDIR)/lib/
81 UCFRONT_MAPDIRS += /include/=$(STAGEDIR)/include/
82 ifneq ($(STAGEDIR),$(ROOTDIR))
83 UCFRONT_MAPDIRS += /usr/include=$(STAGEDIR)/usr/include
84 UCFRONT_MAPDIRS += /usr/lib=$(STAGEDIR)/usr/lib
86 UCFRONT_MAPDIRS += /usr/include=$(STAGEDIR)/include
87 UCFRONT_MAPDIRS += /usr/lib=$(STAGEDIR)/lib
91 # some short cut config, just set URL = blah
92 # and we work the rest out
94 ifeq ($(AUTOMAKE_y)$(AUTOMAKE_n)$(AUTOMAKE_),)
97 PKG := $(shell basename $(URL))
98 PKG := $(PKG:.tar.gz=)
99 PKG := $(PKG:.tar.bz2=)
100 PKG := $(PKG:.tar.xz=)
113 $(1)_METHOD ?= $(METHOD)
114 $(1)_INSTALL ?= $(if $(INSTALL),$(INSTALL),install)
115 $(1)_NODEFCONF ?= $(NODEFCONF)
116 $(1)_AUTOCONF ?= $(AUTOCONF)
117 $(1)_VERSION ?= $(VERSION)
118 $(1)_SUBDIR ?= $(SUBDIR)
119 $(1)_ROMFS ?= $(ROMFS)
120 $(1)_CONFIGURE ?= $(if $(CONFIGURE),$(CONFIGURE),configure)
121 $(1)_BUILDDIR ?= $(if $(BUILDDIR),$(BUILDDIR),$(1))
122 $(1)_SRCDIR ?= $(if $(SRCDIR),$(SRCDIR),$$($(1)_BUILDDIR))
123 $(1)_DOWNLOADNAME ?= $(if $(DOWNLOADNAME),$(DOWNLOADNAME),$$(shell basename "$$($(1)_URL)"))
125 $(foreach pkg,$(AUTOMAKE_y),$(eval $(call pkg_def,$(pkg))))
127 # put arguments on their own line
133 # allow some targets to be overridden
136 INSTALLTARGET ?= installed
138 COMPLETETARGET ?= complete_target
143 all: $(foreach pkg,$(AUTOMAKE_y),build/$(pkg)-$(FINALTARGET)) $(COMPLETETARGET)
145 .PHONY: $(COMPLETETARGET)
146 $(COMPLETETARGET): $(foreach pkg,$(AUTOMAKE_y),build/$(pkg)-$(FINALTARGET))
151 .PRECIOUS: $(addprefix build/,$(addsuffix -extracted,$(AUTOMAKE_y)))
152 .PRECIOUS: $(addprefix build/,$(addsuffix -autoconf,$(AUTOMAKE_y)))
153 .PRECIOUS: $(addprefix build/,$(addsuffix -configured,$(AUTOMAKE_y)))
154 .PRECIOUS: $(addprefix build/,$(addsuffix -built,$(AUTOMAKE_y)))
155 .PRECIOUS: $(addprefix build/,$(addsuffix -installed,$(AUTOMAKE_y)))
156 .PRECIOUS: $(addprefix build/,$(addsuffix -patched,$(AUTOMAKE_y)))
157 .PRECIOUS: $(addprefix build/,$(addsuffix -$(BUILDTARGET),$(AUTOMAKE_y)))
158 .PRECIOUS: $(addprefix build/,$(addsuffix -$(INSTALLTARGET),$(AUTOMAKE_y)))
161 # download support for tarballs and the like from a URL
163 define download_dep_default
165 .PRECIOUS: downloads/$$($(1)_DOWNLOADNAME)
166 downloads/$$($(1)_DOWNLOADNAME):
167 @echo "Downloading $$($(1)_DOWNLOADNAME) from $($(1)_URL) ..."
168 $(AT)[ -d "$(UC_DOWNLOADS)" ] || mkdir -p "$(UC_DOWNLOADS)"
169 $(AT)if [ ! -f "$(UC_DOWNLOADS)/`basename $$@`" ]; then \
170 cd "$(UC_DOWNLOADS)"; $(WGET) -O `basename $$@` "$($(1)_URL)"; \
172 $(AT)mkdir -p `dirname $$@`
173 $(AT)if [ -f "$(UC_DOWNLOADS)/`basename $$@`" ]; then \
174 ln -fs "$(UC_DOWNLOADS)/`basename $$@`" $$@; \
176 $(AT)if [ ! -f "$$@" ]; then \
177 echo "Cannot find download for $$@" >&2 ; \
181 build/$(1)-extracted: downloads/$($(1)_DOWNLOADNAME)
182 @echo "Extracting $$< ..."
183 $(AT)rm -rf build/$($(1)_SRCDIR)
186 *zip) rm -rf build/$(1); mkdir -p build/$(1); pkg=`pwd`/$$<; (cd build/$(1); unzip $$$$pkg);; \
187 *bz2) bunzip2 < $$< | (cd build; tar xf -);; \
188 *xz) unxz < $$< | (cd build; tar xf -);; \
189 *) gunzip < $$< | (cd build; tar xf -);; \
196 # Support for remote GIT subdirectories of sorts, we do not remember master
197 # downloads as they change from load to load so just save it until the next
198 # clean. The clone will save us downloading it all again.
200 define download_dep_gitarchive
202 .PRECIOUS: downloads/$(1)$(if $($(1)_VERSION),-$($(1)_VERSION)).tar
203 downloads/$(1)$(if $($(1)_VERSION),-$($(1)_VERSION)).tar:
204 @echo "Downloading `basename $$@` ..."
205 $(AT)[ -d "$(UC_DOWNLOADS)" ] || mkdir -p "$(UC_DOWNLOADS)"
206 $(AT)if [ ! -f "$(UC_DOWNLOADS)/`basename $$@`" ]; then \
207 echo "Updating/Cloning `basename $$($(1)_URL)` for archive ..."; \
208 if [ -d "archive/`basename $$($(1)_URL)`" ]; then \
210 cd "archive/`basename $$($(1)_URL)`"; \
211 $(GIT) checkout -q master || exit 1; \
212 $(GIT) pull || exit 1; \
213 $(GIT) checkout -q $(if $($(1)_VERSION),$($(1)_VERSION),master) || exit 1; \
216 $(GIT) clone $$($(1)_URL) archive/`basename $$($(1)_URL)` || exit 1; \
218 cd "archive/`basename $$($(1)_URL)`"; \
219 $(GIT) checkout -q $(if $($(1)_VERSION),$($(1)_VERSION),master) || exit 1; \
222 cd archive/`basename $$($(1)_URL)`; \
223 $(GIT) archive -o $(UC_DOWNLOADS)/`basename $$@` HEAD:$(if $($(1)_SUBDIR),$($(1)_SUBDIR)/,) || exit 1; \
225 $(AT)mkdir -p `dirname $$@`
226 $(AT)if [ "$(if $($(1)_VERSION),$($(1)_VERSION),master)" = "master" ]; then \
227 mv -f "$(UC_DOWNLOADS)/`basename $$@`" $$@ || exit 1; \
228 elif [ -f "$(UC_DOWNLOADS)/`basename $$@`" ]; then \
229 ln -fs "$(UC_DOWNLOADS)/`basename $$@`" $$@; \
231 $(AT)if [ ! -f "$$@" ]; then \
232 echo "Cannot find download for $$@" >&2 ; \
236 build/$(1)-extracted: downloads/$(1)$(if $($(1)_VERSION),-$($(1)_VERSION)).tar
237 @echo "Extracting $$< ..."
238 $(AT)rm -rf build/$(1)
239 $(AT)mkdir -p build/$(1)
240 $(AT)cat < $$< | (cd build/$(1); tar xf -); exit $?
246 # Support for remote GIT repos
248 define download_dep_git
250 build/$(1)-extracted:
251 @echo "Cloning $(1) ..."
253 $(AT)if [ -d "clone/$(1)" ]; then \
255 $(GIT) checkout -q master; \
256 $(GIT) pull || exit 1; \
258 $(GIT) clone $$($(1)_URL) clone/$(1) || exit 1; \
260 $(AT)cd "clone/$(1)" && $(GIT) checkout -q $(if $($(1)_VERSION),$($(1)_VERSION),master)
261 $(AT)rm -rf build/$(1)
262 $(AT)mkdir -p build/$(1)
263 $(AT)lndir -silent `pwd`/clone/$(1) build/$(1)
268 $(foreach pkg,$(AUTOMAKE_y),$(eval $(call download_dep_$($(pkg)_METHOD),$(pkg))))
270 $(foreach pkg,$(AUTOMAKE_y), $(eval $(call oneline,build/$(pkg)-extracted: $(wildcard patches/series patches/$(pkg)*.patch) $(MAKEFILE_LIST))))
272 build/%-patched: build/%-extracted
273 $(AT)if [ -f patches/series ]; then \
275 [ -f patches/$$t ] || continue; \
276 echo "Patching $* with patches/$$t from series"; \
278 *.gz) (cd build/$($*_SRCDIR); gunzip | patch -E -p1) < patches/$$t || exit 1;; \
279 *) (cd build/$($*_SRCDIR); patch -E -p1) < patches/$$t || exit 1;; \
281 done < patches/series || exit 1; \
283 for t in patches/$**.patch*; do \
284 [ -f "$$t" ] || continue; \
285 echo "Patching $* with $$t"; \
287 *.gz) (cd build/$($*_SRCDIR); gunzip | patch -E -p1) < $$t || exit 1 ;; \
288 *) (cd build/$($*_SRCDIR); patch -E -p1) < $$t || exit 1;; \
294 build/%-autoconf: build/%-patched
295 @echo "Autoconf $* ..."
296 $(if $($*_AUTOCONF),cd build/$($*_SRCDIR); $($*_AUTOCONF))
299 build/%-configured: build/%-autoconf
300 @echo "Configure $* ..."
301 $(AT)mkdir -p build/$($*_BUILDDIR)
302 $(AT)cd build/$($*_BUILDDIR); \
303 if [ -f $($*_CONFIGURE) ]; then \
306 CFLAGS="$(CFLAGS) $($*_CFLAGS)" \
307 bash $($*_CONFIGURE) $(if $($*_NODEFCONF),,$(CONFIGURE_OPTS) $(CONFOPTS)) $($*_CONFOPTS); \
311 build/%-built: build/%-configured
312 @echo "Building $* ..."
315 $(MAKE) -C build/$($*_BUILDDIR) $(MAKEVARS) $($*_MAKEVARS)
318 build/%-installed: build/%-$(BUILDTARGET)
319 @echo "Installing $* ..."
320 $(AT)mkdir -p build/$*-install
324 $(MAKE) -C build/$($*_BUILDDIR) $($*_INSTALL) DESTDIR=`pwd`/build/$*-install $(MAKEVARS) $($*_MAKEVARS)
327 build/%-lndir: build/%-$(INSTALLTARGET) force_target
328 @echo "Staging $* ..."
329 $(AT)mkdir -p build/$*-install
330 $(AT)cd build/$*-install; find . \( -type f -o -type l \) | egrep -v '.la$$' | \
333 ./bin/*) continue;; \
334 ./sbin/*) continue;; \
336 rm -f $(STAGEDIR)/$$t; \
337 mkdir -p "`dirname \"$(STAGEDIR)/$$t\"`"; \
338 ln -s "`pwd`/$$t" "$(STAGEDIR)/$$t"; \
339 echo "ln -s \"`pwd`/$$t\" \"$(STAGEDIR)/$$t\""; \
343 clean: $(foreach pkg,$(AUTOMAKE_y),$($(pkg)_CLEAN))
344 rm -rf build downloads
347 @echo "Romfs pre-install ..."
348 $(AT)for i in build/*-install; do \
349 echo "Installing `basename $$i -install` ..."; \
350 [ ! -d $$i/usr ] || $(ROMFSINST) -v -f $$i/usr /usr; \
351 [ ! -d $$i/bin ] || $(ROMFSINST) -v -f $$i/bin /bin; \
352 [ ! -d $$i/sbin ] || $(ROMFSINST) -v -f $$i/sbin /sbin; \
353 [ ! -d $$i/lib ] || $(ROMFSINST) -v -f $$i/lib /lib; \
354 [ ! -d $$i/lib64 ] || $(ROMFSINST) -v -f $$i/lib64 /lib; \
355 [ ! -d $$i/libexec ] || $(ROMFSINST) -v -f $$i/libexec /libexec; \
356 rm -rf $$i/etc/default; \
357 [ ! -d $$i/etc/config ] || mv $$i/etc/config $$i/etc/default; \
358 [ ! -d $$i/etc ] || $(ROMFSINST) -v -f $$i/etc /etc; \
359 [ ! -d $$i/share ] || $(ROMFSINST) -v -f $$i/share /share; \
361 rm -f $(ROMFSDIR)/lib/*.a
362 rm -f $(ROMFSDIR)/lib/*.la
364 romfs_post: $(foreach pkg,$(AUTOMAKE_y),$($(pkg)_ROMFS))
366 romfs: $(if $(AUTOMAKE_ROMFS),$(AUTOMAKE_ROMFS),romfs_pre) romfs_post