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; \
177 $(BUILD_DIR)/%/.stamp_autoconfigured:
178 $(call MESSAGE,"Running autoreconf")
179 $(Q)cd $(@D)/$($(PKG)_SUBDIR) && $(AUTORECONF)
183 $(BUILD_DIR)/%/.stamp_configured:
184 $(call MESSAGE,"Configuring")
185 $(Q)if test "$($(PKG)_AUTORECONF)" = "YES"; then \
186 cd $(@D)/$($(PKG)_SUBDIR) && $(AUTORECONF); \
188 cd $(@D)/$($(PKG)_SUBDIR) && rm -f config.cache && \
189 $(TARGET_CONFIGURE_OPTS) \
190 $(TARGET_CONFIGURE_ARGS) \
193 --target=$(GNU_TARGET_NAME) \
194 --host=$(GNU_TARGET_NAME) \
195 --build=$(GNU_HOST_NAME) \
203 $(BUILD_DIR)/%/.stamp_built:
204 $(call MESSAGE,"Building")
205 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_MAKE_OPT) -C $(@D)/$($(PKG)_SUBDIR)
208 # Install to staging dir
209 $(BUILD_DIR)/%/.stamp_staging_installed:
210 $(call MESSAGE,'Installing to host (staging directory)')
211 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_INSTALL_STAGING_OPT) -C $(@D)/$($(PKG)_SUBDIR)
212 # toolchain/replace.sh $(STAGING_DIR)/usr/lib ".*\.la" "\(['= ]\)/usr" "\\1$(STAGING_DIR)/usr"
213 for i in $$(find $(STAGING_DIR)/usr/lib/ -name "*.la"); do \
215 $(SED) "s:\(['= ]\)/usr:\\1$(STAGING_DIR)/usr:" $$i; \
219 # Install to target dir
220 $(BUILD_DIR)/%/.stamp_target_installed:
221 $(call MESSAGE,"Installing to target")
222 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_INSTALL_TARGET_OPT) -C $(@D)/$($(PKG)_SUBDIR)
223 $(if $(BR2_HAVE_MANPAGES),,for d in man; do \
224 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
226 $(if $(BR2_HAVE_INFOPAGES),,for d in info share/info; do \
227 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
229 $(if $(BR2_HAVE_INCLUDES),,for d in include; do \
230 rm -rf $(TARGET_DIR)/$$d $(TARGET_DIR)/usr/$$d; \
232 find $(TARGET_DIR) -name '*.la' -delete
235 $(BUILD_DIR)/%/.stamp_cleaned:
236 $(call MESSAGE,"Cleaning up")
237 -$($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_CLEAN_OPT) -C $(@D)/$($(PKG)_SUBDIR)
239 $(BUILD_DIR)/%/.stamp_uninstalled:
240 $(call MESSAGE,"Uninstalling")
241 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_UNINSTALL_STAGING_OPT) -C $(@D)/$($(PKG)_SUBDIR)
242 $($(PKG)_MAKE_ENV) $(MAKE) $($(PKG)_UNINSTALL_TARGET_OPT) -C $(@D)/$($(PKG)_SUBDIR)
244 $(BUILD_DIR)/%/.stamp_dircleaned:
248 ################################################################################
249 # AUTOTARGETS -- the target generator macro; define a set of human-readable
250 # make targets, stamps, and default per-package variables.
251 # Argument 1 is the package directory prefix.
252 # Argument 2 is the (lowercase) package name.
253 ################################################################################
256 $(call AUTOTARGETS_INNER,$(2),$(call UPPERCASE,$(2)),$(1))
259 # AUTOTARGETS_INNER -- does the job for AUTOTARGETS; argument 1 is the
260 # lowercase package name, argument 2 the uppercase package name,
261 # argument 3 the package directory prefix
262 define AUTOTARGETS_INNER
264 # define package-specific variables to default values
266 $(2)_VERSION ?= undefined
267 $(2)_DIR = $$(BUILD_DIR)/$(1)-$$($(2)_VERSION)
268 $(2)_SOURCE ?= $(1)-$$($(2)_VERSION).tar.gz
270 http://$$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/$(1)
272 $(2)_AUTORECONF ?= NO
277 $(2)_INSTALL_STAGING ?= NO
278 $(2)_INSTALL_TARGET ?= YES
279 $(2)_INSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) install
280 $(2)_INSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) install-exec
281 $(2)_CLEAN_OPT ?= clean
282 $(2)_UNINSTALL_STAGING_OPT ?= DESTDIR=$$(STAGING_DIR) uninstall
283 $(2)_UNINSTALL_TARGET_OPT ?= DESTDIR=$$(TARGET_DIR) uninstall
285 $(2)_DIR_PREFIX = $(if $(3),$(3),$(TOP_SRCDIR)/package)
288 # define sub-target stamps
289 $(2)_TARGET_INSTALL_TARGET = $$($(2)_DIR)/.stamp_target_installed
290 $(2)_TARGET_INSTALL_STAGING = $$($(2)_DIR)/.stamp_staging_installed
291 $(2)_TARGET_BUILD = $$($(2)_DIR)/.stamp_built
292 $(2)_TARGET_CONFIGURE = $$($(2)_DIR)/.stamp_configured
293 $(2)_TARGET_AUTORECONF = $$($(2)_DIR)/.stamp_autoconfigured
294 $(2)_TARGET_PATCH = $$($(2)_DIR)/.stamp_patched
295 $(2)_TARGET_EXTRACT = $$($(2)_DIR)/.stamp_extracted
296 $(2)_TARGET_SOURCE = $$($(2)_DIR)/.stamp_downloaded
297 $(2)_TARGET_UNINSTALL = $$($(2)_DIR)/.stamp_uninstalled
298 $(2)_TARGET_CLEAN = $$($(2)_DIR)/.stamp_cleaned
299 $(2)_TARGET_DIRCLEAN = $$($(2)_DIR)/.stamp_dircleaned
301 $(2)_HOOK_POST_BUILD = $$($(2)_DIR)/.stamp_hook_post_build
302 $(2)_HOOK_POST_INSTALL = $$($(2)_DIR)/.stamp_hook_post_install
304 # human-friendly targets and target sequencing
306 $(1)-install: $(1)-install-staging $(1)-install-target \
307 $$($(2)_HOOK_POST_INSTALL)
309 ifeq ($$($(2)_INSTALL_TARGET),YES)
310 $(1)-install-target: $(1)-build $$($(2)_TARGET_INSTALL_TARGET)
315 ifeq ($$($(2)_INSTALL_STAGING),YES)
316 $(1)-install-staging: $(1)-build $$($(2)_TARGET_INSTALL_STAGING)
318 $(1)-install-staging:
321 $(1)-build: $(1)-configure \
322 $$($(2)_TARGET_BUILD) \
323 $$($(2)_HOOK_POST_BUILD)
325 $(1)-configure: $(1)-autoreconf $$($(2)_TARGET_CONFIGURE)
327 ifeq ($$($(2)_AUTORECONF),YES)
328 $(1)-autoreconf: $(1)-patch $$($(2)_TARGET_AUTORECONF)
329 $(2)_DEPENDENCIES += host-automake host-autoconf host-libtool
331 $(1)-autoreconf: $(1)-patch
334 $(1)-patch: $(1)-extract $$($(2)_TARGET_PATCH)
336 $(1)-extract: $(1)-depends $$($(2)_TARGET_EXTRACT)
338 $(1)-depends: $(1)-source $$($(2)_DEPENDENCIES)
340 $(1)-source: $$($(2)_TARGET_SOURCE)
343 $(1)-uninstall: $(1)-configure $$($(2)_TARGET_UNINSTALL)
345 $(1)-clean: $$($(2)_TARGET_CLEAN)
347 $(1)-dirclean: $$($(2)_TARGET_DIRCLEAN)
349 # define the PKG variable for all targets, containing the
350 # uppercase package variable prefix
351 $$($(2)_TARGET_INSTALL_TARGET): PKG=$(2)
352 $$($(2)_TARGET_INSTALL_STAGING): PKG=$(2)
353 $$($(2)_TARGET_BUILD): PKG=$(2)
354 $$($(2)_TARGET_CONFIGURE): PKG=$(2)
355 $$($(2)_TARGET_AUTORECONF): PKG=$(2)
356 $$($(2)_TARGET_PATCH): PKG=$(2)
357 $$($(2)_TARGET_EXTRACT): PKG=$(2)
358 $$($(2)_TARGET_SOURCE): PKG=$(2)
359 $$($(2)_TARGET_UNINSTALL): PKG=$(2)
360 $$($(2)_TARGET_CLEAN): PKG=$(2)
361 $$($(2)_TARGET_DIRCLEAN): PKG=$(2)
362 $$($(2)_HOOK_POST_BUILD): PKG=$(2)
363 $$($(2)_HOOK_POST_INSTALL): PKG=$(2)
365 # define hook targets
366 # default hook behaviour: do nothing
367 $$($(2)_HOOK_POST_BUILD):
368 $$($(2)_HOOK_POST_INSTALL):
370 # add package to the general list if targets if requested by the buildroot
372 ifeq ($$(BR2_PACKAGE_$(2)),y)