summaryrefslogtreecommitdiff
path: root/core/mk/pkg-macros/configure.mk
blob: a26f1d89144988dd8f5ea61651b99a50bbd35300 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
################################################################################
# Embtoolkit
# Copyright(C) 2014 Abdoulaye Walsimou GAYE.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
#
# \file         configure.mk
# \brief	configure.mk of Embtoolkit
# \author       Abdoulaye Walsimou GAYE <awg@embtoolkit.org>
# \date         January 2014
################################################################################

#
# embtk_fixgconfigsfor_pkg
#
__embtk_gconfigsub	:= $(EMBTK_ROOT)/scripts/config.sub
__embtk_gconfiguess	:= $(EMBTK_ROOT)/scripts/config.guess
define __embtk_fixgconfigsfor_pkg
	subs="$$(find $(__embtk_pkg_srcdir)/ -type f -name config.sub)";	\
	for sub in $$subs; do							\
		if [ -n $$sub -a -e $$sub ]; then				\
			ln -sf $(__embtk_gconfigsub) $$sub;			\
		fi;								\
	done;									\
	guesses="$$(find $(__embtk_pkg_srcdir)/ -type f -name config.guess)"; 	\
	for guess in $$guesses; do						\
		if [ -n $$guess -a -e $$guess ]; then				\
			ln -sf $(__embtk_gconfiguess) $$guess;			\
		fi;								\
	done;
endef

#
# A macro which runs configure script (conpatible with autotools configure)
# for a package and sets environment variables correctly.
# Usage:
# $(call embtk_configure_pkg,PACKAGE)
#
__embtk_pkg_autoreconf-y = $(CONFIG_EMBTK_$(PKGV)_NEED_AUTORECONF)
define embtk_autoreconf_pkg
	$(if $(__embtk_pkg_autoreconf-y),$(call __embtk_autoreconf_pkg,$(1)))
endef
define __embtk_autoreconf_pkg
	test -e $(__embtk_pkg_srcdir)/configure.ac ||				\
	test -e $(__embtk_pkg_srcdir)/configure.in ||				\
	($(call embtk_perror,"Can not autoreconf $(__embtk_pkg_name)"); exit 1)
	cd $(__embtk_pkg_srcdir); $(AUTORECONF)					\
		--install -f --include=$(embtk_sysroot)/usr/share/aclocal
endef

define embtk_autoreconf_hostpkg
	$(if $(__embtk_pkg_autoreconf-y),$(call __embtk_autoreconf_hostpkg,$(1)))
endef
define __embtk_autoreconf_hostpkg
	test -e $(__embtk_pkg_srcdir)/configure.ac ||				\
	test -e $(__embtk_pkg_srcdir)/configure.in ||				\
	($(call embtk_perror,"Can not autoreconf $(__embtk_pkg_name)"); exit 1)
	cd $(__embtk_pkg_srcdir); $(AUTORECONF) --install -f
endef

__embtk_parse_configure_opts = $(subst $(embtk_space),"\\n\\t",$(strip $(1)))
define __embtk_print_configure_opts
	$(if $(strip $(1)),
	$(call embtk_echo_blue,"Configure options:\\n\\t$(__embtk_parse_configure_opts)"))
	echo
endef

__embtk_pkg_configurescript = $(__embtk_pkg_srcdir)/$(__embtk_pkg_configuredir)configure

