1 ################################################################################
3 # Makefile.autotools.in --
5 # Implicit and Generated Rules for easily creating autotools-compatible
8 ## Example minimal makefile for a package named 'foo'
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,
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
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=$(STAGING_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
55 # FOO_UNINSTALL_TARGET_OPT [default DESTDIR=$(STAGING_DIR)/usr uninstall]
56 # arguments passed to <make> while uninstalling from the target
58 # FOO_SUBDIR [default empty]
59 # relative path in the package source from which to run configure and
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_BUILD, FOO_HOOK_POST_INSTALL
69 ## The following variables contain targets that can be overriden
71 # FOO_TARGET_INSTALL_TARGET FOO_TARGET_INSTALL_STAGING FOO_TARGET_BUILD
72 # FOO_TARGET_CONFIGURE FOO_TARGET_PATCH FOO_TARGET_EXTRACT FOO_TARGET_SOURCE
73 # FOO_TARGET_UNINSTALL FOO_TARGET_CLEAN FOO_TARGET_DIRCLEAN
75 # E.g. if your package has a no <configure> script you can place the following
76 # in your package makefile:
78 # | $(FOO_TARGET_INSTALL):
81 ## The following variables are defined automatically and can be used in
85 # is always the current package name ("foo" in the example)
87 # the directory in which the package source is extracted.
88 # the base name will always be foo-$(FOO_VERSION), no matter what the
89 # archive name or the directory-in-archive name are.
91 # macro that outputs a pretty message to stdout, e.g. use
92 # $(call MESSAGE,"Hello World")
96 # - the 'eval' line (final line in the example) must be placed
97 # after all variable settings, but before all target re-definition
99 ################################################################################
101 # UPPERCASE Macro -- transform its argument to uppercase and replace dots and
102 # hyphens to underscores
103 UPPERCASE = $(shell echo $(1) | tr "a-z.-" "A-Z__")
105 # Define extrators for different archive suffixes
106 INFLATE.bz2 = $(BZCAT)
108 INFLATE.tbz = $(BZCAT)
109 INFLATE.tgz = $(ZCAT)
112 # MESSAGE Macro -- display a message in bold type
113 MESSAGE = @echo $(TERM_BOLD); \
114 echo ">>> $($(PKG)_NAME) $($(PKG)_VERSION) $(1)"; \
116 TERM_BOLD = #$(shell tput bold)
117 TERM_RESET = #$(shell tput rmso)
119 # Utility programs used to build packages
121 #ACLOCAL_STAGING_DIR ?= $(STAGING_DIR)/usr/share/aclocal
122 #ACLOCAL ?= aclocal -I $(ACLOCAL_STAGING_DIR)
123 #AUTORECONF ?= autoreconf -v -i -f -I $(ACLOCAL_STAGING_DIR)
124 # ACLOCAL="$(ACLOCAL)"
127 ################################################################################
128 # Implicit targets -- produce a stamp file for each step of a package build
129 ################################################################################
131 # Retrieve and unpack the archive
132 $(BUILD_DIR)/%/.stamp_downloaded:
133 $(call MESSAGE,"Downloading")
134 $(Q)test -e $(DL_DIR)/$($(PKG)_SOURCE) || $(WGET) -P $(DL_DIR) $($(PKG)_SITE)/$($(PKG)_SOURCE)
135 $(if $($(PKG)_PATCH),$(Q)test -e $(DL_DIR)/$($(PKG)_PATCH) || $(WGET) -P $(DL_DIR) $($(PKG)_SITE)/$($(PKG)_PATCH))
139 # Retrieve and unpack the archive
140 $(BUILD_DIR)/%/.stamp_extracted:
141 $(call MESSAGE,"Extracting")
143 $(Q)$(INFLATE$(suffix $($(PKG)_SOURCE))) $(DL_DIR)/$($(PKG)_SOURCE) | \
144 $(TAR) --strip-components=1 -C $(@D) $(TAR_OPTIONS) -
148 # XXX: FIXME: This has to be done differently and path-independent, i.e. use
149 # XXX: FIXME: the dir-part of the stem as base-dir (instead of hardcoding
150 # XXX: FIXME: "package/".
151 $(BUILD_DIR)/%/.stamp_patched: NAMEVER = $($(PKG)_NAME)-$($(PKG)_VERSION)
152 $(BUILD_DIR)/%/.stamp_patched:
153 $(call MESSAGE,"Patching")
154 $(if $($(PKG)_PATCH),toolchain/patch-kernel.sh $(@D) $(DL_DIR) $($(PKG)_PATCH))
156 if test -d $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME); then \
157 if test "$(wildcard $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME)/$(NAMEVER)*.patch)"; then \
158 toolchain/patch-kernel.sh $(@D) $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME) $(NAMEVER)\*.patch || exit 1; \
160 toolchain/patch-kernel.sh $(@D) $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME) $($(PKG)_NAME)\*.patch || exit 1; \
161 if test -d package/$($(PKG)_DIR_PREFIX)/$($(PKG)_NAME)/$(NAMEVER); then \
162 toolchain/patch-kernel.sh $(@D) $($(PKG)_DIR_PREFIX)/$($(PKG)_NAME)/$(NAMEVER) \*.patch || exit 1; \
167 ifeq ($(strip $(BR2_UPDATE_CONFIG)),y)
168 $(Q)(for file in config.guess config.sub; do \
169 for i in $$(find $(@D) -name $$file); do \
170 cp package/gnuconfig/$$file $$i; \
174 -$(Q)chmod +x $(@D)/configure
178 $(BUILD_DIR)/%/.stamp_autoconfigured:
179 $(call MESSAGE,"Running autoreconf")
180 $(Q)cd $(@D)/$($(PKG)_SUBDIR) && $(AUTORECONF)
184 $(BUILD_DIR)/%/.stamp_configured:
185 $(call MESSAGE,"Configuring")
186 $(Q)if test "$($(PKG)_AUTORECONF)" = "YES"; then \
187 cd $(@D)/$($(PKG)_SUBDIR) && $(AUTORECONF); \
189 cd $(@D)/$($(PKG)_SUBDIR) && rm -f config.cache && \
191 $(AUTO_CONFIGURE_TARGET) \
199 $(BUILD_DIR)/%/.stamp_built:
200 $(call MESSAGE,"Building")
201 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_MAKE_OPT) -C $(@D)/$($(PKG)_SUBDIR)
204 # Install to staging dir
205 $(BUILD_DIR)/%/.stamp_staging_installed:
206 $(call MESSAGE,'Installing to host (staging directory)')
207 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_INSTALL_STAGING_OPT) -C $(@D)/$($(PKG)_SUBDIR)
208 # toolchain/replace.sh $(STAGING_DIR)/usr/lib ".*\.la" "\(['= ]\)/usr" "\\1$(STAGING_DIR)/usr"
209 for i in $$(find $(STAGING_DIR)/usr/lib/ -name "*.la"); do \
211 $(SED) "s:\(['= ]\)/usr:\\1$(STAGING_DIR)/usr:" $$i; \
215 # Install to target dir
216 $(BUILD_DIR)/%/.stamp_target_installed:
217 $(call MESSAGE,"Installing to target")
218 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_INSTALL_TARGET_OPT) -C $(@D)/$($(PKG)_SUBDIR)
219 $(if $(BR2_HAVE_MANPAGES),,for d in man; do \
220 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
222 $(if $(BR2_HAVE_INFOPAGES),,for d in info share/info; do \
223 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
225 $(if $(BR2_HAVE_INCLUDES),,for d in include; do \
226 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
228 find $(TARGET_DIR) -name '*.la' -delete
231 $(BUILD_DIR)/%/.stamp_cleaned:
232 $(call MESSAGE,"Cleaning up")
233 -$($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_CLEAN_OPT) -C $(@D)/$($(PKG)_SUBDIR)
235 $(BUILD_DIR)/%/.stamp_uninstalled:
236 $(call MESSAGE,"Uninstalling")
237 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_UNINSTALL_STAGING_OPT) -C $(@D)/$($(PKG)_SUBDIR)
238 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_UNINSTALL_TARGET_OPT) -C $(@D)/$($(PKG)_SUBDIR)
240 $(BUILD_DIR)/%/.stamp_dircleaned:
244 ################################################################################
245 # AUTOTARGETS -- the target generator macro; define a set of human-readable
246 # make targets, stamps, and default per-package variables.
247 # Argument 1 is the package directory prefix.
248 # Argument 2 is the (lowercase) package name.
249 ################################################################################
252 $(call AUTOTARGETS_INNER,$(2),$(call UPPERCASE,$(2)),$(1))
255 # AUTOTARGETS_INNER -- does the job for AUTOTARGETS; argument 1 is the
256 # lowercase package name, argument 2 the uppercase package name,
257 # argument 3 the package directory prefix
258 define AUTOTARGETS_INNER
260 # define package-specific variables to default values
262 $(2)_VERSION ?= undefined
263 $(2)_DIR = $$(BUILD_DIR)/$(1)-$$($(2)_VERSION)
264 $(2)_SOURCE ?= $(1)-$$($(2)_VERSION).tar.gz
266 http://$$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/$(1)
268 $(2)_AUTORECONF ?= NO
273 $(2)_INSTALL_STAGING ?= NO
274 $(2)_INSTALL_TARGET ?= YES
275 $(2)_INSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) install
276 $(2)_INSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) install-exec
277 $(2)_CLEAN_OPT ?= clean
278 $(2)_UNINSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) uninstall
279 $(2)_UNINSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) uninstall
281 $(2)_DIR_PREFIX = $(if $(3),$(3),$(TOP_SRCDIR)/package)
284 # define sub-target stamps
285 $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
286 $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
287 $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
288 $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
289 $(2)_TARGET_AUTORECONF = $$($(2)_DIR)/.stamp_autoconfigured
290 $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
291 $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
292 $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
293 $(2)_TARGET_UNINSTALL = $$($(2)_DIR)/.stamp_uninstalled
294 $(2)_TARGET_CLEAN = $$($(2)_DIR)/.stamp_cleaned
295 $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
297 $(2)_HOOK_POST_BUILD = $$($(2)_DIR)/.stamp_hook_post_build
298 $(2)_HOOK_POST_INSTALL = $$($(2)_DIR)/.stamp_hook_post_install
300 # human-friendly targets and target sequencing
302 $(1)-install: $(1)-install-staging $(1)-install-target \
303 $$($(2)_HOOK_POST_INSTALL)
305 ifeq ($$($(2)_INSTALL_TARGET),YES)
306 $(1)-install-target: $(1)-build $$($(2)_TARGET_INSTALL_TARGET)
311 ifeq ($$($(2)_INSTALL_STAGING),YES)
312 $(1)-install-staging: $(1)-build $$($(2)_TARGET_INSTALL_STAGING)
314 $(1)-install-staging:
317 $(1)-build: $(1)-configure \
318 $$($(2)_TARGET_BUILD) \
319 $$($(2)_HOOK_POST_BUILD)
321 $(1)-configure: $(1)-autoreconf $$($(2)_TARGET_CONFIGURE)
323 ifeq ($$($(2)_AUTORECONF),YES)
324 $(1)-autoreconf: $(1)-patch $$($(2)_TARGET_AUTORECONF)
325 $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
327 $(1)-autoreconf: $(1)-patch
330 $(1)-patch: $(1)-extract $$($(2)_TARGET_PATCH)
332 $(1)-extract: $(1)-depends $$($(2)_TARGET_EXTRACT)
334 $(1)-depends: $(1)-source $$($(2)_DEPENDENCIES)
336 $(1)-source: $$($(2)_TARGET_SOURCE)
339 $(1)-uninstall: $(1)-configure $$($(2)_TARGET_UNINSTALL)
341 $(1)-clean: $$($(2)_TARGET_CLEAN)
343 $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
345 # define the PKG variable for all targets, containing the
346 # uppercase package variable prefix
347 $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
348 $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
349 $$($(2)_TARGET_BUILD): PKG=$(2)
350 $$($(2)_TARGET_CONFIGURE): PKG=$(2)
351 $$($(2)_TARGET_AUTORECONF): PKG=$(2)
352 $$($(2)_TARGET_PATCH): PKG=$(2)
353 $$($(2)_TARGET_EXTRACT): PKG=$(2)
354 $$($(2)_TARGET_SOURCE): PKG=$(2)
355 $$($(2)_TARGET_UNINSTALL): PKG=$(2)
356 $$($(2)_TARGET_CLEAN): PKG=$(2)
357 $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
358 $$($(2)_HOOK_POST_BUILD): PKG=$(2)
359 $$($(2)_HOOK_POST_INSTALL): PKG=$(2)
361 # define hook targets
362 # default hook behaviour: do nothing
363 $$($(2)_HOOK_POST_BUILD):
364 $$($(2)_HOOK_POST_INSTALL):
366 # add package to the general list if targets if requested by the buildroot
368 ifeq ($$(BR2_PACKAGE_$(2)),y)