source: trunk/make/Makefile.in @ 14473

Letzte Änderung dieser Datei seit 14473 war 14473, erstellt von er13 vor 8 Monaten

FREETZ_GCC_ABI/FREETZ_GCC_FLOAT_ABI symbols:

  • do not set ABI/FLOAT_ABI related compiler flags if the values these symbols contain are empty
  • this makes it possible to leave these symbols empty for architectures not supporting them
  • by f_666
  • refs #2862, refs https://github.com/Freetz/freetz/pull/20
Dateigröße: 34.3 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)_EXCLUDED:=
451#
452$(PKG)_CONFIGURE_DEFOPTS:=y
453#
454# $(pkg)-precompiled--int must be the first target, it will depend on DEPENDS_ON
455$(pkg)-precompiled: $(pkg)-precompiled--int $(pkg)-clean-echo-item $(pkg)
456$(pkg)-clean-echo-item:
457    @$(RM) $(ECHO_ITEM_START) $(ECHO_ITEM_BUILD)
458.PHONY: $(pkg)-clean-echo-item $(pkg)-precompiled $(pkg)-precompiled--int $(pkg)
459endef
460
461# Stage 2a: initialise other package-specific variables for binary packages
462define PKG_INIT_BIN__INT
463PKG_TYPE:=BIN
464# level 99 for packages that are not actually started
465$(PKG)_STARTLEVEL=99
466$(PKG)_MAKE_DIR:=$(MAKE_DIR)/$(pkg)
467$(PKG)_TARGET_DIR:=$(PACKAGES_DIR)/$(pkg)-$($(PKG)_VERSION)
468$(PKG)_TARGET_LIBDIR:=$(TARGET_SPECIFIC_ROOT_DIR)$(FREETZ_LIBRARY_DIR)
469$(PKG)_DEST_DIR:=$($(PKG)_TARGET_DIR)/root
470$(PKG)_DEST_LIBDIR:=$($(PKG)_TARGET_DIR)/root$(FREETZ_LIBRARY_DIR)
471$(PKG)_CLEAN_TARGET_DIR__INT:=$(RM) -r $($(PKG)_TARGET_DIR); $(RM) $(PACKAGES_DIR)/.$(pkg) $(PACKAGES_DIR)/.$(pkg)-$($(PKG)_VERSION);
472$(pkg)-precompiled $(pkg): | $(PKG)_TARGET_DIR
473endef
474
475# Stage 2b: initialise other package-specific variables for library packages
476define PKG_INIT_LIB__INT
477PKG_TYPE:=LIB
478$(PKG)_MAKE_DIR:=$(MAKE_DIR)/libs/$(pkg)
479$(PKG)_TARGET_DIR:=$(TARGET_SPECIFIC_ROOT_DIR)$(FREETZ_LIBRARY_DIR)
480$(PKG)_TARGET_LIBDIR:=$($(PKG)_TARGET_DIR)
481$(PKG)_DEST_DIR:=$(TARGET_SPECIFIC_ROOT_DIR)
482endef
483
484# Stage 3: Common definitions after BIN/LIB specific definitions
485define PKG_INIT__INT3
486$(PKG)_DEST_BIN:=$($(PKG)_DEST_DIR)/bin
487$(PKG)_DEST_SBIN:=$($(PKG)_DEST_DIR)/sbin
488$(PKG)_DEST_LIB:=$($(PKG)_DEST_DIR)/lib
489$(PKG)_DEST_USR_BIN:=$($(PKG)_DEST_DIR)/usr/bin
490$(PKG)_DEST_USR_SBIN:=$($(PKG)_DEST_DIR)/usr/sbin
491$(PKG)_DEST_USR_LIB:=$($(PKG)_DEST_DIR)/usr/lib
492$(PKG)_CLEAN_STAGING_DIR__INT:=$(MAKE_ENV) $(MAKE) --quiet --ignore-errors $(pkg)-clean >/dev/null 2>&1;
493endef
494
495define PKG_INIT_BIN__INTV
496$(value PKG_INIT__INT)
497$(value PKG_INIT_BIN__INT)
498$(value PKG_INIT__INT3)
499endef
500# Call & evaluate stages 1,2a,3 for binary packages
501define PKG_INIT_BIN
502$(eval $(call PKG_INIT_BIN__INTV,$1,$2,$3))
503endef
504
505define PKG_INIT_LIB__INTV
506$(value PKG_INIT__INT)
507$(value PKG_INIT_LIB__INT)
508$(value PKG_INIT__INT3)
509endef
510# Call & evaluate stages 1,2b,3 for library packages
511define PKG_INIT_LIB
512$(eval $(call PKG_INIT_LIB__INTV,$1,$2,$3))
513endef
514
515# PKG_ADD_BIN
516#  $1 PKG FREETZ_PACKAGE_ Config Symbol
517#  $2 pkg Name (optional)
518define PKG_ADD_BIN__INT
519ifeq ($(FREETZ_PACKAGE_$1),y)
520PACKAGES+=$(if $(strip $2),$2,$(pkg))
521endif
522endef
523define PKG_ADD_BIN
524$(eval $(call PKG_ADD_BIN__INT,$1,$2))
525endef
526
527# PKG_ADD_LIB
528#  $1 PKG FREETZ_LIB_ Config Symbol
529#  $2 pkg Name (optional)
530define PKG_ADD_LIB__INT
531ifeq ($(FREETZ_LIB_$1),y)
532LIBS+=$(if $(strip $2),$2,$(pkg))
533endif
534endef
535define PKG_ADD_LIB
536$(eval $(call PKG_ADD_LIB__INT,$1,$2))
537endef
538
539### PKG_FINISH - package finalisation
540
541# Finalise binary packages
542define PKG_FINISH_BIN__INT
543$(PKG)_TARGET_DIR:
544    @mkdir -p $($(PKG)_TARGET_DIR)
545.PHONY: $(PKG)_TARGET_DIR
546
547# create marker containing package version
548$(PACKAGES_DIR)/.$(pkg): | $(PACKAGES_DIR)
549    @echo "$($(PKG)_VERSION)" > $$@
550
551# copy files under make/$(pkg)/files to the package target dir
552$(PACKAGES_DIR)/.$(pkg)-$($(PKG)_VERSION): | $(PACKAGES_DIR)
553    mkdir -p $($(PKG)_TARGET_DIR)/root
554    if test -d $($(PKG)_MAKE_DIR)/files; then \
555        $(call COPY_USING_TAR,$($(PKG)_MAKE_DIR)/files,$($(PKG)_TARGET_DIR)) \
556    fi
557    @touch $$@
558
559$(pkg) $(pkg)-precompiled: $(PACKAGES_DIR)/.$(pkg) $(PACKAGES_DIR)/.$(pkg)-$($(PKG)_VERSION)
560
561$($(PKG)_TARGET_DIR)/.exclude: $(TOPDIR)/.config | $(PKG)_TARGET_DIR
562    @$(call write-list-to-file,$(patsubst /%,%,$(patsubst $($(PKG)_DEST_DIR)/%,%,$(strip $($(PKG)_EXCLUDED)))),$$@)
563
564$(pkg): $($(PKG)_TARGET_DIR)/.exclude
565
566$(PKG_LIST)
567$(call PKG_ADD_BIN__INT,$(PKG))
568endef
569
570# Finalise library packages
571define PKG_FINISH_LIB__INT
572endef
573
574# check for changed suboptions, should only be called if $(PKG)_REBUILD_SUBOPTS is defined
575define PKG_FINISH_CHECK_REBUILD_SUBOPTS__INT1
576$(PKG)_FREETZ_CONFIG_FILE:=$(FREETZ_BASE_DIR)/$(SOURCE_DIR)/.$(pkg)_config
577endef
578define PKG_FINISH_CHECK_REBUILD_SUBOPTS__INT2
579$($(PKG)_FREETZ_CONFIG_FILE): $(TOPDIR)/.config | $(SOURCE_DIR)
580    @($(foreach OPT,$($(PKG)_REBUILD_SUBOPTS),echo "$(if $($(OPT)),$(OPT)=$($(OPT)),$(_hash) $(OPT) is not set)";):) > $($(PKG)_FREETZ_CONFIG_FILE).temp
581    @if ! diff -q $($(PKG)_FREETZ_CONFIG_FILE).temp $($(PKG)_FREETZ_CONFIG_FILE) 2>/dev/null $(SILENT); then \
582        $(RM) -r $($(PKG)_DIR); \
583        $($(PKG)_CLEAN_TARGET_DIR__INT) \
584        mv $($(PKG)_FREETZ_CONFIG_FILE).temp $($(PKG)_FREETZ_CONFIG_FILE); \
585    else \
586        $(RM) $($(PKG)_FREETZ_CONFIG_FILE).temp; \
587    fi
588$(pkg)-build-prereq: $($(PKG)_FREETZ_CONFIG_FILE)
589endef
590
591# Finalise packages (general functionality + call to type specifics)
592define PKG_FINISH__INT
593$(pkg)-precompiled--int: $(pkg)-build-prereq $(TOOLCHAIN) $($(PKG)_HOST_DEPENDS_ON) $(patsubst %,%-precompiled,$($(PKG)_DEPENDS_ON))
594$(pkg)-precompiled:
595    @$(call _ECHO_DONE)
596
597.PHONY: $(pkg)-build-prereq
598$(pkg)-build-prereq: $($(PKG)_DIR)/.build-prereq-checked
599$($(PKG)_DIR)/.build-prereq-checked:
600ifneq ($($(PKG)_BUILD_PREREQ),)
601    @MISSING_PREREQ=""; \
602    for fv in $($(PKG)_BUILD_PREREQ); do \
603        f=$$$$(echo $$$$fv | cut -d ':' -f 1); \
604        v=$$$$(echo $$$$fv | cut -d ':' -sf 2 | sed -e 's,[.],[.],g'); \
605        if ! which $$$$f >/dev/null 2>&1; then \
606            MISSING_PREREQ="$$$$MISSING_PREREQ $$$$f"; \
607        elif [ -n "$$$$v" ] && ! $$$$f --version 2>&1 | grep -q "$$$$v"; then \
608            MISSING_PREREQ="$$$$MISSING_PREREQ $$$$fv"; \
609        fi; \
610    done; \
611    if [ -n "$$$$MISSING_PREREQ" ]; then \
612        echo -n -e "$(_Y)"; \
613        echo -e \
614            "ERROR: The following commands/packages required for building the $(pkg)-package are missing on your system:" \
615            `echo $$$$MISSING_PREREQ | sed -e 's| |, |g'`; \
616        if [ -n "$(strip $($(PKG)_BUILD_PREREQ_HINT))" ]; then \
617            echo "$($(PKG)_BUILD_PREREQ_HINT)"; \
618        fi; \
619        echo -n -e "$(_N)"; \
620        exit 1; \
621    fi;
622endif
623    @mkdir -p $$(dir $$@); touch $$@;
624
625$(pkg)-dirclean--int:
626    $(RM) -r $($(PKG)_DIR)
627    $($(PKG)_CLEAN_TARGET_DIR__INT)
628#   $($(PKG)_CLEAN_STAGING_DIR__INT)
629
630$(pkg)-dirclean: $(pkg)-dirclean--int
631$(pkg)-distclean: $(pkg)-dirclean $(pkg)-clean $(pkg)-uninstall
632.PHONY: $(pkg)-dirclean $(pkg)-dirclean--int $(pkg)-distclean $(pkg)-clean $(pkg)-uninstall
633
634PKG:=
635PKG_TYPE:=
636PKG_MAKEFILE:=
637PKG_BASENAME:=
638pkg:=
639endef
640
641PKG_FINISH=$(eval $(PKG_FINISH_$(PKG_TYPE)__INT))
642PKG_FINISH+=$(if $($(PKG)_REBUILD_SUBOPTS),$(eval $(PKG_FINISH_CHECK_REBUILD_SUBOPTS__INT1))$(eval $(PKG_FINISH_CHECK_REBUILD_SUBOPTS__INT2)))
643PKG_FINISH+=$(eval $(PKG_FINISH__INT))
644
645### PKG_SOURCE_DOWNLOAD - download source packages
646
647define PKG_SOURCE_DOWNLOAD__INT
648NON_LOCALSOURCE_PACKAGES+=$(pkg)
649$(DL_DIR)/$($(PKG)_SOURCE): | $(DL_DIR)
650    $(call _ECHO,downloading... )
651    @if [ -e $(MIRROR_DIR)/$($(PKG)_SOURCE) ]; then \
652        $(call MESSAGE, Found $($(PKG)_SOURCE) in $(MIRROR_DIR), creating hard link); \
653        ln $(MIRROR_DIR)/$($(PKG)_SOURCE) $(DL_DIR); \
654    else \
655        $(DL_TOOL) \
656            $(DL_DIR) \
657            $(if $($(PKG)_SOURCE_DOWNLOAD_NAME),$($(PKG)_SOURCE_DOWNLOAD_NAME),$($(PKG)_SOURCE)) \
658            $($(PKG)_SITE) \
659            $(or $($(PKG)_SOURCE_SHA512),$($(PKG)_SOURCE_SHA256),$($(PKG)_SOURCE_SHA1),$($(PKG)_SOURCE_MD5)) \
660            $(SILENT) \
661            $(if $($(PKG)_SOURCE_DOWNLOAD_NAME),&& mv -f $(DL_DIR)/$($(PKG)_SOURCE_DOWNLOAD_NAME) $(DL_DIR)/$($(PKG)_SOURCE)); \
662    fi
663
664$(pkg)-download: $(DL_DIR)/$($(PKG)_SOURCE)
665
666$(MIRROR_DIR)/$($(PKG)_SOURCE): | $(MIRROR_DIR)
667    @if [ -e $(DL_DIR)/$($(PKG)_SOURCE) ]; then \
668        $(call MESSAGE, Found $($(PKG)_SOURCE) in $(DL_DIR), creating hard link); \
669        ln $(DL_DIR)/$($(PKG)_SOURCE) $(MIRROR_DIR); \
670    else \
671        $(DL_TOOL) \
672            $(MIRROR_DIR) \
673            $(if $($(PKG)_SOURCE_DOWNLOAD_NAME),$($(PKG)_SOURCE_DOWNLOAD_NAME),$($(PKG)_SOURCE)) \
674            $($(PKG)_SITE) \
675            $(or $($(PKG)_SOURCE_SHA512),$($(PKG)_SOURCE_SHA256),$($(PKG)_SOURCE_SHA1),$($(PKG)_SOURCE_MD5)) \
676            $(SILENT) \
677            $(if $($(PKG)_SOURCE_DOWNLOAD_NAME),&& mv -f $(DL_DIR)/$($(PKG)_SOURCE_DOWNLOAD_NAME) $(DL_DIR)/$($(PKG)_SOURCE)); \
678    fi
679
680$(pkg)-download-mirror: $(MIRROR_DIR)/$($(PKG)_SOURCE)
681
682$(pkg)-check-download:
683    @echo -n "Checking download for package $(pkg)..."
684    @if $(DL_TOOL) check $($(PKG)_SOURCE) $($(PKG)_SITE); then \
685        echo "ok."; \
686    else \
687        echo "ERROR: NOT FOUND!"; \
688    fi
689
690.PHONY: $(pkg)-download $(pkg)-check-download $(pkg)-download-mirror
691endef
692PKG_SOURCE_DOWNLOAD=$(eval $(PKG_SOURCE_DOWNLOAD__INT))
693
694
695### PKG_UNPACK - unpack source archive & apply patches
696# Unpack, without patch, but only if source package is defined
697define PKG_UNPACK
698    $(if $($(PKG)_SOURCE),$(strip $(call $(if $($(PKG)_CUSTOM_UNPACK),$(PKG)_CUSTOM_UNPACK,UNPACK_TARBALL),$(DL_DIR)/$($(PKG)_SOURCE),$($(PKG)_SOURCE_DIR))))
699endef
700
701### PKG_PATCH - apply patches
702define PKG_PATCH
703    $(subst $(_dollar),$(_dollar)$(_dollar), \
704        $(call \
705            APPLY_PATCHES, \
706            $($(PKG)_MAKE_DIR)/patches \
707            $(if $(strip $($(PKG)_CONDITIONAL_PATCHES)),$(addprefix $($(PKG)_MAKE_DIR)/patches/,$(strip $($(PKG)_CONDITIONAL_PATCHES)))), \
708            $($(PKG)_DIR) \
709        ) \
710    )
711endef
712
713# $1: commands to execute
714# $2: optional directory $1 to be executed within, default $($(PKG)_DIR)
715define PKG_EXECUTE_WITHIN__INT
716    $(if $(strip $(1)),(cd $(if $(strip $(2)),$(strip $(2)),$($(PKG)_DIR)); $(strip $(1))))
717endef
718
719# Removes all files under $1 except for those in $2
720define RMDIR_KEEP_FILES__INT
721    $(if $2,if [ -d "$1" ]; then TMPFILE=`mktemp`; $(TAR) -C $1 -cf $$$$TMPFILE $2; fi;) \
722    $(RM) -r $1; \
723    $(if $2,if [ -n "$$$$TMPFILE" ]; then mkdir -p $1; $(TAR) -C $1 -xf $$$$TMPFILE; rm -f $$$$TMPFILE; fi;)
724endef
725
726## Unpack and patch package
727define PKG_UNPACKED__INT
728$($(PKG)_DIR)/.unpacked: $(DL_DIR)/$($(PKG)_SOURCE) $(if $($(PKG)_CUSTOM_UNPACK),$($(PKG)_DIR)/.build-prereq-checked) | $(PKG)_SOURCE_DIR $(UNPACK_TARBALL_PREREQUISITES)
729    @$(call _ECHO,preparing... )
730    @$(call RMDIR_KEEP_FILES__INT,$($(PKG)_DIR),.build-prereq-checked)
731    $(call PKG_UNPACK)
732    $(call PKG_EXECUTE_WITHIN__INT,$($(PKG)_PATCH_PRE_CMDS))
733    $(call PKG_PATCH)
734    $(call PKG_EXECUTE_WITHIN__INT,$($(PKG)_PATCH_POST_CMDS))
735    @touch $$@
736$(pkg)-source: $($(PKG)_DIR)/.unpacked
737$(pkg)-unpacked: $($(PKG)_DIR)/.unpacked
738.PHONY: $(pkg)-source $(pkg)-unpacked
739endef
740
741## "unpack" (actually copy) local source package
742define PKG_UNPACKED_LOCALSOURCE_PACKAGE__INT
743$($(PKG)_DIR)/.unpacked: $(wildcard $($(PKG)_MAKE_DIR)/src/*) | $(PKG)_SOURCE_DIR
744    @$(call _ECHO,preparing... )
745    @$(call RMDIR_KEEP_FILES__INT,$($(PKG)_DIR),.build-prereq-checked)
746    mkdir -p $($(PKG)_DIR)
747    cp -a $$^ $($(PKG)_DIR)
748    @touch $$@
749$(pkg)-source: $($(PKG)_DIR)/.unpacked
750$(pkg)-unpacked: $($(PKG)_DIR)/.unpacked
751.PHONY: $(pkg)-source $(pkg)-unpacked
752endef
753
754define PKG_UNPACKED_SOURCE__INT
755$(PKG)_SOURCE_DIR:
756    @mkdir -p $($(PKG)_SOURCE_DIR)
757.PHONY: $(PKG)_SOURCE_DIR
758endef
759
760## check for changed suboptions, should only be called if $(PKG)_REBUILD_SUBOPTS is defined
761define PKG_UNPACKED_CHECK_REBUILD_SUBOPTS
762$($(PKG)_DIR)/.unpacked: $($(PKG)_FREETZ_CONFIG_FILE)
763endef
764
765## check for changed files in files and patches folder
766define PKG_UNPACKED_CHECK_CHANGES__INT1
767$(PKG)_FREETZ_CHANGES_FILE:=$(FREETZ_BASE_DIR)/$(SOURCE_DIR)/.$(pkg)_changes
768$(PKG)_FREETZ_CHANGES_RECOMPILE_SEARCH:=patches/.*\|src/.*\|$(pkg)\.mk\|$(pkg).*\.mk\.in\|Makefile\.in\|Config\.in\|Config\.in\.libs\|Config\.in\.modules
769$(PKG)_FREETZ_CHANGES_REPACK_SEARCH:=files/.*
770endef
771define PKG_UNPACKED_CHECK_CHANGES__INT2
772$(PKG)_FREETZ_CHANGES_CHECK: $(PKG)_SOURCE_DIR
773    @find $($(PKG)_MAKE_DIR) \
774        -regex "^$($(PKG)_MAKE_DIR)/\($($(PKG)_FREETZ_CHANGES_RECOMPILE_SEARCH)\|$($(PKG)_FREETZ_CHANGES_REPACK_SEARCH)\)" \
775        ! -wholename '*/.svn*' -printf '%TY-%Tm-%Td %TH:%TM:%TS\t%P\n' 2>/dev/null | sort -k 3 >$($(PKG)_FREETZ_CHANGES_FILE).temp
776    @if [ -e $($(PKG)_FREETZ_CHANGES_FILE) ]; then \
777        for i in 1 2; do \
778            PATTERN=; \
779            [ $$$$i = 1 ] && PATTERN='$($(PKG)_FREETZ_CHANGES_RECOMPILE_SEARCH)'; \
780            [ $$$$i = 2 ] && PATTERN='$($(PKG)_FREETZ_CHANGES_REPACK_SEARCH)'; \
781            if [ ! -z "$$$$PATTERN" ]; then \
782                if [ "`grep -e "$$$$PATTERN" $($(PKG)_FREETZ_CHANGES_FILE)`" != "`grep -e "$$$$PATTERN" $($(PKG)_FREETZ_CHANGES_FILE).temp`" ]; then \
783                    mv $($(PKG)_FREETZ_CHANGES_FILE).temp $($(PKG)_FREETZ_CHANGES_FILE); \
784                    [ $$$$i == 1 ] && $(RM) -r $($(PKG)_DIR); \
785                    $($(PKG)_CLEAN_TARGET_DIR__INT) \
786                    $($(PKG)_CLEAN_STAGING_DIR__INT) \
787                    break; \
788                fi \
789            fi \
790        done \
791    else \
792        mv $($(PKG)_FREETZ_CHANGES_FILE).temp $($(PKG)_FREETZ_CHANGES_FILE); \
793    fi
794    @$(RM) $($(PKG)_FREETZ_CHANGES_FILE).temp
795$(pkg)-build-prereq: $(PKG)_FREETZ_CHANGES_CHECK
796.PHONY: $(PKG)_FREETZ_CHANGES_CHECK
797endef
798
799PKG_UNPACKED           =$(eval $(PKG_UNPACKED_SOURCE__INT))
800PKG_LOCALSOURCE_PACKAGE=$(eval $(PKG_UNPACKED_SOURCE__INT))
801#
802ifeq ($(strip $(FREETZ_CHECK_CHANGED)),y)
803PKG_UNPACKED           +=$(eval $(PKG_UNPACKED_CHECK_CHANGES__INT1))$(eval $(PKG_UNPACKED_CHECK_CHANGES__INT2))
804PKG_LOCALSOURCE_PACKAGE+=$(eval $(PKG_UNPACKED_CHECK_CHANGES__INT1))$(eval $(PKG_UNPACKED_CHECK_CHANGES__INT2))
805endif
806#
807PKG_UNPACKED           +=$(eval $(PKG_UNPACKED__INT))
808PKG_LOCALSOURCE_PACKAGE+=$(eval $(PKG_UNPACKED_LOCALSOURCE_PACKAGE__INT))
809#
810PKG_UNPACKED           +=$(if $($(PKG)_REBUILD_SUBOPTS),$(eval $(PKG_UNPACKED_CHECK_REBUILD_SUBOPTS)))
811PKG_LOCALSOURCE_PACKAGE+=$(if $($(PKG)_REBUILD_SUBOPTS),$(eval $(PKG_UNPACKED_CHECK_REBUILD_SUBOPTS)))
812
813### Configure package
814define PKG_CONFIGURED_COMMON__INT
815$(pkg)-configured: $($(PKG)_DIR)/.configured
816.PHONY: $(pkg)-configured
817endef
818## Configure package, using ./configure
819define PKG_CONFIGURED_CONFIGURE__INT
820# Must be first
821$(PKG_CONFIGURED_COMMON__INT)
822$($(PKG)_DIR)/.configured: $($(PKG)_DIR)/.build-prereq-checked $($(PKG)_DIR)/.unpacked
823    @$(call _ECHO,configuring... )
824    ($(CONFIGURE) \
825        cd $($(PKG)_DIR); \
826        $(if $(strip $(FREETZ_BACKUP_CONFIG_CACHE)),$(call BACKUP_CONFIG_CACHE,before-$(pkg)),) \
827        $(TARGET_CONFIGURE_PRE_CMDS) \
828        $($(PKG)_CONFIGURE_PRE_CMDS) \
829        $(if $(strip $($(PKG)_BUILD_SUBDIR)),cd $(strip $($(PKG)_BUILD_SUBDIR));,) \
830        $(TARGET_CONFIGURE_ENV) \
831        $($(PKG)_CONFIGURE_ENV) \
832        CONFIG_SITE=$(CONFIG_SITE) \
833        conf_cmd \
834        $(if $(findstring y,$($(PKG)_CONFIGURE_DEFOPTS)), $(TARGET_CONFIGURE_OPTIONS)) \
835        $($(PKG)_CONFIGURE_OPTIONS) \
836        $(if $(strip $($(PKG)_BUILD_SUBDIR)),&& { cd $(abspath $($(PKG)_DIR)); },) \
837        $(if $($(PKG)_CONFIGURE_POST_CMDS),&& { $($(PKG)_CONFIGURE_POST_CMDS) },) \
838        $(if $(strip $(FREETZ_BACKUP_CONFIG_CACHE)),&& { $(call BACKUP_CONFIG_CACHE,after-$(pkg)) },) \
839    )
840    @touch $$@
841endef
842PKG_CONFIGURED_CONFIGURE=$(eval $(PKG_CONFIGURED_CONFIGURE__INT))
843
844## Package needs no configuration
845define PKG_CONFIGURED_NOP__INT
846# Must be first
847$(PKG_CONFIGURED_COMMON__INT)
848$($(PKG)_DIR)/.configured: $($(PKG)_DIR)/.build-prereq-checked $($(PKG)_DIR)/.unpacked
849    @touch $$@
850endef
851PKG_CONFIGURED_NOP=$(eval $(PKG_CONFIGURED_NOP__INT))
852
853
854## Add package to static or dynamic list
855define PKG_LIST__INT
856$(pkg)-list:
857ifeq ($(strip $(FREETZ_PACKAGE_$(PKG))),y)
858    @echo "S$(strip $($(PKG)_STARTLEVEL))$(pkg)-$($(PKG)_VERSION)" >> .static
859else
860    @echo "S$(strip $($(PKG)_STARTLEVEL))$(pkg)-$($(PKG)_VERSION)" >> .dynamic
861endif
862.PHONY: $(pkg)-list
863endef
864PKG_LIST=$(eval $(PKG_LIST__INT))
Hinweis: Hilfe zum Repository-Browser finden Sie in TracBrowser.