1*4882a593Smuzhiyun################################################################################ 2*4882a593Smuzhiyun# Autotools package infrastructure 3*4882a593Smuzhiyun# 4*4882a593Smuzhiyun# This file implements an infrastructure that eases development of 5*4882a593Smuzhiyun# package .mk files for autotools packages. It should be used for all 6*4882a593Smuzhiyun# packages that use the autotools as their build system. 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# See the Buildroot documentation for details on the usage of this 9*4882a593Smuzhiyun# infrastructure 10*4882a593Smuzhiyun# 11*4882a593Smuzhiyun# In terms of implementation, this autotools infrastructure requires 12*4882a593Smuzhiyun# the .mk file to only specify metadata information about the 13*4882a593Smuzhiyun# package: name, version, download URL, etc. 14*4882a593Smuzhiyun# 15*4882a593Smuzhiyun# We still allow the package .mk file to override what the different 16*4882a593Smuzhiyun# steps are doing, if needed. For example, if <PKG>_BUILD_CMDS is 17*4882a593Smuzhiyun# already defined, it is used as the list of commands to perform to 18*4882a593Smuzhiyun# build the package, instead of the default autotools behaviour. The 19*4882a593Smuzhiyun# package can also define some post operation hooks. 20*4882a593Smuzhiyun# 21*4882a593Smuzhiyun################################################################################ 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun# 25*4882a593Smuzhiyun# Utility function to upgrade config.sub and config.guess files 26*4882a593Smuzhiyun# 27*4882a593Smuzhiyun# argument 1 : directory into which config.guess and config.sub need 28*4882a593Smuzhiyun# to be updated. Note that config.sub and config.guess are searched 29*4882a593Smuzhiyun# recursively in this directory. 30*4882a593Smuzhiyun# 31*4882a593Smuzhiyundefine CONFIG_UPDATE 32*4882a593Smuzhiyun for file in config.guess config.sub; do \ 33*4882a593Smuzhiyun for i in $$(find $(1) -name $$file); do \ 34*4882a593Smuzhiyun cp support/gnuconfig/$$file $$i; \ 35*4882a593Smuzhiyun done; \ 36*4882a593Smuzhiyun done 37*4882a593Smuzhiyunendef 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun# This function generates the ac_cv_file_<foo> value for a given 40*4882a593Smuzhiyun# filename. This is needed to convince configure script doing 41*4882a593Smuzhiyun# AC_CHECK_FILE() tests that the file actually exists, since such 42*4882a593Smuzhiyun# tests cannot be done in a cross-compilation context. This function 43*4882a593Smuzhiyun# takes as argument the path of the file. An example usage is: 44*4882a593Smuzhiyun# 45*4882a593Smuzhiyun# FOOBAR_CONF_ENV = \ 46*4882a593Smuzhiyun# $(call AUTOCONF_AC_CHECK_FILE_VAL,/dev/random)=yes 47*4882a593SmuzhiyunAUTOCONF_AC_CHECK_FILE_VAL = ac_cv_file_$(subst -,_,$(subst /,_,$(subst .,_,$(1)))) 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun# 50*4882a593Smuzhiyun# Hook to update config.sub and config.guess if needed 51*4882a593Smuzhiyun# 52*4882a593Smuzhiyundefine UPDATE_CONFIG_HOOK 53*4882a593Smuzhiyun @$(call MESSAGE,"Updating config.sub and config.guess") 54*4882a593Smuzhiyun $(call CONFIG_UPDATE,$(@D)) 55*4882a593Smuzhiyunendef 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun# 58*4882a593Smuzhiyun# Hook to patch libtool to make it work properly for cross-compilation 59*4882a593Smuzhiyun# 60*4882a593Smuzhiyundefine LIBTOOL_PATCH_HOOK 61*4882a593Smuzhiyun @$(call MESSAGE,"Patching libtool") 62*4882a593Smuzhiyun $(Q)for i in `find $($(PKG)_DIR) -name ltmain.sh`; do \ 63*4882a593Smuzhiyun ltmain_version=`sed -n '/^[ \t]*VERSION=/{s/^[ \t]*VERSION=//;p;q;}' $$i | \ 64*4882a593Smuzhiyun sed -e 's/\([0-9]*\.[0-9]*\).*/\1/' -e 's/\"//'`; \ 65*4882a593Smuzhiyun ltmain_patchlevel=`sed -n '/^[ \t]*VERSION=/{s/^[ \t]*VERSION=//;p;q;}' $$i | \ 66*4882a593Smuzhiyun sed -e 's/\([0-9]*\.[0-9]*\.*\)\([0-9]*\).*/\2/' -e 's/\"//'`; \ 67*4882a593Smuzhiyun if test $${ltmain_version} = '1.5'; then \ 68*4882a593Smuzhiyun patch -i support/libtool/buildroot-libtool-v1.5.patch $${i}; \ 69*4882a593Smuzhiyun elif test $${ltmain_version} = "2.2"; then\ 70*4882a593Smuzhiyun patch -i support/libtool/buildroot-libtool-v2.2.patch $${i}; \ 71*4882a593Smuzhiyun elif test $${ltmain_version} = "2.4"; then\ 72*4882a593Smuzhiyun if test $${ltmain_patchlevel:-0} -gt 2; then\ 73*4882a593Smuzhiyun patch -i support/libtool/buildroot-libtool-v2.4.4.patch $${i}; \ 74*4882a593Smuzhiyun else \ 75*4882a593Smuzhiyun patch -i support/libtool/buildroot-libtool-v2.4.patch $${i}; \ 76*4882a593Smuzhiyun fi \ 77*4882a593Smuzhiyun fi \ 78*4882a593Smuzhiyun done 79*4882a593Smuzhiyunendef 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun# 82*4882a593Smuzhiyun# Hook to patch common issue with configure on powerpc64{,le} failing 83*4882a593Smuzhiyun# to detect shared library support: 84*4882a593Smuzhiyun# 85*4882a593Smuzhiyundefine CONFIGURE_FIX_POWERPC64_HOOK 86*4882a593Smuzhiyun @$(call MESSAGE,"Checking configure (powerpc64/powerpc64le)") 87*4882a593Smuzhiyun support/scripts/fix-configure-powerpc64.sh $($(PKG)_DIR) 88*4882a593Smuzhiyunendef 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun# 91*4882a593Smuzhiyun# Hook to gettextize the package if needed 92*4882a593Smuzhiyun# 93*4882a593Smuzhiyundefine GETTEXTIZE_HOOK 94*4882a593Smuzhiyun @$(call MESSAGE,"Gettextizing") 95*4882a593Smuzhiyun $(Q)cd $($(PKG)_SRCDIR) && $(GETTEXTIZE) $($(PKG)_GETTEXTIZE_OPTS) 96*4882a593Smuzhiyunendef 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun# 99*4882a593Smuzhiyun# Hook to autoreconf the package if needed 100*4882a593Smuzhiyun# 101*4882a593Smuzhiyundefine AUTORECONF_HOOK 102*4882a593Smuzhiyun @$(call MESSAGE,"Autoreconfiguring") 103*4882a593Smuzhiyun $(Q)cd $($(PKG)_SRCDIR) && $($(PKG)_AUTORECONF_ENV) $(AUTORECONF) $($(PKG)_AUTORECONF_OPTS) 104*4882a593Smuzhiyunendef 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun################################################################################ 107*4882a593Smuzhiyun# inner-autotools-package -- defines how the configuration, compilation and 108*4882a593Smuzhiyun# installation of an autotools package should be done, implements a 109*4882a593Smuzhiyun# few hooks to tune the build process for autotools specifities and 110*4882a593Smuzhiyun# calls the generic package infrastructure to generate the necessary 111*4882a593Smuzhiyun# make targets 112*4882a593Smuzhiyun# 113*4882a593Smuzhiyun# argument 1 is the lowercase package name 114*4882a593Smuzhiyun# argument 2 is the uppercase package name, including a HOST_ prefix 115*4882a593Smuzhiyun# for host packages 116*4882a593Smuzhiyun# argument 3 is the uppercase package name, without the HOST_ prefix 117*4882a593Smuzhiyun# for host packages 118*4882a593Smuzhiyun# argument 4 is the type (target or host) 119*4882a593Smuzhiyun################################################################################ 120*4882a593Smuzhiyun 121*4882a593Smuzhiyundefine inner-autotools-package 122*4882a593Smuzhiyun 123*4882a593Smuzhiyunifndef $(2)_LIBTOOL_PATCH 124*4882a593Smuzhiyun ifdef $(3)_LIBTOOL_PATCH 125*4882a593Smuzhiyun $(2)_LIBTOOL_PATCH = $$($(3)_LIBTOOL_PATCH) 126*4882a593Smuzhiyun else 127*4882a593Smuzhiyun $(2)_LIBTOOL_PATCH ?= YES 128*4882a593Smuzhiyun endif 129*4882a593Smuzhiyunendif 130*4882a593Smuzhiyun 131*4882a593Smuzhiyunifndef $(2)_MAKE 132*4882a593Smuzhiyun ifdef $(3)_MAKE 133*4882a593Smuzhiyun $(2)_MAKE = $$($(3)_MAKE) 134*4882a593Smuzhiyun else 135*4882a593Smuzhiyun $(2)_MAKE ?= $$(MAKE) 136*4882a593Smuzhiyun endif 137*4882a593Smuzhiyunendif 138*4882a593Smuzhiyun 139*4882a593Smuzhiyunifndef $(2)_AUTORECONF 140*4882a593Smuzhiyun ifdef $(3)_AUTORECONF 141*4882a593Smuzhiyun $(2)_AUTORECONF = $$($(3)_AUTORECONF) 142*4882a593Smuzhiyun else 143*4882a593Smuzhiyun $(2)_AUTORECONF ?= NO 144*4882a593Smuzhiyun endif 145*4882a593Smuzhiyunendif 146*4882a593Smuzhiyun 147*4882a593Smuzhiyunifndef $(2)_GETTEXTIZE 148*4882a593Smuzhiyun ifdef $(3)_GETTEXTIZE 149*4882a593Smuzhiyun $(2)_GETTEXTIZE = $$($(3)_GETTEXTIZE) 150*4882a593Smuzhiyun else 151*4882a593Smuzhiyun $(2)_GETTEXTIZE ?= NO 152*4882a593Smuzhiyun endif 153*4882a593Smuzhiyunendif 154*4882a593Smuzhiyun 155*4882a593Smuzhiyunifeq ($(4),host) 156*4882a593Smuzhiyun $(2)_GETTEXTIZE_OPTS ?= $$($(3)_GETTEXTIZE_OPTS) 157*4882a593Smuzhiyunendif 158*4882a593Smuzhiyun 159*4882a593Smuzhiyunifeq ($(4),host) 160*4882a593Smuzhiyun $(2)_AUTORECONF_OPTS ?= $$($(3)_AUTORECONF_OPTS) 161*4882a593Smuzhiyunendif 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun$(2)_CONF_ENV ?= 164*4882a593Smuzhiyun$(2)_CONF_OPTS ?= 165*4882a593Smuzhiyun$(2)_MAKE_ENV ?= 166*4882a593Smuzhiyun$(2)_MAKE_OPTS ?= 167*4882a593Smuzhiyun$(2)_INSTALL_OPTS ?= install 168*4882a593Smuzhiyun$(2)_INSTALL_STAGING_OPTS ?= DESTDIR=$$(STAGING_DIR) install 169*4882a593Smuzhiyun$(2)_INSTALL_TARGET_OPTS ?= DESTDIR=$$(TARGET_DIR) install 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun# 172*4882a593Smuzhiyun# Configure step. Only define it if not already defined by the package 173*4882a593Smuzhiyun# .mk file. And take care of the differences between host and target 174*4882a593Smuzhiyun# packages. 175*4882a593Smuzhiyun# 176*4882a593Smuzhiyunifndef $(2)_CONFIGURE_CMDS 177*4882a593Smuzhiyunifeq ($(4),target) 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun# Configure package for target 180*4882a593Smuzhiyundefine $(2)_CONFIGURE_CMDS 181*4882a593Smuzhiyun (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache && \ 182*4882a593Smuzhiyun $$(TARGET_CONFIGURE_OPTS) \ 183*4882a593Smuzhiyun $$(TARGET_CONFIGURE_ARGS) \ 184*4882a593Smuzhiyun $$($$(PKG)_CONF_ENV) \ 185*4882a593Smuzhiyun CONFIG_SITE=/dev/null \ 186*4882a593Smuzhiyun ./configure \ 187*4882a593Smuzhiyun --target=$$(GNU_TARGET_NAME) \ 188*4882a593Smuzhiyun --host=$$(GNU_TARGET_NAME) \ 189*4882a593Smuzhiyun --build=$$(GNU_HOST_NAME) \ 190*4882a593Smuzhiyun --prefix=/usr \ 191*4882a593Smuzhiyun --exec-prefix=/usr \ 192*4882a593Smuzhiyun --sysconfdir=/etc \ 193*4882a593Smuzhiyun --localstatedir=/var \ 194*4882a593Smuzhiyun --program-prefix="" \ 195*4882a593Smuzhiyun --disable-gtk-doc \ 196*4882a593Smuzhiyun --disable-gtk-doc-html \ 197*4882a593Smuzhiyun --disable-doc \ 198*4882a593Smuzhiyun --disable-docs \ 199*4882a593Smuzhiyun --disable-documentation \ 200*4882a593Smuzhiyun --with-xmlto=no \ 201*4882a593Smuzhiyun --with-fop=no \ 202*4882a593Smuzhiyun $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \ 203*4882a593Smuzhiyun --enable-ipv6 \ 204*4882a593Smuzhiyun $$(NLS_OPTS) \ 205*4882a593Smuzhiyun $$(SHARED_STATIC_LIBS_OPTS) \ 206*4882a593Smuzhiyun $$(QUIET) $$($$(PKG)_CONF_OPTS) \ 207*4882a593Smuzhiyun ) 208*4882a593Smuzhiyunendef 209*4882a593Smuzhiyunelse 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun# Configure package for host 212*4882a593Smuzhiyun# disable all kind of documentation generation in the process, 213*4882a593Smuzhiyun# because it often relies on host tools which may or may not be 214*4882a593Smuzhiyun# installed. 215*4882a593Smuzhiyundefine $(2)_CONFIGURE_CMDS 216*4882a593Smuzhiyun (cd $$($$(PKG)_SRCDIR) && rm -rf config.cache; \ 217*4882a593Smuzhiyun $$(HOST_CONFIGURE_OPTS) \ 218*4882a593Smuzhiyun CFLAGS="$$(HOST_CFLAGS)" \ 219*4882a593Smuzhiyun LDFLAGS="$$(HOST_LDFLAGS)" \ 220*4882a593Smuzhiyun $$($$(PKG)_CONF_ENV) \ 221*4882a593Smuzhiyun CONFIG_SITE=/dev/null \ 222*4882a593Smuzhiyun ./configure \ 223*4882a593Smuzhiyun --prefix="$$(HOST_DIR)" \ 224*4882a593Smuzhiyun --sysconfdir="$$(HOST_DIR)/etc" \ 225*4882a593Smuzhiyun --localstatedir="$$(HOST_DIR)/var" \ 226*4882a593Smuzhiyun --enable-shared --disable-static \ 227*4882a593Smuzhiyun --disable-gtk-doc \ 228*4882a593Smuzhiyun --disable-gtk-doc-html \ 229*4882a593Smuzhiyun --disable-doc \ 230*4882a593Smuzhiyun --disable-docs \ 231*4882a593Smuzhiyun --disable-documentation \ 232*4882a593Smuzhiyun --disable-debug \ 233*4882a593Smuzhiyun --with-xmlto=no \ 234*4882a593Smuzhiyun --with-fop=no \ 235*4882a593Smuzhiyun --disable-nls \ 236*4882a593Smuzhiyun $$(if $$($$(PKG)_OVERRIDE_SRCDIR),,--disable-dependency-tracking) \ 237*4882a593Smuzhiyun $$(QUIET) $$($$(PKG)_CONF_OPTS) \ 238*4882a593Smuzhiyun ) 239*4882a593Smuzhiyunendef 240*4882a593Smuzhiyunendif 241*4882a593Smuzhiyunendif 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun$(2)_POST_PATCH_HOOKS += UPDATE_CONFIG_HOOK 244*4882a593Smuzhiyun 245*4882a593Smuzhiyunifeq ($$($(2)_AUTORECONF),YES) 246*4882a593Smuzhiyun 247*4882a593Smuzhiyun# This has to come before autoreconf 248*4882a593Smuzhiyunifeq ($$($(2)_GETTEXTIZE),YES) 249*4882a593Smuzhiyun$(2)_PRE_CONFIGURE_HOOKS += GETTEXTIZE_HOOK 250*4882a593Smuzhiyun$(2)_DEPENDENCIES += host-gettext 251*4882a593Smuzhiyunendif 252*4882a593Smuzhiyun$(2)_PRE_CONFIGURE_HOOKS += AUTORECONF_HOOK 253*4882a593Smuzhiyun# default values are not evaluated yet, so don't rely on this defaulting to YES 254*4882a593Smuzhiyunifneq ($$($(2)_LIBTOOL_PATCH),NO) 255*4882a593Smuzhiyun$(2)_PRE_CONFIGURE_HOOKS += LIBTOOL_PATCH_HOOK 256*4882a593Smuzhiyunendif 257*4882a593Smuzhiyun$(2)_DEPENDENCIES += host-automake host-autoconf host-libtool 258*4882a593Smuzhiyun 259*4882a593Smuzhiyunelse # ! AUTORECONF = YES 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun# default values are not evaluated yet, so don't rely on this defaulting to YES 262*4882a593Smuzhiyunifneq ($$($(2)_LIBTOOL_PATCH),NO) 263*4882a593Smuzhiyun$(2)_POST_PATCH_HOOKS += LIBTOOL_PATCH_HOOK 264*4882a593Smuzhiyunendif 265*4882a593Smuzhiyun 266*4882a593Smuzhiyunendif 267*4882a593Smuzhiyun 268*4882a593Smuzhiyun# Append a configure hook if building for a powerpc64 (or powerpc64le) arch. 269*4882a593Smuzhiyun# Must be added after other pre-configure hooks that might regenerate the 270*4882a593Smuzhiyun# configure script and overwrite the changes made here. 271*4882a593Smuzhiyunifneq ($$(filter powerpc64%,$$(if $$(filter target,$(4)),$$(ARCH),$$(HOSTARCH))),) 272*4882a593Smuzhiyun$(2)_PRE_CONFIGURE_HOOKS += CONFIGURE_FIX_POWERPC64_HOOK 273*4882a593Smuzhiyunendif 274*4882a593Smuzhiyun 275*4882a593Smuzhiyun# 276*4882a593Smuzhiyun# Build step. Only define it if not already defined by the package .mk 277*4882a593Smuzhiyun# file. 278*4882a593Smuzhiyun# 279*4882a593Smuzhiyunifndef $(2)_BUILD_CMDS 280*4882a593Smuzhiyunifeq ($(4),target) 281*4882a593Smuzhiyundefine $(2)_BUILD_CMDS 282*4882a593Smuzhiyun $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR) 283*4882a593Smuzhiyunendef 284*4882a593Smuzhiyunelse 285*4882a593Smuzhiyundefine $(2)_BUILD_CMDS 286*4882a593Smuzhiyun $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_MAKE_OPTS) -C $$($$(PKG)_SRCDIR) 287*4882a593Smuzhiyunendef 288*4882a593Smuzhiyunendif 289*4882a593Smuzhiyunendif 290*4882a593Smuzhiyun 291*4882a593Smuzhiyun# 292*4882a593Smuzhiyun# Host installation step. Only define it if not already defined by the 293*4882a593Smuzhiyun# package .mk file. 294*4882a593Smuzhiyun# 295*4882a593Smuzhiyunifndef $(2)_INSTALL_CMDS 296*4882a593Smuzhiyundefine $(2)_INSTALL_CMDS 297*4882a593Smuzhiyun $$(HOST_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_OPTS) -C $$($$(PKG)_SRCDIR) 298*4882a593Smuzhiyunendef 299*4882a593Smuzhiyunendif 300*4882a593Smuzhiyun 301*4882a593Smuzhiyun# 302*4882a593Smuzhiyun# Staging installation step. Only define it if not already defined by 303*4882a593Smuzhiyun# the package .mk file. 304*4882a593Smuzhiyun# 305*4882a593Smuzhiyunifndef $(2)_INSTALL_STAGING_CMDS 306*4882a593Smuzhiyundefine $(2)_INSTALL_STAGING_CMDS 307*4882a593Smuzhiyun $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_STAGING_OPTS) -C $$($$(PKG)_SRCDIR) 308*4882a593Smuzhiyunendef 309*4882a593Smuzhiyunendif 310*4882a593Smuzhiyun 311*4882a593Smuzhiyun# 312*4882a593Smuzhiyun# Target installation step. Only define it if not already defined by 313*4882a593Smuzhiyun# the package .mk file. 314*4882a593Smuzhiyun# 315*4882a593Smuzhiyunifndef $(2)_INSTALL_TARGET_CMDS 316*4882a593Smuzhiyundefine $(2)_INSTALL_TARGET_CMDS 317*4882a593Smuzhiyun $$(TARGET_MAKE_ENV) $$($$(PKG)_MAKE_ENV) $$($$(PKG)_MAKE) $$($$(PKG)_INSTALL_TARGET_OPTS) -C $$($$(PKG)_SRCDIR) 318*4882a593Smuzhiyunendef 319*4882a593Smuzhiyunendif 320*4882a593Smuzhiyun 321*4882a593Smuzhiyun# Call the generic package infrastructure to generate the necessary 322*4882a593Smuzhiyun# make targets 323*4882a593Smuzhiyun$(call inner-generic-package,$(1),$(2),$(3),$(4)) 324*4882a593Smuzhiyun 325*4882a593Smuzhiyunendef 326*4882a593Smuzhiyun 327*4882a593Smuzhiyun################################################################################ 328*4882a593Smuzhiyun# autotools-package -- the target generator macro for autotools packages 329*4882a593Smuzhiyun################################################################################ 330*4882a593Smuzhiyun 331*4882a593Smuzhiyunautotools-package = $(call inner-autotools-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target) 332*4882a593Smuzhiyunhost-autotools-package = $(call inner-autotools-package,host-$(pkgname),$(call UPPERCASE,host-$(pkgname)),$(call UPPERCASE,$(pkgname)),host) 333