__embtk_pkg_ildflags	= -L$(embtk_sysroot)/$(LIBDIR)
__embtk_pkg_ildflags	+= -L$(embtk_sysroot)/usr/$(LIBDIR)
__embtk_pkg_cc		= CC=$(if $(__embtk_pkg_noccache),$(TARGETCC),$(TARGETCC_CACHED))
___embtk_pkg_cxx	= CXX=$(if $(__embtk_pkg_noccache),$(TARGETCXX_CACHED),$(TARGETCXX_CACHED))
__embtk_pkg_cxx		= $(if $(CONFIG_EMBTK_GCC_LANGUAGE_CPP),$(___embtk_pkg_cxx))
define embtk_configure_pkg
	$(if $(EMBTK_BUILDSYS_DEBUG),
		$(call embtk_pinfo,"Configure $(__embtk_pkg_package)..."))
	$(call embtk_autoreconf_pkg,$(1))
	$(Q)test -e $(__embtk_pkg_configurescript) || exit 1
	$(call __embtk_print_configure_opts,$(__embtk_pkg_configureopts))
	$(if $(CONFIG_EMBTK_CLIB_MUSL),$(call __embtk_fixgconfigsfor_pkg,$(1)))
	$(Q)cd $(__embtk_pkg_builddir);						\
	$(__embtk_pkg_cc)							\
	$(__embtk_pkg_cxx)							\
	AR=$(TARGETAR)								\
	RANLIB=$(TARGETRANLIB)							\
	AS=$(CROSS_COMPILE)as							\
	NM=$(TARGETNM)								\
	STRIP=$(TARGETSTRIP)							\
	OBJDUMP=$(TARGETOBJDUMP)						\
	OBJCOPY=$(TARGETOBJCOPY)						\
	CFLAGS="$(__embtk_pkg_cflags) $(TARGET_CFLAGS)"				\
	CXXFLAGS="$(__embtk_pkg_cxxflags) $(TARGET_CXXFLAGS)"			\
	LDFLAGS="$(__embtk_pkg_ildflags) $(__embtk_pkg_ldflags)"		\
	CPPFLAGS="-I$(embtk_sysroot)/usr/include $(__embtk_pkg_cppflags)"	\
	PKG_CONFIG="$(PKGCONFIG_BIN)"						\
	PKG_CONFIG_PATH="$(EMBTK_PKG_CONFIG_PATH)"				\
	PKG_CONFIG_LIBDIR="$(EMBTK_PKG_CONFIG_LIBDIR)"				\
	ac_cv_func_malloc_0_nonnull=yes						\
	ac_cv_func_realloc_0_nonnull=yes					\
	CONFIG_SHELL=$(CONFIG_EMBTK_SHELL)					\
	$(__embtk_pkg_configureenv) $(__embtk_pkg_scanbuild)			\
	$(CONFIG_EMBTK_SHELL) $(__embtk_pkg_configurescript)			\
	--build=$(HOST_BUILD) --host=$(STRICT_GNU_TARGET)			\
	--target=$(STRICT_GNU_TARGET) --libdir=/usr/$(LIBDIR)			\
	--prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-rpath	\
	$(__embtk_pkg_configureopts)
	$(Q)$(call __embtk_setconfigured_pkg,$(1))
	$(Q)$(call __embtk_kill_lt_rpath,$(__embtk_pkg_builddir))
endef

#
# A macro which runs configure script (conpatible with autotools configure)
# for a package for host development machine and sets environment variables
# correctly.
# Usage:
# $(call embtk_configure_hostpkg,PACKAGE)
#
__embtk_hostpkg_rpathldflags	= "-Wl,-rpath,$(embtk_htools)/usr/lib"
__embtk_hostpkg_rpath		= $(strip $(if $(__embtk_pkg_setrpath),		\
					$(__embtk_hostpkg_rpathldflags)))

__embtk_hostpkg_ldflags		= -L$(embtk_htools)/usr/lib -L/opt/local/lib $(__embtk_hostpkg_rpath)
__embtk_hostpkg_cppflags	= -I$(embtk_htools)/usr/include -I/opt/local/include
define embtk_configure_hostpkg
	$(if $(EMBTK_BUILDSYS_DEBUG),
	$(call embtk_pinfo,"Configure $(__embtk_pkg_package) for host..."))
	$(call embtk_autoreconf_hostpkg,$(1))
	$(if $(CONFIG_EMBTK_CLIB_MUSL),$(call __embtk_fixgconfigsfor_pkg,$(1)))
	$(Q)test -e $(__embtk_pkg_configurescript) || exit 1
	$(call __embtk_print_configure_opts,$(__embtk_pkg_configureopts))
	$(Q)cd $(__embtk_pkg_builddir);						\
	CPPFLAGS="$(__embtk_hostpkg_cppflags)"					\
	LDFLAGS="$(__embtk_hostpkg_ldflags)"					\
	PKG_CONFIG="$(PKGCONFIG_BIN)"						\
	PKG_CONFIG_PATH="$(EMBTK_HOST_PKG_CONFIG_PATH)"				\
	$(if $(__embtk_pkg_noccache),,CC=$(HOSTCC_CACHED))			\
	$(if $(__embtk_pkg_noccache),,CXX=$(HOSTCXX_CACHED))			\
	CONFIG_SHELL=$(CONFIG_EMBTK_SHELL)					\
	$(__embtk_pkg_configureenv)						\
	$(CONFIG_EMBTK_SHELL) $(__embtk_pkg_configurescript)			\
	--build=$(HOST_BUILD) --host=$(HOST_ARCH)				\
	--prefix=$(strip $(if $(__embtk_pkg_prefix),				\
				$(__embtk_pkg_prefix),$(embtk_htools)/usr))	\
	$(__embtk_pkg_configureopts)
	$(Q)$(call __embtk_setconfigured_pkg,$(1))
