xref: /OK3568_Linux_fs/buildroot/docs/manual/adding-packages-autotools.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun// -*- mode:doc; -*-
2*4882a593Smuzhiyun// vim: set syntax=asciidoc:
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun=== Infrastructure for autotools-based packages
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun[[autotools-package-tutorial]]
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun==== +autotools-package+ tutorial
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunFirst, let's see how to write a +.mk+ file for an autotools-based
11*4882a593Smuzhiyunpackage, with an example :
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun------------------------
14*4882a593Smuzhiyun01: ################################################################################
15*4882a593Smuzhiyun02: #
16*4882a593Smuzhiyun03: # libfoo
17*4882a593Smuzhiyun04: #
18*4882a593Smuzhiyun05: ################################################################################
19*4882a593Smuzhiyun06:
20*4882a593Smuzhiyun07: LIBFOO_VERSION = 1.0
21*4882a593Smuzhiyun08: LIBFOO_SOURCE = libfoo-$(LIBFOO_VERSION).tar.gz
22*4882a593Smuzhiyun09: LIBFOO_SITE = http://www.foosoftware.org/download
23*4882a593Smuzhiyun10: LIBFOO_INSTALL_STAGING = YES
24*4882a593Smuzhiyun11: LIBFOO_INSTALL_TARGET = NO
25*4882a593Smuzhiyun12: LIBFOO_CONF_OPTS = --disable-shared
26*4882a593Smuzhiyun13: LIBFOO_DEPENDENCIES = libglib2 host-pkgconf
27*4882a593Smuzhiyun14:
28*4882a593Smuzhiyun15: $(eval $(autotools-package))
29*4882a593Smuzhiyun------------------------
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunOn line 7, we declare the version of the package.
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunOn line 8 and 9, we declare the name of the tarball (xz-ed tarball recommended)
34*4882a593Smuzhiyunand the location of the tarball on the Web. Buildroot will automatically
35*4882a593Smuzhiyundownload the tarball from this location.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunOn line 10, we tell Buildroot to install the package to the staging
38*4882a593Smuzhiyundirectory. The staging directory, located in +output/staging/+
39*4882a593Smuzhiyunis the directory where all the packages are installed, including their
40*4882a593Smuzhiyundevelopment files, etc. By default, packages are not installed to the
41*4882a593Smuzhiyunstaging directory, since usually, only libraries need to be installed in
42*4882a593Smuzhiyunthe staging directory: their development files are needed to compile
43*4882a593Smuzhiyunother libraries or applications depending on them. Also by default, when
44*4882a593Smuzhiyunstaging installation is enabled, packages are installed in this location
45*4882a593Smuzhiyunusing the +make install+ command.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunOn line 11, we tell Buildroot to not install the package to the
48*4882a593Smuzhiyuntarget directory. This directory contains what will become the root
49*4882a593Smuzhiyunfilesystem running on the target. For purely static libraries, it is
50*4882a593Smuzhiyunnot necessary to install them in the target directory because they will
51*4882a593Smuzhiyunnot be used at runtime. By default, target installation is enabled; setting
52*4882a593Smuzhiyunthis variable to NO is almost never needed. Also by default, packages are
53*4882a593Smuzhiyuninstalled in this location using the +make install+ command.
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunOn line 12, we tell Buildroot to pass a custom configure option, that
56*4882a593Smuzhiyunwill be passed to the +./configure+ script before configuring
57*4882a593Smuzhiyunand building the package.
58*4882a593Smuzhiyun
59*4882a593SmuzhiyunOn line 13, we declare our dependencies, so that they are built
60*4882a593Smuzhiyunbefore the build process of our package starts.
61*4882a593Smuzhiyun
62*4882a593SmuzhiyunFinally, on line line 15, we invoke the +autotools-package+
63*4882a593Smuzhiyunmacro that generates all the Makefile rules that actually allows the
64*4882a593Smuzhiyunpackage to be built.
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun[[autotools-package-reference]]
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun==== +autotools-package+ reference
69*4882a593Smuzhiyun
70*4882a593SmuzhiyunThe main macro of the autotools package infrastructure is
71*4882a593Smuzhiyun+autotools-package+. It is similar to the +generic-package+ macro. The ability to
72*4882a593Smuzhiyunhave target and host packages is also available, with the
73*4882a593Smuzhiyun+host-autotools-package+ macro.
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunJust like the generic infrastructure, the autotools infrastructure
76*4882a593Smuzhiyunworks by defining a number of variables before calling the
77*4882a593Smuzhiyun+autotools-package+ macro.
78*4882a593Smuzhiyun
79*4882a593SmuzhiyunFirst, all the package metadata information variables that exist in the
80*4882a593Smuzhiyungeneric infrastructure also exist in the autotools infrastructure:
81*4882a593Smuzhiyun+LIBFOO_VERSION+, +LIBFOO_SOURCE+,
82*4882a593Smuzhiyun+LIBFOO_PATCH+, +LIBFOO_SITE+,
83*4882a593Smuzhiyun+LIBFOO_SUBDIR+, +LIBFOO_DEPENDENCIES+,
84*4882a593Smuzhiyun+LIBFOO_INSTALL_STAGING+, +LIBFOO_INSTALL_TARGET+.
85*4882a593Smuzhiyun
86*4882a593SmuzhiyunA few additional variables, specific to the autotools infrastructure,
87*4882a593Smuzhiyuncan also be defined. Many of them are only useful in very specific
88*4882a593Smuzhiyuncases, typical packages will therefore only use a few of them.
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun* +LIBFOO_SUBDIR+ may contain the name of a subdirectory
91*4882a593Smuzhiyun  inside the package that contains the configure script. This is useful,
92*4882a593Smuzhiyun  if for example, the main configure script is not at the root of the
93*4882a593Smuzhiyun  tree extracted by the tarball. If +HOST_LIBFOO_SUBDIR+ is
94*4882a593Smuzhiyun  not specified, it defaults to +LIBFOO_SUBDIR+.
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun* +LIBFOO_CONF_ENV+, to specify additional environment
97*4882a593Smuzhiyun  variables to pass to the configure script. By default, empty.
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun* +LIBFOO_CONF_OPTS+, to specify additional configure
100*4882a593Smuzhiyun  options to pass to the configure script. By default, empty.
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun* +LIBFOO_MAKE+, to specify an alternate +make+
103*4882a593Smuzhiyun  command. This is typically useful when parallel make is enabled in
104*4882a593Smuzhiyun  the configuration (using +BR2_JLEVEL+) but that this
105*4882a593Smuzhiyun  feature should be disabled for the given package, for one reason or
106*4882a593Smuzhiyun  another. By default, set to +$(MAKE)+. If parallel building
107*4882a593Smuzhiyun  is not supported by the package, then it should be set to
108*4882a593Smuzhiyun  +LIBFOO_MAKE=$(MAKE1)+.
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun* +LIBFOO_MAKE_ENV+, to specify additional environment
111*4882a593Smuzhiyun  variables to pass to make in the build step. These are passed before
112*4882a593Smuzhiyun  the +make+ command. By default, empty.
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun* +LIBFOO_MAKE_OPTS+, to specify additional variables to
115*4882a593Smuzhiyun  pass to make in the build step. These are passed after the
116*4882a593Smuzhiyun  +make+ command. By default, empty.
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun* +LIBFOO_AUTORECONF+, tells whether the package should
119*4882a593Smuzhiyun  be autoreconfigured or not (i.e. if the configure script and
120*4882a593Smuzhiyun  Makefile.in files should be re-generated by re-running autoconf,
121*4882a593Smuzhiyun  automake, libtool, etc.). Valid values are +YES+ and
122*4882a593Smuzhiyun  +NO+. By default, the value is +NO+
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun* +LIBFOO_AUTORECONF_ENV+, to specify additional environment
125*4882a593Smuzhiyun  variables to pass to the 'autoreconf' program if
126*4882a593Smuzhiyun  +LIBFOO_AUTORECONF=YES+. These are passed in the environment of
127*4882a593Smuzhiyun  the 'autoreconf' command. By default, empty.
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun* +LIBFOO_AUTORECONF_OPTS+ to specify additional options
130*4882a593Smuzhiyun  passed to the 'autoreconf' program if
131*4882a593Smuzhiyun  +LIBFOO_AUTORECONF=YES+. By default, empty.
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun* +LIBFOO_GETTEXTIZE+, tells whether the package should be
134*4882a593Smuzhiyun  gettextized or not (i.e. if the package uses a different gettext
135*4882a593Smuzhiyun  version than Buildroot provides, and it is needed to run
136*4882a593Smuzhiyun  'gettextize'.) Only valid when +LIBFOO_AUTORECONF=YES+. Valid
137*4882a593Smuzhiyun  values are +YES+ and +NO+. The default is +NO+.
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun* +LIBFOO_GETTEXTIZE_OPTS+, to specify additional options passed to
140*4882a593Smuzhiyun  the 'gettextize' program, if +LIBFOO_GETTEXTIZE=YES+. You may
141*4882a593Smuzhiyun  use that if, for example, the +.po+ files are not located in the
142*4882a593Smuzhiyun  standard place (i.e. in +po/+ at the root of the package.) By
143*4882a593Smuzhiyun  default, '-f'.
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun* +LIBFOO_LIBTOOL_PATCH+ tells whether the Buildroot
146*4882a593Smuzhiyun  patch to fix libtool cross-compilation issues should be applied or
147*4882a593Smuzhiyun  not. Valid values are +YES+ and +NO+. By
148*4882a593Smuzhiyun  default, the value is +YES+
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun* +LIBFOO_INSTALL_STAGING_OPTS+ contains the make options
151*4882a593Smuzhiyun  used to install the package to the staging directory. By default, the
152*4882a593Smuzhiyun  value is +DESTDIR=$(STAGING_DIR) install+, which is
153*4882a593Smuzhiyun  correct for most autotools packages. It is still possible to override
154*4882a593Smuzhiyun  it.
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun* +LIBFOO_INSTALL_TARGET_OPTS+ contains the make options
157*4882a593Smuzhiyun  used to install the package to the target directory. By default, the
158*4882a593Smuzhiyun  value is +DESTDIR=$(TARGET_DIR) install+. The default
159*4882a593Smuzhiyun  value is correct for most autotools packages, but it is still possible
160*4882a593Smuzhiyun  to override it if needed.
161*4882a593Smuzhiyun
162*4882a593SmuzhiyunWith the autotools infrastructure, all the steps required to build
163*4882a593Smuzhiyunand install the packages are already defined, and they generally work
164*4882a593Smuzhiyunwell for most autotools-based packages. However, when required, it is
165*4882a593Smuzhiyunstill possible to customize what is done in any particular step:
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun* By adding a post-operation hook (after extract, patch, configure,
168*4882a593Smuzhiyun  build or install). See xref:hooks[] for details.
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun* By overriding one of the steps. For example, even if the autotools
171*4882a593Smuzhiyun  infrastructure is used, if the package +.mk+ file defines its
172*4882a593Smuzhiyun  own +LIBFOO_CONFIGURE_CMDS+ variable, it will be used
173*4882a593Smuzhiyun  instead of the default autotools one. However, using this method
174*4882a593Smuzhiyun  should be restricted to very specific cases. Do not use it in the
175*4882a593Smuzhiyun  general case.
176