pass HOST_ variables, not BUILD_
[buildroot.git] / package / Makefile.autotools.in
blob51e57f4f762ffa56c72a6950cdf441bbeff4ac04
1 ################################################################################
3 # Makefile.autotools.in --
5 # Implicit and Generated Rules for easily creating autotools-compatible
6 # buildroot packages
8 ## Example minimal makefile for a package named 'foo'
10 # | FOO_VERSION = 1.0
11 # | FOO_SOURCE = foo-$(FOO_VERSION).tar.gz
12 # | FOO_SITE = http://www.libfoo.org/dist
13 # | $(eval $(call AUTOTARGETS,foo))
15 ## The following targets can be called from the shell:
17 # foo, foo-source, foo-patch, foo-configure, foo-build, foo-install,
18 # foo-install-target, foo-install-staging, foo-uninstall, foo-clean,
19 # foo-dirclean
21 ## The following variables which can be (re)defined in the package makefile:
23 # FOO_VERSION [mandatory]
24 #       version string of the package
25 # FOO_SOURCE [default foo-$(FOO_VERSION).tar.gz]
26 #       file name of the package source
27 # FOO_SITE [default sourceforge project "foo"]
28 #       URL under wich $(FOO_SOURCE) can be found
29 # FOO_DEPENDENCIES [default empty]
30 #       list of (package) targets that must be built before foo
31 # FOO_AUTORECONF [YES/NO, default NO]
32 #       run <autoreconf> before <configure>
33 # FOO_CONF_ENV [default empty]
34 #       environment passed to the <configure> script
35 # FOO_CONF_OPT [default empty]
36 #       arguments passed to the <configure> script
37 # FOO_MAKE_ENV [default empty]
38 #       environment passed to all calls to <make> in the package source
39 #       directory
40 # FOO_MAKE_OPT [default empty]
41 #       arguments passed to <make> while building
42 # FOO_INSTALL_STAGING [YES/NO, default NO]
43 #       install the package to the staging directory
44 # FOO_INSTALL_TARGET [YES/NO, default YES]
45 #       install the package to the target directory
46 # FOO_INSTALL_STAGING_OPT [default DESTDIR=$(STAGING_DIR)/usr install]
47 #       arguments passed to <make> while installing to the staging directory
48 # FOO_INSTALL_TARGET_OPT [default DESTDIR=$(TARGET_DIR)/usr install-exec]
49 #       arguments passed to <make> while installing to the target directory
50 # FOO_CLEAN_OPT [default clean]
51 #       arguments passed to <make> while installing to the staging directory
52 # FOO_UNINSTALL_STAGING_OPT  [default DESTDIR=$(STAGING_DIR)/usr uninstall]
53 #       arguments passed to <make> while uninstalling from the staging
54 #       directory
55 # FOO_UNINSTALL_TARGET_OPT [default DESTDIR=$(STAGING_DIR)/usr uninstall]
56 #       arguments passed to <make> while uninstalling from the target
57 #       directory
58 # FOO_SUBDIR [default empty]
59 #       relative path in the package source from which to run configure and
60 #       make
61 # FOO_DIR_PREFIX [default empty]
62 #       toplevel relative path to package *.mk file and corresponding patches
64 ## The following variables contain hook target names
65 ## by default they do nothing, they can be overriden in package makefiles
67 # FOO_HOOK_POST_EXTRACT, FOO_HOOK_POST_CONFIGURE,
68 # FOO_HOOK_POST_BUILD, FOO_HOOK_POST_INSTALL
70 ## The following variables contain targets that can be overriden
72 # FOO_TARGET_INSTALL_TARGET FOO_TARGET_INSTALL_STAGING FOO_TARGET_BUILD
73 # FOO_TARGET_CONFIGURE FOO_TARGET_PATCH FOO_TARGET_EXTRACT FOO_TARGET_SOURCE
74 # FOO_TARGET_UNINSTALL FOO_TARGET_CLEAN FOO_TARGET_DIRCLEAN
76 # E.g. if your package has a no <configure> script you can place the following
77 # in your package makefile:
79 # | $(FOO_TARGET_INSTALL):
80 # |     touch $@
82 ## The following variables are defined automatically and can be used in
83 ## overriden targets:
85 # PKG
86 #       is always the current package name ("foo" in the example)
87 # FOO_DIR
88 #       the directory in which the package source is extracted.
89 #       the base name will always be foo-$(FOO_VERSION), no matter what the
90 #       archive name or the directory-in-archive name are.
91 # MESSAGE
92 #       macro that outputs a pretty message to stdout, e.g. use
93 #       $(call MESSAGE,"Hello World")
94 #       in a target.
96 # Caveats:
97 # - the 'eval' line (final line in the example) must be placed
98 #   after all variable settings, but before all target re-definition
99 #   (including hooks)
100 ################################################################################
102 # UPPERCASE Macro -- transform its argument to uppercase and replace dots and
103 # hyphens to underscores
104 UPPERCASE = $(shell echo $(1) | tr "a-z.-" "A-Z__")
106 # Define extrators for different archive suffixes
107 INFLATE.bz2 = $(BZCAT)
108 INFLATE.gz  = $(ZCAT)
109 INFLATE.tbz = $(BZCAT)
110 INFLATE.tgz = $(ZCAT)
111 INFLATE.tar = cat
113 # MESSAGE Macro -- display a message in bold type
114 MESSAGE = @echo "$(TERM_BOLD)>>> $($(PKG)_NAME) $($(PKG)_VERSION) $(1)$(TERM_RESET)"
115 TERM_BOLD = #$(shell tput bold)
116 TERM_RESET = #$(shell tput rmso)
118 # Utility programs used to build packages
119 TAR ?= tar
120 #ACLOCAL_STAGING_DIR ?= $(STAGING_DIR)/usr/share/aclocal
121 #ACLOCAL ?= aclocal -I $(ACLOCAL_STAGING_DIR)
122 #AUTORECONF ?= autoreconf -v -i -f -I $(ACLOCAL_STAGING_DIR)
123 #       ACLOCAL="$(ACLOCAL)"
126 ################################################################################
127 # Implicit targets -- produce a stamp file for each step of a package build
128 ################################################################################
130 # Retrieve and unpack the archive
131 $(BUILD_DIR)/%/.stamp_downloaded:
132 # support make source-check/external-deps
133 ifneq ($(SPIDER),)
134         $(WGET) -P $(DL_DIR) $($(PKG)_SITE)/$($(PKG)_SOURCE)
135         $(if $($(PKG)_PATCH),$(WGET) -P $(DL_DIR) $($(PKG)_SITE)/$($(PKG)_PATCH))
136 else
137         $(call MESSAGE,"Downloading")
138 ifneq ($(strip $(subst ",,$(BR2_PRIMARY_SITE))),)
139 #"))
140         -$(Q)test -e $(DL_DIR)/$($(PKG)_SOURCE) || $(WGET) -P $(DL_DIR) $(BR2_PRIMARY_SITE)/$($(PKG)_SOURCE)
141 endif
142         $(Q)test -e $(DL_DIR)/$($(PKG)_SOURCE) || $(WGET) -P $(DL_DIR) $($(PKG)_SITE)/$($(PKG)_SOURCE)
143         $(if $($(PKG)_PATCH),$(Q)test -e $(DL_DIR)/$($(PKG)_PATCH) || $(WGET) -P $(DL_DIR) $($(PKG)_SITE)/$($(PKG)_PATCH))
144         $(Q)mkdir -p $(@D)
145         $(Q)touch $@
146 endif
148 # Retrieve and unpack the archive
149 $(BUILD_DIR)/%/.stamp_extracted:
150         $(call MESSAGE,"Extracting")
151         $(Q)mkdir -p $(@D)
152         $(Q)$(INFLATE$(suffix $($(PKG)_SOURCE))) $(DL_DIR)/$($(PKG)_SOURCE) | \
153         $(TAR) --strip-components=1 -C $(@D) $(TAR_OPTIONS) -
154 # some packages have messed up permissions inside
155         $(Q)chmod -R ug+rw $(@D)
156 # if the package uses libtool, patch it for cross-compiling in buildroot
157         for i in `find $(@D) -name ltmain.sh`; do \
158                 toolchain/patch-kernel.sh $${i%/*} package buildroot-libtool.patch; \
159         done
160         $(Q)touch $@
162 # Patch
163 # XXX: FIXME: This has to be done differently and path-independent, i.e. use
164 # XXX: FIXME: the dir-part of the stem as base-dir (instead of hardcoding
165 # XXX: FIXME: "package/".
166 $(BUILD_DIR)/%/.stamp_patched: NAMEVER = $($(PKG)_NAME)-$($(PKG)_VERSION)
167 $(BUILD_DIR)/%/.stamp_patched:
168         $(call MESSAGE,"Patching $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME)")
169         $(if $($(PKG)_PATCH),toolchain/patch-kernel.sh $(@D) $(DL_DIR) $($(PKG)_PATCH))
170         $(Q)( \
171         if test -d $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME); then \
172           if test "$(wildcard $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME)/$(NAMEVER)*.patch*)"; then \
173             toolchain/patch-kernel.sh $(@D) $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME) $(NAMEVER)\*.patch || exit 1; \
174           else \
175             toolchain/patch-kernel.sh $(@D) $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME) $($(PKG)_NAME)\*.patch || exit 1; \
176             if test -d $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME)/$(NAMEVER); then \
177               toolchain/patch-kernel.sh $(@D) $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME)/$(NAMEVER) \*.patch || exit 1; \
178             fi; \
179           fi; \
180         fi; \
181         )
182 ifeq ($(strip $(BR2_UPDATE_CONFIG)),y)
183         $(Q)(for file in config.guess config.sub; do \
184                 for i in $$(find $(@D) -name $$file); do \
185                         cp package/gnuconfig/$$file $$i; \
186                 done; \
187         done)
188 endif
189         -$(Q)chmod +x $(@D)/configure
190         $(Q)touch $@
192 # Running autoreconf
193 $(BUILD_DIR)/%/.stamp_autoconfigured:
194         $(call MESSAGE,"Running autoreconf")
195         $(Q)cd $(@D)/$($(PKG)_SUBDIR) && $(TARGET_CONFIGURE_OPTS) $(AUTORECONF)
196         $(Q)touch $@
198 # Configuring
199 $(BUILD_DIR)/%/.stamp_configured:
200         $(call MESSAGE,"Configuring")
201         cd $(@D)/$($(PKG)_SUBDIR) && rm -f config.cache && \
202         $($(PKG)_CONF_ENV) \
203                 $(AUTO_CONFIGURE_TARGET) \
204                 --prefix=/usr \
205                 --exec-prefix=/usr \
206                 --sysconfdir=/etc \
207                 $(if $(findstring s,$(MAKEFLAGS)),--quiet,) \
208                 $($(PKG)_CONF_OPT)
209         $(Q)touch $@
211 # Build
212 $(BUILD_DIR)/%/.stamp_built:
213         $(call MESSAGE,"Building")
214         +$($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_MAKE_OPT) -C $(@D)/$($(PKG)_SUBDIR)
215         $(Q)touch $@
217 # Install to staging dir
218 $(BUILD_DIR)/%/.stamp_staging_installed:
219         $(call MESSAGE,'Installing to host (staging directory)')
220         $($(PKG)_MAKE_ENV) $(MAKE1) $($(PKG)_INSTALL_STAGING_OPT) -C $(@D)/$($(PKG)_SUBDIR)
221 #       toolchain/replace.sh $(STAGING_DIR)/usr/lib ".*\.la" "\(['= ]\)/usr" "\\1$(STAGING_DIR)/usr"
222         for i in $$(find $(STAGING_DIR)/usr/lib/ -name "*.la"); do \
223                 cp $$i $$i~; \
224                 $(SED) "s:\(['= ]\)/usr:\\1$(STAGING_DIR)/usr:g" $$i; \
225         done
226         touch $@
228 # Install to target dir
229 $(PROJECT_BUILD_DIR)/autotools-stamps/%_target_installed:
230         $(call MESSAGE,"Installing to target")
231         $($(PKG)_MAKE_ENV) $(MAKE1) $($(PKG)_INSTALL_TARGET_OPT) -C $($(PKG)_DIR)/$($(PKG)_SUBDIR)
232         $(if $(BR2_HAVE_MANPAGES),,for d in share/man; do \
233                 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
234         done)
235         $(if $(BR2_HAVE_INFOPAGES),,for d in share/info; do \
236                 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
237         done)
238         $(if $(BR2_HAVE_INCLUDES),,for d in include; do \
239                 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
240         done)
241         $(Q)mkdir -p $(@D)
242         touch $@
244 $(BUILD_DIR)/%/.stamp_cleaned:
245         $(call MESSAGE,"Cleaning up")
246         -$($(PKG)_MAKE_ENV) $(MAKE1)  $($(PKG)_CLEAN_OPT) -C $(@D)/$($(PKG)_SUBDIR)
247         rm -f $(@D)/.stamp_built
249 $(BUILD_DIR)/%/.stamp_uninstalled:
250         $(call MESSAGE,"Uninstalling")
251         -$($(PKG)_MAKE_ENV) $(MAKE1) $($(PKG)_UNINSTALL_STAGING_OPT) -C $(@D)/$($(PKG)_SUBDIR)
252         rm -f $(@D)/.stamp_staging_installed
253         -$($(PKG)_MAKE_ENV) $(MAKE1) $($(PKG)_UNINSTALL_TARGET_OPT) -C $(@D)/$($(PKG)_SUBDIR)
254         rm -rf $($(PKG)_TARGET_INSTALL_TARGET) $($(PKG)_HOOK_POST_INSTALL)
256 $(BUILD_DIR)/%/.stamp_dircleaned:
257         rm -rf $(@D)
260 ################################################################################
261 # AUTOTARGETS -- the target generator macro; define a set of human-readable
262 # make targets, stamps, and default per-package variables.
263 # Argument 1 is the package directory prefix.
264 # Argument 2 is the (lowercase) package name.
265 ################################################################################
267 define AUTOTARGETS
268 $(call AUTOTARGETS_INNER,$(2),$(call UPPERCASE,$(2)),$(1))
269 endef
271 # AUTOTARGETS_INNER -- does the job for AUTOTARGETS; argument 1 is the
272 # lowercase package name, argument 2 the uppercase package name,
273 # argument 3 the package directory prefix
274 define AUTOTARGETS_INNER
276 # define package-specific variables to default values
277 $(2)_NAME                       =  $(1)
278 $(2)_VERSION                    ?= undefined
279 $(2)_DIR                        =  $$(BUILD_DIR)/$(1)-$$($(2)_VERSION)
280 $(2)_SOURCE                     ?= $(1)-$$($(2)_VERSION).tar.gz
281 $(2)_SITE                       ?= \
282         http://$$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/$(1)
283 $(2)_DEPENDENCIES               ?=
284 $(2)_AUTORECONF                 ?= NO
285 $(2)_CONF_ENV                   ?=
286 $(2)_CONF_OPT                   ?=
287 $(2)_MAKE_ENV                   ?=
288 $(2)_MAKE_OPT                   ?=
289 $(2)_INSTALL_STAGING            ?= NO
290 $(2)_INSTALL_TARGET             ?= YES
291 $(2)_INSTALL_STAGING_OPT        ?= DESTDIR=$$(STAGING_DIR) install
292 $(2)_INSTALL_TARGET_OPT         ?= DESTDIR=$$(TARGET_DIR)  install-exec
293 $(2)_CLEAN_OPT                  ?= clean
294 $(2)_UNINSTALL_STAGING_OPT      ?= DESTDIR=$$(STAGING_DIR) uninstall
295 $(2)_UNINSTALL_TARGET_OPT       ?= DESTDIR=$$(TARGET_DIR)  uninstall
296 $(2)_SUBDIR                     ?=
297 $(2)_DIR_PREFIX                 =  $(if $(3),$(3),$(TOP_SRCDIR)/package)
300 # define sub-target stamps
301 # targets which affect $(TARGET_DIR) must use a unique stamp for each $(PROJECT)
302 $(2)_TARGET_INSTALL_TARGET =    $(PROJECT_BUILD_DIR)/autotools-stamps/$(1)_target_installed
303 $(2)_TARGET_INSTALL_STAGING =   $$($(2)_DIR)/.stamp_staging_installed
304 $(2)_TARGET_BUILD =             $$($(2)_DIR)/.stamp_built
305 $(2)_TARGET_CONFIGURE =         $$($(2)_DIR)/.stamp_configured
306 $(2)_TARGET_AUTORECONF =        $$($(2)_DIR)/.stamp_autoconfigured
307 $(2)_TARGET_PATCH =             $$($(2)_DIR)/.stamp_patched
308 $(2)_TARGET_EXTRACT =           $$($(2)_DIR)/.stamp_extracted
309 $(2)_TARGET_SOURCE =            $$($(2)_DIR)/.stamp_downloaded
310 $(2)_TARGET_UNINSTALL =         $$($(2)_DIR)/.stamp_uninstalled
311 $(2)_TARGET_CLEAN =             $$($(2)_DIR)/.stamp_cleaned
312 $(2)_TARGET_DIRCLEAN =          $$($(2)_DIR)/.stamp_dircleaned
314 $(2)_HOOK_POST_EXTRACT =        $$($(2)_DIR)/.stamp_hook_post_extract
315 $(2)_HOOK_POST_CONFIGURE =      $$($(2)_DIR)/.stamp_hook_post_configure
316 $(2)_HOOK_POST_BUILD =          $$($(2)_DIR)/.stamp_hook_post_build
317 $(2)_HOOK_POST_INSTALL =        $(PROJECT_BUILD_DIR)/autotools-stamps/$(1)_hook_post_install
319 # human-friendly targets and target sequencing
320 $(1):                   $(1)-install
321 $(1)-install:           $(1)-install-staging $(1)-install-target \
322                         $$($(2)_HOOK_POST_INSTALL)
324 ifeq ($$($(2)_INSTALL_TARGET),YES)
325 $(1)-install-target:    $(1)-build $$($(2)_TARGET_INSTALL_TARGET)
326 else
327 $(1)-install-target:
328 endif
330 ifeq ($$($(2)_INSTALL_STAGING),YES)
331 $(1)-install-staging:   $(1)-build $$($(2)_TARGET_INSTALL_STAGING)
332 else
333 $(1)-install-staging:
334 endif
336 $(1)-build:             $(1)-configure \
337                         $$($(2)_TARGET_BUILD) \
338                         $$($(2)_HOOK_POST_BUILD)
340 $(1)-configure:         $(1)-autoreconf \
341                         $$($(2)_TARGET_CONFIGURE) \
342                         $$($(2)_HOOK_POST_CONFIGURE)
344 ifeq ($$($(2)_AUTORECONF),YES)
345 $(1)-autoreconf:        $(1)-patch $$($(2)_TARGET_AUTORECONF)
346 $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
347 else
348 $(1)-autoreconf:        $(1)-patch
349 endif
351 $(1)-patch:             $(1)-extract $$($(2)_TARGET_PATCH)
353 $(1)-extract:           $(1)-depends \
354                         $$($(2)_TARGET_EXTRACT) \
355                         $$($(2)_HOOK_POST_EXTRACT)
357 $(1)-depends:           $(1)-source $$($(2)_DEPENDENCIES)
359 $(1)-source:            $$($(2)_TARGET_SOURCE)
361 # non-build targets
362 $(1)-uninstall: $(1)-configure $$($(2)_TARGET_UNINSTALL)
364 $(1)-clean:             $(1)-uninstall \
365                         $$($(2)_TARGET_CLEAN)
367 $(1)-dirclean:          $$($(2)_TARGET_DIRCLEAN)
369 # define the PKG variable for all targets, containing the
370 # uppercase package variable prefix
371 $$($(2)_TARGET_INSTALL_TARGET):         PKG=$(2)
372 $$($(2)_TARGET_INSTALL_STAGING):        PKG=$(2)
373 $$($(2)_TARGET_BUILD):                  PKG=$(2)
374 $$($(2)_TARGET_CONFIGURE):              PKG=$(2)
375 $$($(2)_TARGET_AUTORECONF):             PKG=$(2)
376 $$($(2)_TARGET_PATCH):                  PKG=$(2)
377 $$($(2)_TARGET_EXTRACT):                PKG=$(2)
378 $$($(2)_TARGET_SOURCE):                 PKG=$(2)
379 $$($(2)_TARGET_UNINSTALL):              PKG=$(2)
380 $$($(2)_TARGET_CLEAN):                  PKG=$(2)
381 $$($(2)_TARGET_DIRCLEAN):               PKG=$(2)
382 $$($(2)_HOOK_POST_EXTRACT):             PKG=$(2)
383 $$($(2)_HOOK_POST_CONFIGURE):           PKG=$(2)
384 $$($(2)_HOOK_POST_BUILD):               PKG=$(2)
385 $$($(2)_HOOK_POST_INSTALL):             PKG=$(2)
387 # define hook targets
388 # default hook behaviour: do nothing
389 $$($(2)_HOOK_POST_EXTRACT):
390 $$($(2)_HOOK_POST_CONFIGURE):
391 $$($(2)_HOOK_POST_BUILD):
392 $$($(2)_HOOK_POST_INSTALL):
394 # add package to the general list of targets if requested by the buildroot
395 # configuration
396 ifeq ($$(BR2_PACKAGE_$(2)),y)
397 TARGETS += $(1)
398 endif
399 endef