OSDN Git Service

Add MS7619SE
[uclinux-h8/uClinux-dist.git] / tools / automake.inc
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>
4
5 .EXPORT_ALL_VARIABLES:
6
7 AT := $(if $(V:0=),,@)
8 ifndef STAGEDIR
9 STAGEDIR = $(ROOTDIR)
10 endif
11
12 #
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
15 #
16 ifndef UC_DOWNLOADS
17 UC_DOWNLOADS = $(HOME)/.downloads
18 endif
19
20 #
21 # these config options apply to all things we build
22 #
23 CONFOPTS += --prefix=
24 ifdef CONFIG_USER_FLATFSD_FLATFSD
25 ifeq ($(findstring --sysconfdir,$(CONFOPTS)),)
26   CONFOPTS += --sysconfdir=/etc/config
27 endif
28 endif
29
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
35
36 #
37 # for uClibc without glibc compat
38 #
39 CONFOPTS += --enable-malloc0returnsnull
40
41 #
42 # make sure LD does the right thing during configure if invoked directly
43 #
44 LDFLAGS  += -Wl,-L$(STAGEDIR)/lib -Wl,-rpath-link -Wl,$(STAGEDIR)/lib
45 LDFLAGS  += -Wl,-L$(STAGEDIR)/lib64 -Wl,-rpath-link -Wl,$(STAGEDIR)/lib64
46
47 #
48 # where our pkgconfig stuff will go
49 #
50 PKG_CONFIG_PATH   = $(STAGEDIR)/lib/pkgconfig:$(STAGEDIR)/lib:$(STAGEDIR)/share/pkgconfig
51 PKG_CONFIG_LIBDIR = $(STAGEDIR)/lib/pkgconfig
52
53 #
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
56 #
57 LDFLAGS := $(LDFLAGS:-Wl,--fatal-warnings=)
58
59 BUILD_CC = $(HOSTCC)
60 HOST_CC      = gcc
61 HOST_CXX     = g++
62 HOST_RANLIB  = $(shell which ranlib || echo :)
63
64 #
65 # we use wget to download
66 #
67 WGET ?= wget
68 GIT ?= git
69 METHOD ?= default
70
71 #
72 # force using our special libtool
73 #
74 MAKEVARS     ?= LIBTOOL="$(LIBTOOL)"
75
76 #
77 # remap directories in a build to ensure that only uClinux-dist files
78 # are used
79 #
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
85 else
86 UCFRONT_MAPDIRS += /usr/include=$(STAGEDIR)/include
87 UCFRONT_MAPDIRS += /usr/lib=$(STAGEDIR)/lib
88 endif
89
90 #
91 # some short cut config,  just set URL = blah
92 # and we work the rest out
93 #
94 ifeq ($(AUTOMAKE_y)$(AUTOMAKE_n)$(AUTOMAKE_),)
95   ifdef URL
96     ifndef PKG
97       PKG := $(shell basename $(URL))
98       PKG := $(PKG:.tar.gz=)
99       PKG := $(PKG:.tar.bz2=)
100       PKG := $(PKG:.tar.xz=)
101       PKG := $(PKG:.tgz=)
102       PKG := $(PKG:.tbz2=)
103       PKG := $(PKG:.txz=)
104       PKG := $(PKG:.zip=)
105       PKG := $(PKG:.git=)
106     endif
107     AUTOMAKE_y += $(PKG)
108   endif
109 endif
110
111 define pkg_def
112   $(1)_URL ?= $(URL)
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)"))
124 endef
125 $(foreach pkg,$(AUTOMAKE_y),$(eval $(call pkg_def,$(pkg))))
126
127 # put arguments on their own line
128 define oneline
129 $(1)
130 endef
131
132 #
133 # allow some targets to be overridden
134 #
135 BUILDTARGET ?= built
136 INSTALLTARGET ?= installed
137 FINALTARGET ?= lndir
138 COMPLETETARGET ?= complete_target
139
140 #
141 # the main target
142 #
143 all: $(foreach pkg,$(AUTOMAKE_y),build/$(pkg)-$(FINALTARGET)) $(COMPLETETARGET)
144
145 .PHONY: $(COMPLETETARGET)
146 $(COMPLETETARGET): $(foreach pkg,$(AUTOMAKE_y),build/$(pkg)-$(FINALTARGET))
147
148 .PHONY: force_target
149 force_target:
150
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)))
159
160 #
161 # download support for tarballs and the like from a URL
162 #
163 define download_dep_default
164
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)"; \
171         fi
172         $(AT)mkdir -p `dirname $$@`
173         $(AT)if [ -f "$(UC_DOWNLOADS)/`basename $$@`" ]; then \
174                         ln -fs "$(UC_DOWNLOADS)/`basename $$@`" $$@; \
175         fi
176         $(AT)if [ ! -f "$$@" ]; then \
177                 echo "Cannot find download for $$@" >&2 ; \
178                 exit 1; \
179         fi
180
181 build/$(1)-extracted: downloads/$($(1)_DOWNLOADNAME)
182         @echo "Extracting $$< ..."
183         $(AT)rm -rf build/$($(1)_SRCDIR)
184         $(AT)mkdir -p build
185         $(AT)case "$$<" in \
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 -);; \
190         esac || exit 1
191         $(AT)touch $$@
192
193 endef
194
195 #
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.
199 #
200 define download_dep_gitarchive
201
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 \
209                         (\
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; \
214                         ) || exit 1; \
215                 else \
216                         $(GIT) clone $$($(1)_URL) archive/`basename $$($(1)_URL)` || exit 1; \
217                         (\
218                         cd "archive/`basename $$($(1)_URL)`"; \
219                         $(GIT) checkout -q $(if $($(1)_VERSION),$($(1)_VERSION),master) || exit 1; \
220                         ) || exit 1; \
221                 fi ; \
222                 cd archive/`basename $$($(1)_URL)`; \
223                         $(GIT) archive -o $(UC_DOWNLOADS)/`basename $$@` HEAD:$(if $($(1)_SUBDIR),$($(1)_SUBDIR)/,) || exit 1; \
224         fi
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 $$@`" $$@; \
230         fi
231         $(AT)if [ ! -f "$$@" ]; then \
232                 echo "Cannot find download for $$@" >&2 ; \
233                 exit 1; \
234         fi
235
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 $?
241         $(AT)touch $$@
242
243 endef
244
245 #
246 # Support for remote GIT repos
247 #
248 define download_dep_git
249
250 build/$(1)-extracted:
251         @echo "Cloning $(1) ..."
252         $(AT)mkdir -p clone
253         $(AT)if [ -d "clone/$(1)" ]; then \
254                 cd "clone/$(1)"; \
255                 $(GIT) checkout -q master; \
256                 $(GIT) pull || exit 1; \
257         else \
258                 $(GIT) clone $$($(1)_URL) clone/$(1) || exit 1; \
259         fi
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)
264         $(AT)touch $$@
265
266 endef
267
268 $(foreach pkg,$(AUTOMAKE_y),$(eval $(call download_dep_$($(pkg)_METHOD),$(pkg))))
269
270 $(foreach pkg,$(AUTOMAKE_y), $(eval $(call oneline,build/$(pkg)-extracted: $(wildcard patches/series patches/$(pkg)*.patch) $(MAKEFILE_LIST))))
271
272 build/%-patched: build/%-extracted
273         $(AT)if [ -f patches/series ]; then \
274                 while read t; do \
275                         [ -f patches/$$t ] || continue; \
276                         echo "Patching $* with patches/$$t from series"; \
277                         case "$$t" in \
278                         *.gz) (cd build/$($*_SRCDIR); gunzip | patch -E -p1) < patches/$$t || exit 1;; \
279                         *)    (cd build/$($*_SRCDIR); patch -E -p1) < patches/$$t || exit 1;; \
280                         esac || exit 1; \
281                 done < patches/series || exit 1; \
282         else \
283                 for t in patches/$**.patch*; do \
284                         [ -f "$$t" ] || continue; \
285                         echo "Patching $* with $$t"; \
286                         case "$$t" in \
287                         *.gz) (cd build/$($*_SRCDIR); gunzip | patch -E -p1) < $$t || exit 1 ;; \
288                         *)    (cd build/$($*_SRCDIR); patch -E -p1) < $$t || exit 1;; \
289                         esac || exit 1; \
290                 done || exit 1; \
291         fi
292         $(AT)touch $@
293
294 build/%-autoconf: build/%-patched
295         @echo "Autoconf $* ..."
296         $(if $($*_AUTOCONF),cd build/$($*_SRCDIR); $($*_AUTOCONF))
297         $(AT)touch $@
298
299 build/%-configured: build/%-autoconf
300         @echo "Configure $* ..."
301         $(AT)mkdir -p build/$($*_BUILDDIR)
302         $(AT)cd build/$($*_BUILDDIR); \
303                 if [ -f $($*_CONFIGURE) ]; then \
304                         $(CONFVARS) \
305                         $($*_CONFVARS) \
306                         CFLAGS="$(CFLAGS) $($*_CFLAGS)" \
307                         bash $($*_CONFIGURE) $(if $($*_NODEFCONF),,$(CONFIGURE_OPTS) $(CONFOPTS)) $($*_CONFOPTS); \
308                 fi
309         $(AT)touch $@
310
311 build/%-built: build/%-configured
312         @echo "Building $* ..."
313         $(AT)$(BUILDVARS) \
314         $($*_BUILDVARS) \
315                 $(MAKE) -C build/$($*_BUILDDIR) $(MAKEVARS) $($*_MAKEVARS)
316         $(AT)touch $@
317
318 build/%-installed: build/%-$(BUILDTARGET)
319         @echo "Installing $* ..."
320         $(AT)mkdir -p build/$*-install
321         $(AT)$(BUILDVARS) \
322         $($*_BUILDVARS) \
323         $($*_INSTALLVARS) \
324                 $(MAKE) -C build/$($*_BUILDDIR) $($*_INSTALL) DESTDIR=`pwd`/build/$*-install $(MAKEVARS) $($*_MAKEVARS)
325         $(AT)touch $@
326
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$$' | \
331         while read t; do \
332                 case "$$t" in \
333                 ./bin/*) continue;; \
334                 ./sbin/*) continue;; \
335                 esac; \
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\""; \
340         done
341         $(AT)touch $@
342
343 clean: $(foreach pkg,$(AUTOMAKE_y),$($(pkg)_CLEAN))
344         rm -rf build downloads
345
346 romfs_pre:
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; \
360         done
361         rm -f $(ROMFSDIR)/lib/*.a
362         rm -f $(ROMFSDIR)/lib/*.la
363
364 romfs_post: $(foreach pkg,$(AUTOMAKE_y),$($(pkg)_ROMFS))
365
366 romfs: $(if $(AUTOMAKE_ROMFS),$(AUTOMAKE_ROMFS),romfs_pre) romfs_post
367