[include]
[openwrt.git] / include / autotools.mk
1 #
2 # Copyright (C) 2007-2010 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 autoconf_bool = $(patsubst %,$(if $($(1)),--enable,--disable)-%,$(2))
9
10 # delete *.la-files from staging_dir - we can not yet remove respective lines within all package
11 # Makefiles, since backfire still uses libtool v1.5.x which (may) require those files
12 define libtool_remove_files
13         find $(1) -name '*.la' | $(XARGS) rm -f;
14 endef
15
16 # 1: build dir
17 # 2: remove files
18 # 3: automake paths
19 # 4: libtool paths
20 # 5: extra m4 dirs
21 define autoreconf
22         (cd $(1); \
23                 $(patsubst %,rm -f %;,$(2)) \
24                 $(foreach p,$(3), \
25                         if [ -x $(p)/autogen.sh ]; then \
26                                 $(p)/autogen.sh || true; \
27                         elif [ -f $(p)/configure.ac ] || [ -f $(p)/configure.in ]; then \
28                                 [ -f $(p)/aclocal.m4 ] && [ ! -f $(p)/acinclude.m4 ] && mv aclocal.m4 acinclude.m4; \
29                                 [ -d $(p)/autom4te.cache ] && rm -rf autom4te.cache; \
30                                 $(STAGING_DIR_HOST)/bin/autoreconf -v -f -i -s \
31                                         -B $(STAGING_DIR_HOST)/share/aclocal \
32                                         $(patsubst %,-B %,$(5)) \
33                                         $(patsubst %,-I %,$(4)) $(4) || true; \
34                         fi; \
35                 ) \
36         );
37 endef
38
39
40 PKG_LIBTOOL_PATHS?=$(CONFIGURE_PATH)
41 PKG_AUTOMAKE_PATHS?=$(CONFIGURE_PATH)
42 PKG_REMOVE_FILES?=aclocal.m4
43
44 Hooks/InstallDev/Post += libtool_remove_files
45
46 define autoreconf_target
47   $(strip $(call autoreconf, \
48     $(PKG_BUILD_DIR), $(PKG_REMOVE_FILES), \
49     $(PKG_AUTOMAKE_PATHS), $(PKG_LIBTOOL_PATHS), \
50     $(STAGING_DIR)/host/share/aclocal $(STAGING_DIR)/usr/share/aclocal))
51 endef
52
53 ifneq ($(filter libtool,$(PKG_FIXUP)),)
54   PKG_BUILD_DEPENDS += libtool
55  ifeq ($(filter no-autoreconf,$(PKG_FIXUP)),)
56   Hooks/Configure/Pre += autoreconf_target
57  endif
58 endif
59
60 ifneq ($(filter libtool-ucxx,$(PKG_FIXUP)),)
61   PKG_BUILD_DEPENDS += libtool
62  ifeq ($(filter no-autoreconf,$(PKG_FIXUP)),)
63   Hooks/Configure/Pre += autoreconf_target
64  endif
65 endif
66
67 ifneq ($(filter autoreconf,$(PKG_FIXUP)),)
68   ifeq ($(filter autoreconf,$(Hooks/Configure/Pre)),)
69     Hooks/Configure/Pre += autoreconf_target
70   endif
71 endif
72
73
74 HOST_FIXUP?=$(PKG_FIXUP)
75 HOST_LIBTOOL_PATHS?=$(if $(PKG_LIBTOOL_PATHS),$(PKG_LIBTOOL_PATHS),.)
76 HOST_AUTOMAKE_PATHS?=$(if $(PKG_AUTOMAKE_PATHS),$(PKG_AUTOMAKE_PATHS),.)
77 HOST_REMOVE_FILES?=$(PKG_REMOVE_FILES)
78
79 define autoreconf_host
80   $(strip $(call autoreconf, \
81     $(HOST_BUILD_DIR), $(HOST_REMOVE_FILES), \
82     $(HOST_AUTOMAKE_PATHS), $(HOST_LIBTOOL_PATHS)))
83 endef
84
85 ifneq ($(filter libtool,$(HOST_FIXUP)),)
86   HOST_BUILD_DEPENDS += libtool
87  ifeq ($(filter no-autoreconf,$(HOST_FIXUP)),)
88   Hooks/HostConfigure/Pre += autoreconf_host
89  endif
90 endif
91
92 ifneq ($(filter libtool-ucxx,$(HOST_FIXUP)),)
93   HOST_BUILD_DEPENDS += libtool
94  ifeq ($(filter no-autoreconf,$(HOST_FIXUP)),)
95   Hooks/HostConfigure/Pre += autoreconf_host
96  endif
97 endif
98
99 ifneq ($(filter autoreconf,$(HOST_FIXUP)),)
100   ifeq ($(filter autoreconf,$(Hooks/HostConfigure/Pre)),)
101     Hooks/HostConfigure/Pre += autoreconf_host
102   endif
103 endif