source: trunk/make/Makefile.in @ 14530

Letzte Änderung dieser Datei seit 14530 war 14530, erstellt von er13 vor 11 Monaten

PKG_UNPACK macro:

  • add support for strip-components and include-filter features of UNPACK_TARBALL
Dateigröße: 34.6 KB
Zeile 
1MAKE_ENV=PATH=$(TARGET_PATH) $(FREETZ_LD_RUN_PATH)
2
3BUILD_FAIL_MSG:= Build failed.
4ifneq ($(strip $(FREETZ_VERBOSITY_LEVEL)),2)
5BUILD_FAIL_MSG += Please re-run make with verbose level set to 2 to see what's going on.
6endif
7
8SUBMAKE1=cmd() { $(MAKE_ENV) $(MAKE1) $(QUIET) "$$@" $(SILENT) || { $(call ERROR,1,$(BUILD_FAIL_MSG)) } }; $(call _ECHO_BUILD) cmd
9SUBMAKE=cmd() { $(MAKE_ENV) $(MAKE) $(QUIET) "$$@" $(SILENT) || { $(call ERROR,1,$(BUILD_FAIL_MSG)) } }; $(call _ECHO_BUILD) cmd
10CONFIGURE=conf_cmd() { ./configure $(QUIET) "$$$$@" $(SILENT) || { $(call ERROR,1,$(BUILD_FAIL_MSG)) } };
11AUTORECONF=autoreconf -f -i || { $(call ERROR,1,autoreconf failed) };
12
13HOSTCC:=gcc
14HOST_STRIP:=strip --strip-all -R .note -R .comment
15
16HOST_ARCH:=$(shell $(HOSTCC) -dumpmachine | sed -e s'/-.*//' \
17    -e 's/sparc.*/sparc/' \
18    -e 's/arm.*/arm/g' \
19    -e 's/m68k.*/m68k/' \
20    -e 's/ppc/powerpc/g' \
21    -e 's/v850.*/v850/g' \
22    -e 's/sh[234]/sh/' \
23    -e 's/mips-.*/mips/' \
24    -e 's/mipsel-.*/mipsel/' \
25    -e 's/cris.*/cris/' \
26    -e 's/i[3-9]86/i386/' \
27    )
28GNU_HOST_NAME:=$(HOST_ARCH)-pc-linux-gnu
29
30ifeq ($(strip $(FREETZ_TARGET_NLS)),y)
31DISABLE_NLS:=
32else
33DISABLE_NLS:=--disable-nls
34endif
35
36TARGET_CROSS:=$(call qstrip,$(FREETZ_TARGET_CROSS))
37KERNEL_CROSS:=$(call qstrip,$(FREETZ_KERNEL_CROSS))
38
39# TODO: investigate if the flags could/should be changed to the commented out ones
40# the current ones correspond to the flags used in Freetz up to r12843
41# binutils-2.25 require "-Wa,...", this however might break compilation of some packages (e.g. libffi)
42TARGET_CFLAGS_ARCH_CPU_TUNE := -march=$(call qstrip,$(FREETZ_GCC_TUNE)) -mtune=$(call qstrip,$(FREETZ_GCC_TUNE))
43TARGET_CFLAGS_FLOAT_ABI     := $(if $(call qstrip,$(FREETZ_GCC_FLOAT_ABI)),-m$(call qstrip,$(FREETZ_GCC_FLOAT_ABI))-float)
44#TARGET_CFLAGS_ARCH_CPU_TUNE := -march=$(call qstrip,$(FREETZ_GCC_ARCH)) -mtune=$(call qstrip,$(FREETZ_GCC_TUNE))
45#TARGET_CFLAGS_FLOAT_ABI     := $(if $(call qstrip,$(FREETZ_GCC_FLOAT_ABI)),-m$(call qstrip,$(FREETZ_GCC_FLOAT_ABI))-float -Wa,-m$(call qstrip,$(FREETZ_GCC_FLOAT_ABI))-float)
46ifneq ($(filter -march=% -mcpu=% -mtune=% -m%-float,$(call qstrip,$(FREETZ_TARGET_CFLAGS))),)
47$(error Please remove any CPU and architecture related flags (-march/-mcpu/-mtune/-m*-float) \
48    from target compiler flags (FREETZ_TARGET_CFLAGS variable in your .config). \
49    These flags are automatically set by freetz build environment now)
50endif
51TARGET_CFLAGS_LFS:=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
52TARGET_CFLAGS:=$(TARGET_CFLAGS_ARCH_CPU_TUNE) $(TARGET_CFLAGS_FLOAT_ABI) $(call qstrip,$(FREETZ_TARGET_CFLAGS)) $(TARGET_CFLAGS_LFS)
53
54FPIC:=-fPIC
55
56TARGET_SPECIFIC_SUBDIR:=target-$(TARGET_TOOLCHAIN_COMPILER)
57SOURCE_DIR:=$(SOURCE_DIR_ROOT)/$(TARGET_SPECIFIC_SUBDIR)
58PACKAGES_DIR:=$(PACKAGES_DIR_ROOT)/$(TARGET_SPECIFIC_SUBDIR)
59TARGET_SPECIFIC_ROOT_DIR:=$(PACKAGES_DIR)/root
60
61$(SOURCE_DIR) \
62$(PACKAGES_DIR):
63    @mkdir -p $@
64
65# If CONFIG_SITE is exported, it can cause errors in the host builds
66unexport CONFIG_SITE
67CONFIG_SITE:=$(FREETZ_BASE_DIR)/$(INCLUDE_DIR)/site/$(TARGET_ARCH_ENDIANNESS_DEPENDENT)-linux-uclibc
68
69TARGET_AR:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)ar
70TARGET_AS:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)as
71TARGET_CC:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)gcc
72TARGET_CXX:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)g++-wrapper
73TARGET_LD:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)ld
74TARGET_LDCONFIG:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)ldconfig
75TARGET_NM:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)nm
76TARGET_RANLIB:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)ranlib
77TARGET_READELF:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)readelf
78TARGET_STRIP:=$(TARGET_MAKE_PATH)/$(TARGET_CROSS)strip --remove-section={.comment,.note,.pdr}
79
80# Don't use TARGET_TOOLCHAIN_PATH here because it's not set
81TARGET_PATH="$(TARGET_MAKE_PATH):$(KERNEL_MAKE_PATH):$(PATH)"
82
83# s. uclibc-${version}/ldso/ldso/dl-elf.c::_dl_load_shared_library
84STANDARD_LIBRARY_DIRS:=/lib /usr/lib
85
86FREETZ_RPATH_SPACE_SEPARATED:=$(patsubst %/,%,$(subst :,$(_space),$(call qstrip,$(FREETZ_RPATH))))
87FREETZ_RPATH:=$(subst $(_space),:,$(FREETZ_RPATH_SPACE_SEPARATED))
88
89ifneq (,$(if $(MAKECMDGOALS),$(filter-out $(KCONFIG_TARGETS),$(MAKECMDGOALS)),do-validate-FREETZ_RPATH))
90# check if FREETZ_RPATH contains a valid value
91ifneq (1,$(words $(FREETZ_RPATH)))
92$(error FREETZ_RPATH (="$(FREETZ_RPATH)") must not be empty and must not contain spaces)
93endif
94$(foreach entry,$(FREETZ_RPATH_SPACE_SEPARATED), \
95$(if $(filter /%,$(entry)),,$(error FREETZ_RPATH (="$(FREETZ_RPATH)" contains invalid entry "$(entry)", each entry must be an absolute path))) \
96)
97ifneq (,$(filter     $(STANDARD_LIBRARY_DIRS),$(FREETZ_RPATH_SPACE_SEPARATED)))
98ifneq (,$(filter-out $(STANDARD_LIBRARY_DIRS),$(FREETZ_RPATH_SPACE_SEPARATED)))
99$(error FREETZ_RPATH (="$(FREETZ_RPATH)") contains both standard and non-standard search paths. This is NOT supported)
100endif
101endif
102ifeq (,$(filter-out $(STANDARD_LIBRARY_DIRS),$(FREETZ_RPATH_SPACE_SEPARATED)))
103$(info )
104$(warning FREETZ_RPATH (="$(FREETZ_RPATH)") contains only standard search paths. The only use-case for such a configuration (and this is the only reason we support it) is to create binaries using the Freetz toolchain and run them on a non-freetz'ed box.)
105$(info )
106endif
107endif
108
109FREETZ_LIBRARY_DIR:=$(firstword $(FREETZ_RPATH_SPACE_SEPARATED))
110FREETZ_LD_RUN_PATH:=$(if $(filter-out $(STANDARD_LIBRARY_DIRS),$(FREETZ_RPATH_SPACE_SEPARATED)),LD_RUN_PATH="$(FREETZ_RPATH)")
111MAKE_ENV+=FREETZ_LIBRARY_DIR="$(FREETZ_LIBRARY_DIR)"
112
113# commands to run before calling configure
114# each command has to be terminated by ';'
115TARGET_CONFIGURE_PRE_CMDS:=
116TARGET_CONFIGURE_PRE_CMDS += $(RM) config.{cache,status};
117
118# setup environment for configure
119TARGET_CONFIGURE_ENV:=
120TARGET_CONFIGURE_ENV += PATH=$(TARGET_PATH)
121TARGET_CONFIGURE_ENV += FREETZ_LIBRARY_DIR="$(FREETZ_LIBRARY_DIR)"
122
123# Set compiler/linker flags here, not in TARGET_CONFIGURE_OPTIONS,
124# because this way they do not disturb old configure scripts
125# (e.g. pjproject, OPIE)
126TARGET_CONFIGURE_ENV += CC="$(TARGET_CC)"
127TARGET_CONFIGURE_ENV += CXX="$(TARGET_CXX)"
128TARGET_CONFIGURE_ENV += CFLAGS="$(TARGET_CFLAGS)"
129TARGET_CONFIGURE_ENV += CXXFLAGS="$(TARGET_CFLAGS)"
130TARGET_CONFIGURE_ENV += LDFLAGS=""
131TARGET_CONFIGURE_ENV += PKG_CONFIG_PATH="$(TARGET_MAKE_PATH)/../lib/pkgconfig"
132TARGET_CONFIGURE_ENV += PKG_CONFIG_LIBDIR="$(TARGET_MAKE_PATH)/../lib/pkgconfig"
133
134CONFIG_CACHE_PATH := $(FREETZ_BASE_DIR)/$(SOURCE_DIR)/config.cache
135CONFIG_CACHE_BACKUP_DIR := $(FREETZ_BASE_DIR)/$(SOURCE_DIR)/_config.cache-backup
136# $1 optional suffix
137define BACKUP_CONFIG_CACHE
138if [ -e $(CONFIG_CACHE_PATH) ]; then mkdir -p $(CONFIG_CACHE_BACKUP_DIR); cp -a $(CONFIG_CACHE_PATH) $(CONFIG_CACHE_BACKUP_DIR)/config.cache-`date +%Y%m%d-%H%M%S`$(if $1,-$1,); fi;
139endef
140
141# Common options for configure
142TARGET_CONFIGURE_OPTIONS:=
143TARGET_CONFIGURE_OPTIONS += --cache-file=$(CONFIG_CACHE_PATH)
144TARGET_CONFIGURE_OPTIONS += --target=$(GNU_TARGET_NAME)
145TARGET_CONFIGURE_OPTIONS += --host=$(GNU_TARGET_NAME)
146TARGET_CONFIGURE_OPTIONS += --build=$(GNU_HOST_NAME)
147TARGET_CONFIGURE_OPTIONS += --program-prefix=""
148TARGET_CONFIGURE_OPTIONS += --program-suffix=""
149TARGET_CONFIGURE_OPTIONS += --prefix=/usr
150TARGET_CONFIGURE_OPTIONS += --exec-prefix=/usr
151TARGET_CONFIGURE_OPTIONS += --bindir=/usr/bin
152TARGET_CONFIGURE_OPTIONS += --datadir=/usr/share
153TARGET_CONFIGURE_OPTIONS += --includedir=/usr/include
154TARGET_CONFIGURE_OPTIONS += --infodir=/usr/share/info
155TARGET_CONFIGURE_OPTIONS += --libdir=/usr/lib
156TARGET_CONFIGURE_OPTIONS += --libexecdir=/usr/lib
157TARGET_CONFIGURE_OPTIONS += --localstatedir=/var
158TARGET_CONFIGURE_OPTIONS += --mandir=/usr/share/man
159TARGET_CONFIGURE_OPTIONS += --sbindir=/usr/sbin
160TARGET_CONFIGURE_OPTIONS += --sysconfdir=/etc
161TARGET_CONFIGURE_OPTIONS += --with-gnu-ld
162TARGET_CONFIGURE_OPTIONS += $(DISABLE_NLS)
163
164DL_SITE:=$(call qstrip,$(FREETZ_DL_SITE))
165DL_SOURCE:=$(call qstrip,$(FREETZ_DL_SOURCE))
166DL_SOURCE_MD5:=$(call qstrip,$(FREETZ_DL_SOURCE_MD5))
167export DL_SOURCE_ID=$(shell echo $(DL_SOURCE) | tools/imagename2id)
168
169ifneq ($(strip $(FREETZ_DL_SOURCE_CONTAINER)),)
170DL_SOURCE_CONTAINER:=$(call qstrip,$(FREETZ_DL_SOURCE_CONTAINER))
171DL_SOURCE_CONTAINER_MD5:=$(call qstrip,$(FREETZ_DL_SOURCE_CONTAINER_MD5))
172DL_SOURCE_CONTAINER_SUFFIX:=$(suffix $(DL_SOURCE_CONTAINER))
173endif
174
175ifneq ($(strip $(FREETZ_DL_SOURCE2)),)
176DL_SITE2:=$(call qstrip,$(FREETZ_DL_SITE2))
177DL_SOURCE2:=$(call qstrip,$(FREETZ_DL_SOURCE2))
178DL_SOURCE2_MD5:=$(call qstrip,$(FREETZ_DL_SOURCE2_MD5))
179endif
180
181ifneq ($(strip $(FREETZ_DL_SOURCE2_CONTAINER)),)
182DL_SOURCE2_CONTAINER:=$(call qstrip,$(FREETZ_DL_SOURCE2_CONTAINER))
183DL_SOURCE2_CONTAINER_MD5:=$(call qstrip,$(FREETZ_DL_SOURCE2_CONTAINER_MD5))
184DL_SOURCE2_CONTAINER_SUFFIX:=$(suffix $(DL_SOURCE2_CONTAINER))
185endif
186
187ifneq ($(strip $(FREETZ_DL_SOURCE3)),)
188DL_SITE3:=$(call qstrip,$(FREETZ_DL_SITE3))
189DL_SOURCE3:=$(call qstrip,$(FREETZ_DL_SOURCE3))
190DL_SOURCE3_MD5:=$(call qstrip,$(FREETZ_DL_SOURCE3_MD5))
191endif
192
193ifneq ($(strip $(FREETZ_DL_SOURCE3_CONTAINER)),)
194DL_SOURCE3_CONTAINER:=$(call qstrip,$(FREETZ_DL_SOURCE3_CONTAINER))
195DL_SOURCE3_CONTAINER_MD5:=$(call qstrip,$(FREETZ_DL_SOURCE3_CONTAINER_MD5))
196DL_SOURCE3_CONTAINER_SUFFIX:=$(suffix $(DL_SOURCE3_CONTAINER))
197endif
198
199### Convenience macros
200# Since the makefiles for the packages contain many similar parts, we define some macros to simplify
201# the creation and maintenance of the makefiles.
202# macro names containing _INT are for internal use only and should not be called outside of this file
203# For details of the required targets, see the documentation in README.Makefiles
204
205define SELECTED_SUBOPTIONS__INT
206$(strip \
207    $(foreach suboption, $(1), \
208        $(if \
209            $(or \
210                $(FREETZ_$(3)_$(if $(2),$(2)_,)$(call LEGAL_VARNAME,$(suboption))), \
211                $(FREETZ_$(3)_$(if $(2),$(2)_,)$(call TOUPPER_NAME,$(suboption))) \
212            ), \
213            $(suboption) \
214        ) \
215    ) \
216)
217endef
218# For each SUFFIX from a given list of menuconfig-option-suffixes evaluates FREETZ_PACKAGE_$(PKG)_$(OPTIONAL_INFIX)_$(SUFFIX) variable
219# and in case it evaluates to non-empty value (i.e. selected) appends the suffix to the list being returned.
220# $(1) - list of package suboptions (suffixes) to be evaluated
221# $(2) - optional infix
222PKG_SELECTED_SUBOPTIONS = $(call SELECTED_SUBOPTIONS__INT,$(1),$(2),PACKAGE_$(PKG))
223# For each SUFFIX from a given list of menuconfig-option-suffixes evaluates FREETZ_LIB_lib$(pkg)_$(OPTIONAL_INFIX)_$(SUFFIX) variable
224# and in case it evaluates to non-empty value (i.e. selected) appends the suffix to the list being returned.
225# $(1) - list of package suboptions (suffixes) to be evaluated
226# $(2) - optional infix
227LIB_SELECTED_SUBOPTIONS = $(call SELECTED_SUBOPTIONS__INT,$(1),$(2),LIB_lib$(patsubst lib%,%,$(pkg)))
228
229# SED helper macros
230# single quote sign within sed script quoted with single quote sign
231_SQ:='"'"'
232# double quote sign within sed script quoted with double quote sign
233_DQ:="'"'"
234
235# PKG_EDIT_CONFIG
236# update a config file
237#   $(1) = list of assignments CONFIG_VAR=value
238PKG_EDIT_CONFIG__INT0 = -e 's%^(\# )?($1)[ =].*%$(if $(patsubst n,,$2),\2=$2,\# \2 is not set)%g'
239PKG_EDIT_CONFIG__INT1 = $(call PKG_EDIT_CONFIG__INT0,$(word 1,$(subst =, ,$1)),$(word 2,$(subst =, ,$1)))
240PKG_EDIT_CONFIG = $(SED) -i -r $(foreach asg,$1,$(call PKG_EDIT_CONFIG__INT1,$(asg)))
241
242# PKG_FIX_LIBTOOL_LA
243#   fix directories is libtool .la files and .pc files
244PKG_FIX_LIBTOOL_LA__INT = -e "s,^($1=)(['$(_DQ)]?)([^'$(_DQ)]*)(\2)$$,\1\2$(TARGET_TOOLCHAIN_STAGING_DIR)\3\4,g"
245PKG_FIX_LIBTOOL_LA__INT_DEPENDENCY_LIBS = -e "/^dependency_libs/s,[ \t],  ,g;s,([ '])((/usr)?/lib/[^ /]+[.]la)([ ']),\1$(TARGET_TOOLCHAIN_STAGING_DIR)\2\4,g;s, +, ,g"
246PKG_FIX_LIBTOOL_LA = $(SED) -i -r \
247    $(foreach key,$(if $(strip $1),$(strip $1),libdir includedir prefix exec_prefix),$(call PKG_FIX_LIBTOOL_LA__INT,$(key))) \
248    $(if $(strip $1),,$(PKG_FIX_LIBTOOL_LA__INT_DEPENDENCY_LIBS))
249
250# Fix configure and/or libtool scripts to prevent RPATH from being hardcoded.
251# Based on ideas provided on http://wiki.debian.org/RpathIssue.
252#
253# Whether RPATH has been hardcoded or not could be tested using the following command:
254#   readelf -d <binary/library> | grep RPATH
255#
256# The macro is intended to be used in $(PKG)_CONFIGURE_PRE_CMDS variable in the following way:
257# $(PKG)_CONFIGURE_PRE_CMDS += $(call PKG_PREVENT_RPATH_HARDCODING,./configure)
258#
259# Replace runpath_var=$runpath_var with runpath_var=
260PKG_FIX_RUNPATH_VAR__INT = -e "s|(runpath_var=)[$$$$]runpath_var|\1|g"
261#
262# Replace hardcode_into_libs=something with hardcode_into_libs=no
263PKG_FIX_HARDCODE_INTO_LIBS__INT = -e "s|(hardcode_into_libs=).+$$$$|\1no|g"
264#
265# In all lines matching the pattern hardcode_libdir_flag_spec[_A-Za-z0-9]*=
266# replace
267#   ${wl}-rpath,$libdir
268#   ${wl}--rpath,$libdir
269#   ${wl}-rpath ${wl}$libdir
270#   ${wl}--rpath ${wl}$libdir
271# with
272#   -D__SOMETHING_NON_EMPTY_TO_FOOL_LIBTOOL__
273PKG_FIX_HARDCODE_LIBDIR_FLAG_SPEC__INT1 = -e '/hardcode_libdir_flag_spec[_A-Za-z0-9]*=/s/[$$$$][{]wl[}]-?-rpath(,| [$$$$][{]wl[}])[$$$$]libdir/-D__SOMETHING_NON_EMPTY_TO_FOOL_LIBTOOL__/g'
274# Replace
275#   hardcode_libdir_flag_spec(_ld)?=$lt_hardcode_libdir_flag_spec...
276#   or
277#   hardcode_libdir_flag_spec(_ld)?=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec..., $1)
278# with
279#   hardcode_libdir_flag_spec(_ld)?=
280PKG_FIX_HARDCODE_LIBDIR_FLAG_SPEC__INT2 = -e 's/(hardcode_libdir_flag_spec(_ld)?=)[$$$$]lt_([[][]]_LT_AC_TAGVAR[(])?hardcode_libdir_flag_spec[_A-Za-z0-9]*(, *[$$$$]1[)])?/\1/g'
281#
282PKG_PREVENT_RPATH_HARDCODING__INT = \
283    cp -a $1 $1.before_rpath_fix; \
284    $(SED) -i -r \
285        $(PKG_FIX_RUNPATH_VAR__INT) \
286        $(PKG_FIX_HARDCODE_INTO_LIBS__INT) \
287        $(PKG_FIX_HARDCODE_LIBDIR_FLAG_SPEC__INT1) \
288        $(PKG_FIX_HARDCODE_LIBDIR_FLAG_SPEC__INT2) \
289    $1;
290PKG_PREVENT_RPATH_HARDCODING = $(foreach f,$1,$(call PKG_PREVENT_RPATH_HARDCODING__INT,$(f)))
291# 1st level PKG_PREVENT_RPATH_HARDCODING
292PKG_PREVENT_RPATH_HARDCODING1 = $(subst $$$$,$$,$(call PKG_PREVENT_RPATH_HARDCODING,$1))
293
294# Changes a typical Makefile.in line from "FOO = @FOO@" to "FOO = @FOO@ $(EXTRA_FOO)", i.e. adds $(EXTRA_FOO) at the end
295# $1 - variable name or variable names separated by |, i.e. regex OR pattern
296# $2 - optional $($(PKG)_DIR) subdir
297PKG_ADD_EXTRA_FLAGS = find $(abspath $($(PKG)_DIR))$(if $(strip $2),/$(strip $2)) -name Makefile.in -type f -exec $(SED) -i -r -e 's,^($(strip $1))[ \t]*=[ \t]*@\1@,& $$$$(EXTRA_\1),' \{\} \+;
298
299# Change prefix of all $3_cv_* variables in $1 to $(pkg).
300#  $1 is allowed to be a space separated list of variables or a ready to be used sed pattern
301#  $2 (optional) is the file to be patched, default ./$($(PKG)_BUILD_SUBDIR)/configure
302#  $3 (optional) is the prefix of the variables to rename, default ac
303PKG_MAKE_AC_VARIABLES_PACKAGE_SPECIFIC = \
304    $(SED) -i -r -e 's/$(if $(strip $3),$(strip $3),ac)(_cv(_('"$(shell echo "$(strip $1)" | tr " " "|")"')))/'"$(shell echo $(pkg) | tr '[\-\+]' '[_x]')"'\2/g' \
305    $(if $(strip $2),$(strip $2),./$(if $(strip $($(PKG)_BUILD_SUBDIR)),$(strip $($(PKG)_BUILD_SUBDIR))/)configure);
306
307# Usage:
308# $(call REPLACE_LIBTOOL,$1,$2,$3)
309# $1 - Relative path to libtool-script, usually ./ (NB: libtool is often generated by configure, i.e. doesn't exist in the tarball)
310# $2 - Relative path to ltmain.sh, varies from package to package. The following locations are the most often used ones:
311#      ./, ./build/, ./builds/unix/, ./auto/, ./autoconf/, ./conftools/
312# $3 - Relative path to libtool.m4, varies from package to package. The following locations are the most often used ones:
313#      ./, ./m4/, ./build/, ./conftools/
314# Each parameter defaults to ./ if omitted
315# NB: all libtool-related macros are heavily based on the openwrt macros provided in autotools.mk
316define REPLACE_FILE_WITH_SYMLINK
317if [ -f "$(abspath $($(PKG)_DIR)/$(3)/$(1))" -a -e "$(2)/$(if $(4),$(4),$(1))" ]; then \
318    $(call MESSAGE, Replacing $(3)/$(if $(4),$(4),$(1)) with symlink to $(2)/$(if $(4),$(4),$(1))); \
319    $(RM) "$(abspath $($(PKG)_DIR)/$(3)/$(1))"; \
320    ln -s "$(2)/$(if $(4),$(4),$(1))" "$(abspath $($(PKG)_DIR)/$(3)/$(1))"; \
321fi;
322endef
323define REPLACE_LIBTOOL__INT
324$(call REPLACE_FILE_WITH_SYMLINK,libtool,$(TARGET_TOOLCHAIN_STAGING_DIR)/usr/bin,$(if $(1),$(1),.)) \
325$(call REPLACE_FILE_WITH_SYMLINK,ltmain.sh,$(TARGET_TOOLCHAIN_STAGING_DIR)/usr/share/libtool,$(if $(2),$(2),.)) \
326$(call REPLACE_FILE_WITH_SYMLINK,libtool.m4,$(TARGET_TOOLCHAIN_STAGING_DIR)/usr/share/aclocal,$(if $(3),$(3),.))
327endef
328define REPLACE_LIBTOOL__INT2
329$(PKG)_CONFIGURE_PRE_CMDS += $(call REPLACE_LIBTOOL__INT,$(1),$(2),$(3))
330$(PKG)_CONFIGURE_POST_CMDS += $(call REPLACE_LIBTOOL__INT,$(1),$(2),$(3))
331endef
332define REPLACE_LIBTOOL
333$(eval $(call REPLACE_LIBTOOL__INT2,$(1),$(2),$(3)))
334endef
335
336define INSTALL_BINARY_STRIP
337$(INSTALL_FILE) \
338$(TARGET_STRIP) $@;
339endef
340define INSTALL_LIBRARY__INT
341chmod 755 $<; \
342mkdir -p $(dir $@); \
343$(RM) $(addprefix $(dir $@),$(call LIBRARY_NAME_TO_SHELL_PATTERN,$(notdir $@),$(if $(1),-$(1)),$(2))); \
344cp -a $(addprefix $(dir $<),$(call LIBRARY_NAME_TO_SHELL_PATTERN,$(notdir $<),$(1),$(2))) $(dir $@);
345endef
346INSTALL_LIBRARY = $(call INSTALL_LIBRARY__INT)
347INSTALL_LIBRARY_INCLUDE_STATIC = $(call INSTALL_LIBRARY__INT,,a)
348INSTALL_LIBRARY_WILDCARD_BEFORE_SO = $(call INSTALL_LIBRARY__INT,*)
349INSTALL_LIBRARY_WILDCARD_BEFORE_SO_INCLUDE_STATIC = $(call INSTALL_LIBRARY__INT,*,a)
350define INSTALL_LIBRARY_STRIP
351$(INSTALL_LIBRARY) \
352$(TARGET_STRIP) $@;
353endef
354define INSTALL_LIBRARY_STRIP_WILDCARD_BEFORE_SO
355$(INSTALL_LIBRARY_WILDCARD_BEFORE_SO) \
356$(TARGET_STRIP) $@;
357endef
358
359# $1 - binary to be installed
360# $2 - directory binary to be installed in
361# $3 (optional) - DESTDIR binary to be installed in, defaults to $(PKG)_DEST_DIR if omitted
362define INSTALL_BINARY_STRIP_RULE
363$(if $(strip $(3)),$(strip $(3)),$($(PKG)_DEST_DIR))$(strip $(2))/$(notdir $(strip $(1))): $(strip $(1))
364    $(value INSTALL_BINARY_STRIP)
365endef
366
367# $1 - library to be installed
368# $2 - directory library to be installed in
369# $3 (optional) - DESTDIR library to be installed in, defaults to $(PKG)_DEST_DIR if omitted
370define INSTALL_LIBRARY_STRIP_RULE
371$(if $(strip $(3)),$(strip $(3)),$($(PKG)_DEST_DIR))$(strip $(2))/$(notdir $(strip $(1))): $(strip $(1))
372    $(value INSTALL_LIBRARY_STRIP)
373endef
374
375define REMOVE_DOC_NLS_DIRS
376$(if $(strip $(1)),$(RM) -r $(addprefix $(strip $(1)),$(foreach p,/ /usr /share /usr/share,$(foreach d,info man doc locale,$(subst //,/,$(p)/$(d))))))
377endef
378
379# We want build output like:
380# "---> package/lynx: downloading... preparing... configuring... building... done."
381# Actually there are two problems:
382# 1. We can't use _ECHO_START in $(SUBMAKE) context.
383# 2. Dot files are deleted within every package. But once at start would be enough.
384# Usage:
385# $(call _ECHO,text)
386# $(call _ECHO_BUILD)
387ECHO_ITEM_START:=$(SOURCE_DIR_ROOT)/.echo_item_start
388ECHO_ITEM_BUILD:=$(SOURCE_DIR_ROOT)/.echo_item_build
389
390define _ECHO_START
391    echo -n "---> "; \
392    case "$(PKG_TYPE)" in \
393        BIN)    echo -n "package/$(pkg): " ;; \
394        LIB)    echo -n "library/$(pkg): " ;; \
395        TOOL)   echo -n "tool/$(pkg): " ;; \
396        *)  echo -n "kernel: " ;; \
397    esac; \
398    $(RM) $(ECHO_ITEM_BUILD); \
399    touch $(ECHO_ITEM_START);
400endef
401
402define _ECHO
403    if [ ! -e $(ECHO_ITEM_START) ]; then \
404        $(call _ECHO_START) \
405    fi; \
406    echo -n "$(1)";
407endef
408
409define _ECHO_BUILD
410    if [ -e $(ECHO_ITEM_START) -a ! -e $(ECHO_ITEM_BUILD) ]; then \
411        echo -n "building... "; \
412        touch $(ECHO_ITEM_BUILD); \
413    fi;
414endef
415
416define _ECHO_DONE
417    if [ -e $(ECHO_ITEM_START) ]; then \
418        echo "done."; \
419    fi; \
420    $(RM) $(ECHO_ITEM_START) $(ECHO_ITEM_BUILD);
421endef
422
423### PKG_INIT - initialise package. See also PKG_FINISH.
424
425# Stage 1: initialise package names
426#   $(1) = version (mandatory)
427#   $(2) = lower-case package name (optional)
428#   $(3) = upper-case package name (optional)
429define PKG_INIT__INT
430#PKG_MAKEFILE:=$(lastword $(MAKEFILE_LIST))
431PKG_MAKEFILE:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
432PKG_BASENAME:=$(basename $(notdir $(PKG_MAKEFILE)))
433$(if $(strip $1),,$(error Undefined version for PKG_INIT in $(PKG_MAKEFILE)))
434pkg:=$(if $(strip $2),$(strip $2),$(PKG_BASENAME))
435PKG:=$(if $(strip $3),$(strip $3),$(call TOUPPER_NAME,$(pkg)))
436ALL_PACKAGES+=$(pkg)
437#
438$(PKG)_VERSION:=$(strip $1)
439#
440$(PKG)_BUILD_PREREQ:=
441$(PKG)_BUILD_PREREQ_HINT:=
442$(PKG)_DEPENDS_ON:=
443$(PKG)_HOST_DEPENDS_ON:=
444#
445$(PKG)_REBUILD_SUBOPTS=FREETZ_RPATH
446#
447$(PKG)_SOURCE_DIR:=$(SOURCE_DIR)
448$(PKG)_DIR:=$($(PKG)_SOURCE_DIR)/$(pkg)-$($(PKG)_VERSION)
449#
450$(PKG)_TARBALL_STRIP_COMPONENTS:=1
451$(PKG)_TARBALL_INCLUDE_FILTER:=
452#
453$(PKG)_EXCLUDED:=
454#
455$(PKG)_CONFIGURE_DEFOPTS:=y
456#
457# $(pkg)-precompiled--int must be the first target, it will depend on DEPENDS_ON
458$(pkg)-precompiled: $(pkg)-precompiled--int $(pkg)-clean-echo-item $(pkg)
459$(pkg)-clean-echo-item:
460    @$(RM) $(ECHO_ITEM_START) $(ECHO_ITEM_BUILD)
461.PHONY: $(pkg)-clean-echo-item $(pkg)-precompiled $(pkg)-precompiled--int $(pkg)
462endef
463
464# Stage 2a: initialise other package-specific variables for binary packages
465define PKG_INIT_BIN__INT
466PKG_TYPE:=BIN
467# level 99 for packages that are not actually started
468$(PKG)_STARTLEVEL=99
469$(PKG)_MAKE_DIR:=$(MAKE_DIR)/$(pkg)
470$(PKG)_TARGET_DIR:=$(PACKAGES_DIR)/$(pkg)-$($(PKG)_VERSION)
471$(PKG)_TARGET_LIBDIR:=$(TARGET_SPECIFIC_ROOT_DIR)$(FREETZ_LIBRARY_DIR)
472$(PKG)_DEST_DIR:=$($(PKG)_TARGET_DIR)/root
473$(PKG)_DEST_LIBDIR:=$($(PKG)_TARGET_DIR)/root$(FREETZ_LIBRARY_DIR)
474$(PKG)_CLEAN_TARGET_DIR__INT:=$(RM) -r $($(PKG)_TARGET_DIR); $(RM) $(PACKAGES_DIR)/.$(pkg) $(PACKAGES_DIR)/.$(pkg)-$($(PKG)_VERSION);
475$(pkg)-precompiled $(pkg): | $(PKG)_TARGET_DIR
476endef
477
478# Stage 2b: initialise other package-specific variables for library packages
479define PKG_INIT_LIB__INT
480PKG_TYPE:=LIB
481$(PKG)_MAKE_DIR:=$(MAKE_DIR)/libs/$(pkg)
482$(PKG)_TARGET_DIR:=$(TARGET_SPECIFIC_ROOT_DIR)$(FREETZ_LIBRARY_DIR)
483$(PKG)_TARGET_LIBDIR:=$($(PKG)_TARGET_DIR)
484$(PKG)_DEST_DIR:=$(TARGET_SPECIFIC_ROOT_DIR)
485endef
486
487# Stage 3: Common definitions after BIN/LIB specific definitions
488define PKG_INIT__INT3
489$(PKG)_DEST_BIN:=$($(PKG)_DEST_DIR)/bin
490$(PKG)_DEST_SBIN:=$($(PKG)_DEST_DIR)/sbin
491$(PKG)_DEST_LIB:=$($(PKG)_DEST_DIR)/lib
492$(PKG)_DEST_USR_BIN:=$($(PKG)_DEST_DIR)/usr/bin
493$(PKG)_DEST_USR_SBIN:=$($(PKG)_DEST_DIR)/usr/sbin
494$(PKG)_DEST_USR_LIB:=$($(PKG)_DEST_DIR)/usr/lib
495$(PKG)_CLEAN_STAGING_DIR__INT:=$(MAKE_ENV) $(MAKE) --quiet --ignore-errors $(pkg)-clean >/dev/null 2>&1;
496endef
497
498define PKG_INIT_BIN__INTV
499$(value PKG_INIT__INT)
500$(value PKG_INIT_BIN__INT)
501$(value PKG_INIT__INT3)
502endef
503# Call & evaluate stages 1,2a,3 for binary packages
504define PKG_INIT_BIN
505$(eval $(call PKG_INIT_BIN__INTV,$1,$2,$3))
506endef
507
508define PKG_INIT_LIB__INTV
509$(value PKG_INIT__INT)
510$(value PKG_INIT_LIB__INT)
511$(value PKG_INIT__INT3)
512endef
513# Call & evaluate stages 1,2b,3 for library packages
514define PKG_INIT_LIB
515$(eval $(call PKG_INIT_LIB__INTV,$1,$2,$3))
516endef
517
518# PKG_ADD_BIN
519#  $1 PKG FREETZ_PACKAGE_ Config Symbol
520#  $2 pkg Name (optional)
521define PKG_ADD_BIN__INT
522ifeq ($(FREETZ_PACKAGE_$1),y)
523PACKAGES+=$(if $(strip $2),$2,$(pkg))
524endif
525endef
526define PKG_ADD_BIN
527$(eval $(call PKG_ADD_BIN__INT,$1,$2))
528endef
529
530# PKG_ADD_LIB
531#  $1 PKG FREETZ_LIB_ Config Symbol
532#  $2 pkg Name (optional)
533define PKG_ADD_LIB__INT
534ifeq ($(FREETZ_LIB_$1),y)
535LIBS+=$(if $(strip $2),$2,$(pkg))
536endif
537endef
538define PKG_ADD_LIB
539$(eval $(call PKG_ADD_LIB__INT,$1,$2))
540endef
541
542### PKG_FINISH - package finalisation
543
544# Finalise binary packages
545define PKG_FINISH_BIN__INT
546$(PKG)_TARGET_DIR:
547    @mkdir -p $($(PKG)_TARGET_DIR)
548.PHONY: $(PKG)_TARGET_DIR
549
550# create marker containing package version
551$(PACKAGES_DIR)/.$(pkg): | $(PACKAGES_DIR)
552    @echo "$($(PKG)_VERSION)" > $$@
553
554# copy files under make/$(pkg)/files to the package target dir
555$(PACKAGES_DIR)/.$(pkg)-$($(PKG)_VERSION): | $(PACKAGES_DIR)
556    mkdir -p $($(PKG)_TARGET_DIR)/root
557    if test -d $($(PKG)_MAKE_DIR)/files; then \
558        $(call COPY_USING_TAR,$($(PKG)_MAKE_DIR)/files,$($(PKG)_TARGET_DIR)) \
559    fi
560    @touch $$@
561
562$(pkg) $(pkg)-precompiled: $(PACKAGES_DIR)/.$(pkg) $(PACKAGES_DIR)/.$(pkg)-$($(PKG)_VERSION)
563
564$($(PKG)_TARGET_DIR)/.exclude: $(TOPDIR)/.config | $(PKG)_TARGET_DIR
565    @$(call write-list-to-file,$(patsubst /%,%,$(patsubst $($(PKG)_DEST_DIR)/%,%,$(strip $($(PKG)_EXCLUDED)))),$$@)
566
567$(pkg): $($(PKG)_TARGET_DIR)/.exclude
568
569$(PKG_LIST)
570$(call PKG_ADD_BIN__INT,$(PKG))
571endef
572
573# Finalise library packages
574define PKG_FINISH_LIB__INT
575endef
576
577# check for changed suboptions, should only be called if $(PKG)_REBUILD_SUBOPTS is defined
578define PKG_FINISH_CHECK_REBUILD_SUBOPTS__INT1
579$(PKG)_FREETZ_CONFIG_FILE:=$(FREETZ_BASE_DIR)/$(SOURCE_DIR)/.$(pkg)_config
580endef
581define PKG_FINISH_CHECK_REBUILD_SUBOPTS__INT2
582$($(PKG)_FREETZ_CONFIG_FILE): $(TOPDIR)/.config | $(SOURCE_DIR)
583    @($(foreach OPT,$($(PKG)_REBUILD_SUBOPTS),echo "$(if $($(OPT)),$(OPT)=$($(OPT)),$(_hash) $(OPT) is not set)";):) > $($(PKG)_FREETZ_CONFIG_FILE).temp
584    @if ! diff -q $($(PKG)_FREETZ_CONFIG_FILE).temp $($(PKG)_FREETZ_CONFIG_FILE) 2>/dev/null $(SILENT); then \
585        $(RM) -r $($(PKG)_DIR); \
586        $($(PKG)_CLEAN_TARGET_DIR__INT) \
587        mv $($(PKG)_FREETZ_CONFIG_FILE).temp $($(PKG)_FREETZ_CONFIG_FILE); \
588    else \
589        $(RM) $($(PKG)_FREETZ_CONFIG_FILE).temp; \
590    fi
591$(pkg)-build-prereq: $($(PKG)_FREETZ_CONFIG_FILE)
592endef
593
594# Finalise packages (general functionality + call to type specifics)
595define PKG_FINISH__INT
596$(pkg)-precompiled--int: $(pkg)-build-prereq $(TOOLCHAIN) $($(PKG)_HOST_DEPENDS_ON) $(patsubst %,%-precompiled,$($(PKG)_DEPENDS_ON))
597$(pkg)-precompiled:
598    @$(call _ECHO_DONE)
599
600.PHONY: $(pkg)-build-prereq
601$(pkg)-build-prereq: $($(PKG)_DIR)/.build-prereq-checked
602$($(PKG)_DIR)/.build-prereq-checked:
603ifneq ($($(PKG)_BUILD_PREREQ),)
604    @MISSING_PREREQ=""; \
605    for fv in $($(PKG)_BUILD_PREREQ); do \
606        f=$$$$(echo $$$$fv | cut -d ':' -f 1); \
607        v=$$$$(echo $$$$fv | cut -d ':' -sf 2 | sed -e 's,[.],[.],g'); \
608        if ! which $$$$f >/dev/null 2>&1; then \
609            MISSING_PREREQ="$$$$MISSING_PREREQ $$$$f"; \
610        elif [ -n "$$$$v" ] && ! $$$$f --version 2>&1 | grep -q "$$$$v"; then \
611            MISSING_PREREQ="$$$$MISSING_PREREQ $$$$fv"; \
612        fi; \
613    done; \
614    if [ -n "$$$$MISSING_PREREQ" ]; then \
615        echo -n -e "$(_Y)"; \
616        echo -e \
617            "ERROR: The following commands/packages required for building the $(pkg)-package are missing on your system:" \
618            `echo $$$$MISSING_PREREQ | sed -e 's| |, |g'`; \
619        if [ -n "$(strip $($(PKG)_BUILD_PREREQ_HINT))" ]; then \
620            echo "$($(PKG)_BUILD_PREREQ_HINT)"; \
621        fi; \
622        echo -n -e "$(_N)"; \
623        exit 1; \
624    fi;
625endif
626    @mkdir -p $$(dir $$@); touch $$@;
627
628$(pkg)-dirclean--int:
629    $(RM) -r $($(PKG)_DIR)
630    $($(PKG)_CLEAN_TARGET_DIR__INT)
631#   $($(PKG)_CLEAN_STAGING_DIR__INT)
632
633$(pkg)-dirclean: $(pkg)-dirclean--int
634$(pkg)-distclean: $(pkg)-dirclean $(pkg)-clean $(pkg)-uninstall
635.PHONY: $(pkg)-dirclean $(pkg)-dirclean--int $(pkg)-distclean $(pkg)-clean $(pkg)-uninstall
636
637PKG:=
638PKG_TYPE:=
639PKG_MAKEFILE:=
640PKG_BASENAME:=
641pkg:=
642endef
643
644PKG_FINISH=$(eval $(PKG_FINISH_$(PKG_TYPE)__INT))
645PKG_FINISH+=$(if $($(PKG)_REBUILD_SUBOPTS),$(eval $(PKG_FINISH_CHECK_REBUILD_SUBOPTS__INT1))$(eval $(PKG_FINISH_CHECK_REBUILD_SUBOPTS__INT2)))
646PKG_FINISH+=$(eval $(PKG_FINISH__INT))
647
648### PKG_SOURCE_DOWNLOAD - download source packages
649
650define PKG_SOURCE_DOWNLOAD__INT
651NON_LOCALSOURCE_PACKAGES+=$(pkg)
652$(DL_DIR)/$($(PKG)_SOURCE): | $(DL_DIR)
653    $(call _ECHO,downloading... )
654    @if [ -e $(MIRROR_DIR)/$($(PKG)_SOURCE) ]; then \
655        $(call MESSAGE, Found $($(PKG)_SOURCE) in $(MIRROR_DIR), creating hard link); \
656        ln $(MIRROR_DIR)/$($(PKG)_SOURCE) $(DL_DIR); \
657    else \
658        $(DL_TOOL) \
659            $(DL_DIR) \
660            $(if $($(PKG)_SOURCE_DOWNLOAD_NAME),$($(PKG)_SOURCE_DOWNLOAD_NAME),$($(PKG)_SOURCE)) \
661            $($(PKG)_SITE) \
662            $(or $($(PKG)_SOURCE_SHA512),$($(PKG)_SOURCE_SHA256),$($(PKG)_SOURCE_SHA1),$($(PKG)_SOURCE_MD5)) \
663            $(SILENT) \
664            $(if $($(PKG)_SOURCE_DOWNLOAD_NAME),&& mv -f $(DL_DIR)/$($(PKG)_SOURCE_DOWNLOAD_NAME) $(DL_DIR)/$($(PKG)_SOURCE)); \
665    fi
666
667$(pkg)-download: $(DL_DIR)/$($(PKG)_SOURCE)
668
669$(MIRROR_DIR)/$($(PKG)_SOURCE): | $(MIRROR_DIR)
670    @if [ -e $(DL_DIR)/$($(PKG)_SOURCE) ]; then \
671        $(call MESSAGE, Found $($(PKG)_SOURCE) in $(DL_DIR), creating hard link); \
672        ln $(DL_DIR)/$($(PKG)_SOURCE) $(MIRROR_DIR); \
673    else \
674        $(DL_TOOL) \
675            $(MIRROR_DIR) \
676            $(if $($(PKG)_SOURCE_DOWNLOAD_NAME),$($(PKG)_SOURCE_DOWNLOAD_NAME),$($(PKG)_SOURCE)) \
677            $($(PKG)_SITE) \
678            $(or $($(PKG)_SOURCE_SHA512),$($(PKG)_SOURCE_SHA256),$($(PKG)_SOURCE_SHA1),$($(PKG)_SOURCE_MD5)) \
679            $(SILENT) \
680            $(if $($(PKG)_SOURCE_DOWNLOAD_NAME),&& mv -f $(DL_DIR)/$($(PKG)_SOURCE_DOWNLOAD_NAME) $(DL_DIR)/$($(PKG)_SOURCE)); \
681    fi
682
683$(pkg)-download-mirror: $(MIRROR_DIR)/$($(PKG)_SOURCE)
684
685$(pkg)-check-download:
686    @echo -n "Checking download for package $(pkg)..."
687    @if $(DL_TOOL) check $($(PKG)_SOURCE) $($(PKG)_SITE); then \
688        echo "ok."; \
689    else \
690        echo "ERROR: NOT FOUND!"; \
691    fi
692
693.PHONY: $(pkg)-download $(pkg)-check-download $(pkg)-download-mirror
694endef
695PKG_SOURCE_DOWNLOAD=$(eval $(PKG_SOURCE_DOWNLOAD__INT))
696
697
698### PKG_UNPACK - unpack source archive & apply patches
699# Unpack, without patch, but only if source package is defined
700define PKG_UNPACK
701    $(if $($(PKG)_SOURCE), \
702        $(strip \
703            mkdir -p $($(PKG)_DIR); \
704            $(call \
705                $(if $($(PKG)_CUSTOM_UNPACK),$(PKG)_CUSTOM_UNPACK,UNPACK_TARBALL), \
706                $(DL_DIR)/$($(PKG)_SOURCE), \
707                $($(PKG)_DIR), \
708                $(strip $(filter-out 0,$($(PKG)_TARBALL_STRIP_COMPONENTS))), \
709                $(strip $($(PKG)_TARBALL_INCLUDE_FILTER)) \
710            ) \
711        ) \
712    )
713endef
714
715### PKG_PATCH - apply patches
716define PKG_PATCH
717    $(subst $(_dollar),$(_dollar)$(_dollar), \
718        $(call \
719            APPLY_PATCHES, \
720            $($(PKG)_MAKE_DIR)/patches \
721            $(if $(strip $($(PKG)_CONDITIONAL_PATCHES)),$(addprefix $($(PKG)_MAKE_DIR)/patches/,$(strip $($(PKG)_CONDITIONAL_PATCHES)))), \
722            $($(PKG)_DIR) \
723        ) \
724    )
725endef
726
727# $1: commands to execute
728# $2: optional directory $1 to be executed within, default $($(PKG)_DIR)
729define PKG_EXECUTE_WITHIN__INT
730    $(if $(strip $(1)),(cd $(if $(strip $(2)),$(strip $(2)),$($(PKG)_DIR)); $(strip $(1))))
731endef
732
733# Removes all files under $1 except for those in $2
734define RMDIR_KEEP_FILES__INT
735    $(if $2,if [ -d "$1" ]; then TMPFILE=`mktemp`; $(TAR) -C $1 -cf $$$$TMPFILE $2; fi;) \
736    $(RM) -r $1; \
737    $(if $2,if [ -n "$$$$TMPFILE" ]; then mkdir -p $1; $(TAR) -C $1 -xf $$$$TMPFILE; rm -f $$$$TMPFILE; fi;)
738endef
739
740## Unpack and patch package
741define PKG_UNPACKED__INT
742$($(PKG)_DIR)/.unpacked: $(DL_DIR)/$($(PKG)_SOURCE) $(if $($(PKG)_CUSTOM_UNPACK),$($(PKG)_DIR)/.build-prereq-checked) | $(PKG)_SOURCE_DIR $(UNPACK_TARBALL_PREREQUISITES)
743    @$(call _ECHO,preparing... )
744    @$(call RMDIR_KEEP_FILES__INT,$($(PKG)_DIR),.build-prereq-checked)
745    $(call PKG_UNPACK)
746    $(call PKG_EXECUTE_WITHIN__INT,$($(PKG)_PATCH_PRE_CMDS))
747    $(call PKG_PATCH)
748    $(call PKG_EXECUTE_WITHIN__INT,$($(PKG)_PATCH_POST_CMDS))
749    @touch $$@
750$(pkg)-source: $($(PKG)_DIR)/.unpacked
751$(pkg)-unpacked: $($(PKG)_DIR)/.unpacked
752.PHONY: $(pkg)-source $(pkg)-unpacked
753endef
754
755## "unpack" (actually copy) local source package
756define PKG_UNPACKED_LOCALSOURCE_PACKAGE__INT
757$($(PKG)_DIR)/.unpacked: $(wildcard $($(PKG)_MAKE_DIR)/src/*) | $(PKG)_SOURCE_DIR
758    @$(call _ECHO,preparing... )
759    @$(call RMDIR_KEEP_FILES__INT,$($(PKG)_DIR),.build-prereq-checked)
760    mkdir -p $($(PKG)_DIR)
761    cp -a $$^ $($(PKG)_DIR)
762    @touch $$@
763$(pkg)-source: $($(PKG)_DIR)/.unpacked
764$(pkg)-unpacked: $($(PKG)_DIR)/.unpacked
765.PHONY: $(pkg)-source $(pkg)-unpacked
766endef
767
768define PKG_UNPACKED_SOURCE__INT
769$(PKG)_SOURCE_DIR:
770    @mkdir -p $($(PKG)_SOURCE_DIR)
771.PHONY: $(PKG)_SOURCE_DIR
772endef
773
774## check for changed suboptions, should only be called if $(PKG)_REBUILD_SUBOPTS is defined
775define PKG_UNPACKED_CHECK_REBUILD_SUBOPTS
776$($(PKG)_DIR)/.unpacked: $($(PKG)_FREETZ_CONFIG_FILE)
777endef
778
779## check for changed files in files and patches folder
780define PKG_UNPACKED_CHECK_CHANGES__INT1
781$(PKG)_FREETZ_CHANGES_FILE:=$(FREETZ_BASE_DIR)/$(SOURCE_DIR)/.$(pkg)_changes
782$(PKG)_FREETZ_CHANGES_RECOMPILE_SEARCH:=patches/.*\|src/.*\|$(pkg)\.mk\|$(pkg).*\.mk\.in\|Makefile\.in\|Config\.in\|Config\.in\.libs\|Config\.in\.modules
783$(PKG)_FREETZ_CHANGES_REPACK_SEARCH:=files/.*
784endef
785define PKG_UNPACKED_CHECK_CHANGES__INT2
786$(PKG)_FREETZ_CHANGES_CHECK: $(PKG)_SOURCE_DIR
787    @find $($(PKG)_MAKE_DIR) \
788        -regex "^$($(PKG)_MAKE_DIR)/\($($(PKG)_FREETZ_CHANGES_RECOMPILE_SEARCH)\|$($(PKG)_FREETZ_CHANGES_REPACK_SEARCH)\)" \
789        ! -wholename '*/.svn*' -printf '%TY-%Tm-%Td %TH:%TM:%TS\t%P\n' 2>/dev/null | sort -k 3 >$($(PKG)_FREETZ_CHANGES_FILE).temp
790    @if [ -e $($(PKG)_FREETZ_CHANGES_FILE) ]; then \
791        for i in 1 2; do \
792            PATTERN=; \
793            [ $$$$i = 1 ] && PATTERN='$($(PKG)_FREETZ_CHANGES_RECOMPILE_SEARCH)'; \
794            [ $$$$i = 2 ] && PATTERN='$($(PKG)_FREETZ_CHANGES_REPACK_SEARCH)'; \
795            if [ ! -z "$$$$PATTERN" ]; then \
796                if [ "`grep -e "$$$$PATTERN" $($(PKG)_FREETZ_CHANGES_FILE)`" != "`grep -e "$$$$PATTERN" $($(PKG)_FREETZ_CHANGES_FILE).temp`" ]; then \
797                    mv $($(PKG)_FREETZ_CHANGES_FILE).temp $($(PKG)_FREETZ_CHANGES_FILE); \
798                    [ $$$$i == 1 ] && $(RM) -r $($(PKG)_DIR); \
799                    $($(PKG)_CLEAN_TARGET_DIR__INT) \
800                    $($(PKG)_CLEAN_STAGING_DIR__INT) \
801                    break; \
802                fi \
803            fi \
804        done \
805    else \
806        mv $($(PKG)_FREETZ_CHANGES_FILE).temp $($(PKG)_FREETZ_CHANGES_FILE); \
807    fi
808    @$(RM) $($(PKG)_FREETZ_CHANGES_FILE).temp
809$(pkg)-build-prereq: $(PKG)_FREETZ_CHANGES_CHECK
810.PHONY: $(PKG)_FREETZ_CHANGES_CHECK
811endef
812
813PKG_UNPACKED           =$(eval $(PKG_UNPACKED_SOURCE__INT))
814PKG_LOCALSOURCE_PACKAGE=$(eval $(PKG_UNPACKED_SOURCE__INT))
815#
816ifeq ($(strip $(FREETZ_CHECK_CHANGED)),y)
817PKG_UNPACKED           +=$(eval $(PKG_UNPACKED_CHECK_CHANGES__INT1))$(eval $(PKG_UNPACKED_CHECK_CHANGES__INT2))
818PKG_LOCALSOURCE_PACKAGE+=$(eval $(PKG_UNPACKED_CHECK_CHANGES__INT1))$(eval $(PKG_UNPACKED_CHECK_CHANGES__INT2))
819endif
820#
821PKG_UNPACKED           +=$(eval $(PKG_UNPACKED__INT))
822PKG_LOCALSOURCE_PACKAGE+=$(eval $(PKG_UNPACKED_LOCALSOURCE_PACKAGE__INT))
823#
824PKG_UNPACKED           +=$(if $($(PKG)_REBUILD_SUBOPTS),$(eval $(PKG_UNPACKED_CHECK_REBUILD_SUBOPTS)))
825PKG_LOCALSOURCE_PACKAGE+=$(if $($(PKG)_REBUILD_SUBOPTS),$(eval $(PKG_UNPACKED_CHECK_REBUILD_SUBOPTS)))
826
827### Configure package
828define PKG_CONFIGURED_COMMON__INT
829$(pkg)-configured: $($(PKG)_DIR)/.configured
830.PHONY: $(pkg)-configured
831endef
832## Configure package, using ./configure
833define PKG_CONFIGURED_CONFIGURE__INT
834# Must be first
835$(PKG_CONFIGURED_COMMON__INT)
836$($(PKG)_DIR)/.configured: $($(PKG)_DIR)/.build-prereq-checked $($(PKG)_DIR)/.unpacked
837    @$(call _ECHO,configuring... )
838    ($(CONFIGURE) \
839        cd $($(PKG)_DIR); \
840        $(if $(strip $(FREETZ_BACKUP_CONFIG_CACHE)),$(call BACKUP_CONFIG_CACHE,before-$(pkg)),) \
841        $(TARGET_CONFIGURE_PRE_CMDS) \
842        $($(PKG)_CONFIGURE_PRE_CMDS) \
843        $(if $(strip $($(PKG)_BUILD_SUBDIR)),cd $(strip $($(PKG)_BUILD_SUBDIR));,) \
844        $(TARGET_CONFIGURE_ENV) \
845        $($(PKG)_CONFIGURE_ENV) \
846        CONFIG_SITE=$(CONFIG_SITE) \
847        conf_cmd \
848        $(if $(findstring y,$($(PKG)_CONFIGURE_DEFOPTS)), $(TARGET_CONFIGURE_OPTIONS)) \
849        $($(PKG)_CONFIGURE_OPTIONS) \
850        $(if $(strip $($(PKG)_BUILD_SUBDIR)),&& { cd $(abspath $($(PKG)_DIR)); },) \
851        $(if $($(PKG)_CONFIGURE_POST_CMDS),&& { $($(PKG)_CONFIGURE_POST_CMDS) },) \
852        $(if $(strip $(FREETZ_BACKUP_CONFIG_CACHE)),&& { $(call BACKUP_CONFIG_CACHE,after-$(pkg)) },) \
853    )
854    @touch $$@
855endef
856PKG_CONFIGURED_CONFIGURE=$(eval $(PKG_CONFIGURED_CONFIGURE__INT))
857
858## Package needs no configuration
859define PKG_CONFIGURED_NOP__INT
860# Must be first
861$(PKG_CONFIGURED_COMMON__INT)
862$($(PKG)_DIR)/.configured: $($(PKG)_DIR)/.build-prereq-checked $($(PKG)_DIR)/.unpacked
863    @touch $$@
864endef
865PKG_CONFIGURED_NOP=$(eval $(PKG_CONFIGURED_NOP__INT))
866
867
868## Add package to static or dynamic list
869define PKG_LIST__INT
870$(pkg)-list:
871ifeq ($(strip $(FREETZ_PACKAGE_$(PKG))),y)
872    @echo "S$(strip $($(PKG)_STARTLEVEL))$(pkg)-$($(PKG)_VERSION)" >> .static
873else
874    @echo "S$(strip $($(PKG)_STARTLEVEL))$(pkg)-$($(PKG)_VERSION)" >> .dynamic
875endif
876.PHONY: $(pkg)-list
877endef
878PKG_LIST=$(eval $(PKG_LIST__INT))
Hinweis: Hilfe zum Repository-Browser finden Sie in TracBrowser.