endef

#
#
# Usage:
# $(call embtk_wafconfigure_pkg,xxxx)
#
define embtk_wafconfigure_pkg
	$(Q)test -e $(__embtk_pkg_srcdir)/wscript || exit 1
	$(call __embtk_print_configure_opts,$(__embtk_pkg_configureopts))
	$(Q)cd $(__embtk_pkg_srcdir);						\
	$(__embtk_pkg_cc)							\
	$(__embtk_pkg_cxx)							\
	AR=$(TARGETAR)								\
	RANLIB=$(TARGETRANLIB)							\
	AS=$(CROSS_COMPILE)as							\
	NM=$(TARGETNM)								\
	STRIP=$(TARGETSTRIP)							\
	OBJDUMP=$(TARGETOBJDUMP)						\
	OBJCOPY=$(TARGETOBJCOPY)						\
	CFLAGS="$(__embtk_pkg_cflags) $(TARGET_CFLAGS)"				\
	CXXFLAGS="$(__embtk_pkg_cxxflags) $(TARGET_CXXFLAGS)"			\
	LDFLAGS="$(__embtk_pkg_ildflags) $(__embtk_pkg_ldflags)"		\
	CPPFLAGS="-I$(embtk_sysroot)/usr/include $(__embtk_pkg_cppflags)"	\
	PKG_CONFIG="$(PKGCONFIG_BIN)"						\
	PKG_CONFIG_PATH="$(EMBTK_PKG_CONFIG_PATH)"				\
	PKG_CONFIG_LIBDIR="$(EMBTK_PKG_CONFIG_LIBDIR)"				\
	$(__embtk_pkg_configureenv) $(__embtk_pkg_scanbuild)			\
	./waf configure								\
		--prefix=/usr							\
		$(__embtk_pkg_configureopts)
	$(Q)$(call __embtk_setconfigured_pkg,$(1))
endef

#
#
# Usage:
# $(call embtk_wafconfigure_hostpkg,xxxx)
#
define embtk_wafconfigure_hostpkg
	$(Q)test -e $(__embtk_pkg_srcdir)/wscript || exit 1
	$(call __embtk_print_configure_opts,$(__embtk_pkg_configureopts))
	$(Q)cd $(__embtk_pkg_srcdir);						\
	CPPFLAGS="$(__embtk_hostpkg_cppflags)"					\
	LDFLAGS="$(__embtk_hostpkg_ldflags)"					\
	PKG_CONFIG="$(PKGCONFIG_BIN)"						\
	PKG_CONFIG_PATH="$(EMBTK_HOST_PKG_CONFIG_PATH)"				\
	$(if $(__embtk_pkg_noccache),,CC=$(HOSTCC_CACHED))			\
	$(if $(__embtk_pkg_noccache),,CXX=$(HOSTCXX_CACHED))			\
	$(__embtk_pkg_configureenv)						\
	./waf configure								\
		--prefix=$(strip $(if $(__embtk_pkg_prefix),			\
				$(__embtk_pkg_prefix),$(embtk_htools)/usr))	\
		$(__embtk_pkg_configureopts)
	$(Q)$(call __embtk_setconfigured_pkg,$(1))
endef