dpkg-buildflags.1 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. .\" dpkg manual page - dpkg-buildflags(1)
  2. .\"
  3. .\" Copyright © 2010-2011 Raphaël Hertzog <hertzog@debian.org>
  4. .\" Copyright © 2011 Kees Cook <kees@debian.org>
  5. .\" Copyright © 2011-2015 Guillem Jover <guillem@debian.org>
  6. .\"
  7. .\" This is free software; you can redistribute it and/or modify
  8. .\" it under the terms of the GNU General Public License as published by
  9. .\" the Free Software Foundation; either version 2 of the License, or
  10. .\" (at your option) any later version.
  11. .\"
  12. .\" This is distributed in the hope that it will be useful,
  13. .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. .\" GNU General Public License for more details.
  16. .\"
  17. .\" You should have received a copy of the GNU General Public License
  18. .\" along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. .
  20. .TH dpkg\-buildflags 1 "2014-09-04" "Debian Project" "dpkg suite"
  21. .SH NAME
  22. dpkg\-buildflags \- returns build flags to use during package build
  23. .
  24. .SH SYNOPSIS
  25. .B dpkg\-buildflags
  26. .RI [ option "...] [" command ]
  27. .
  28. .SH DESCRIPTION
  29. \fBdpkg\-buildflags\fP is a tool to retrieve compilation flags to use during
  30. build of Debian packages.
  31. .
  32. The default flags are defined by the vendor but they can be
  33. extended/overriden in several ways:
  34. .IP 1.
  35. system-wide with \fB/etc/dpkg/buildflags.conf\fP;
  36. .IP 2.
  37. for the current user with \fB$XDG_CONFIG_HOME/dpkg/buildflags.conf\fP
  38. where \fB$XDG_CONFIG_HOME\fP defaults to \fB$HOME/.config\fP;
  39. .IP 3.
  40. temporarily by the user with environment variables (see section
  41. \fBENVIRONMENT\fP);
  42. .IP 4.
  43. dynamically by the package maintainer with environment variables set via
  44. \fBdebian/rules\fP (see section \fBENVIRONMENT\fP).
  45. .P
  46. The configuration files can contain two types of directives:
  47. .TP
  48. .BI SET " flag value"
  49. Override the flag named \fIflag\fP to have the value \fIvalue\fP.
  50. .TP
  51. .BI STRIP " flag value"
  52. Strip from the flag named \fIflag\fP all the build flags listed in \fIvalue\fP.
  53. .TP
  54. .BI APPEND " flag value"
  55. Extend the flag named \fIflag\fP by appending the options given in \fIvalue\fP.
  56. A space is prepended to the appended value if the flag's current value is non-empty.
  57. .TP
  58. .BI PREPEND " flag value"
  59. Extend the flag named \fIflag\fP by prepending the options given in \fIvalue\fP.
  60. A space is appended to the prepended value if the flag's current value is non-empty.
  61. .P
  62. The configuration files can contain comments on lines starting with a hash
  63. (#). Empty lines are also ignored.
  64. .SH COMMANDS
  65. .TP
  66. .BI \-\-dump
  67. Print to standard output all compilation flags and their values. It prints
  68. one flag per line separated from its value by an equal sign
  69. (\(lq\fIflag\fP=\fIvalue\fP\(rq). This is the default action.
  70. .TP
  71. .BI \-\-list
  72. Print the list of flags supported by the current vendor
  73. (one per line). See the \fBSUPPORTED FLAGS\fP section for more
  74. information about them.
  75. .TP
  76. .BI \-\-status
  77. Display any information that can be useful to explain the behaviour of
  78. \fBdpkg\-buildflags\fP (since dpkg 1.16.5): relevant environment variables,
  79. current vendor, state of all feature flags.
  80. Also print the resulting compiler flags with their origin.
  81. This is intended to be run from \fBdebian/rules\fP, so that the build log
  82. keeps a clear trace of the build flags used. This can be useful to diagnose
  83. problems related to them.
  84. .TP
  85. .BI \-\-export= format
  86. Print to standard output commands that can be used to export all the
  87. compilation flags for some particular tool. If the \fIformat\fP value is not
  88. given, \fBsh\fP is assumed. Only compilation flags starting with an
  89. upper case character are included, others are assumed to not be suitable
  90. for the environment. Supported formats:
  91. .RS
  92. .TP
  93. .B sh
  94. Shell commands to set and export all the compilation flags in the
  95. environment. The flag values are quoted so the output is ready for
  96. evaluation by a shell.
  97. .TP
  98. .B cmdline
  99. Arguments to pass to a build program's command line to use all the
  100. compilation flags (since dpkg 1.17.0). The flag values are quoted in
  101. shell syntax.
  102. .TP
  103. .B configure
  104. This is a legacy alias for \fBcmdline\fP.
  105. .TP
  106. .B make
  107. Make directives to set and export all the compilation flags in the
  108. environment. Output can be written to a makefile fragment and
  109. evaluated using an \fBinclude\fP directive.
  110. .RE
  111. .TP
  112. .BI \-\-get " flag"
  113. Print the value of the flag on standard output. Exits with 0
  114. if the flag is known otherwise exits with 1.
  115. .TP
  116. .BI \-\-origin " flag"
  117. Print the origin of the value that is returned by \fB\-\-get\fP. Exits
  118. with 0 if the flag is known otherwise exits with 1. The origin can be one
  119. of the following values:
  120. .RS
  121. .TP
  122. .B vendor
  123. the original flag set by the vendor is returned;
  124. .TP
  125. .B system
  126. the flag is set/modified by a system-wide configuration;
  127. .TP
  128. .B user
  129. the flag is set/modified by a user-specific configuration;
  130. .TP
  131. .B env
  132. the flag is set/modified by an environment-specific configuration.
  133. .RE
  134. .TP
  135. .BI \-\-query\-features " area"
  136. Print the features enabled for a given area (since dpkg 1.16.2).
  137. The only currently recognized
  138. areas on Debian and derivatives are \fBqa\fP, \fBreproducible\fP,
  139. \fBsanitize\fP and \fBhardening\fP, see the \fBFEATURE AREAS\fP
  140. section for more details.
  141. Exits with 0 if the area is known otherwise exits with 1.
  142. .IP
  143. The output is in RFC822 format, with one section per feature.
  144. For example:
  145. .IP
  146. .nf
  147. Feature: pie
  148. Enabled: no
  149. Feature: stackprotector
  150. Enabled: yes
  151. .fi
  152. .TP
  153. .B \-\-help
  154. Show the usage message and exit.
  155. .TP
  156. .B \-\-version
  157. Show the version and exit.
  158. .
  159. .SH SUPPORTED FLAGS
  160. .TP
  161. .B CFLAGS
  162. Options for the C compiler. The default value set by the vendor
  163. includes \fB\-g\fP and the default optimization level (\fB\-O2\fP usually,
  164. or \fB\-O0\fP if the \fBDEB_BUILD_OPTIONS\fP environment variable defines
  165. \fInoopt\fP).
  166. .TP
  167. .B CPPFLAGS
  168. Options for the C preprocessor. Default value: empty.
  169. .TP
  170. .B CXXFLAGS
  171. Options for the C++ compiler. Same as \fBCFLAGS\fP.
  172. .TP
  173. .B OBJCFLAGS
  174. Options for the Objective C compiler. Same as \fBCFLAGS\fP.
  175. .TP
  176. .B OBJCXXFLAGS
  177. Options for the Objective C++ compiler. Same as \fBCXXFLAGS\fP.
  178. .TP
  179. .B GCJFLAGS
  180. Options for the GNU Java compiler (gcj). A subset of \fBCFLAGS\fP.
  181. .TP
  182. .B FFLAGS
  183. Options for the Fortran 77 compiler. A subset of \fBCFLAGS\fP.
  184. .TP
  185. .B FCFLAGS
  186. Options for the Fortran 9x compiler. Same as \fBFFLAGS\fP.
  187. .TP
  188. .B LDFLAGS
  189. Options passed to the compiler when linking executables or shared
  190. objects (if the linker is called directly, then
  191. .B \-Wl
  192. and
  193. .B ,
  194. have to be stripped from these options). Default value: empty.
  195. .PP
  196. New flags might be added in the future if the need arises (for example
  197. to support other languages).
  198. .
  199. .SH FEATURE AREAS
  200. .P
  201. Each area feature can be enabled and disabled in the \fBDEB_BUILD_OPTIONS\fP
  202. and \fBDEB_BUILD_MAINT_OPTIONS\fP environment variable's area value with the
  203. \(oq\fB+\fP\(cq and \(oq\fB\-\fP\(cq modifier.
  204. For example, to enable the \fBhardening\fP \(lqpie\(rq feature and disable the
  205. \(lqfortify\(rq feature you can do this in \fBdebian/rules\fP:
  206. .P
  207. export DEB_BUILD_MAINT_OPTIONS=hardening=+pie,\-fortify
  208. .P
  209. The special feature \fBall\fP (valid in any area) can be used to enable or
  210. disable all area features at the same time.
  211. Thus disabling everything in the \fBhardening\fP area and enabling only
  212. \(lqformat\(rq and \(lqfortify\(rq can be achieved with:
  213. .P
  214. export DEB_BUILD_MAINT_OPTIONS=hardening=\-all,+format,+fortify
  215. .
  216. .SS qa
  217. Several compile-time options (detailed below) can be used to help detect
  218. problems in the source code or build system.
  219. .TP
  220. .B bug
  221. This setting (disabled by default) adds any warning option that reliably
  222. detects problematic source code. The warnings are fatal.
  223. The only currently supported flags are \fBCFLAGS\fP and \fBCXXFLAGS\fP
  224. with flags set to \fB\-Werror=array\-bounds\fP, \fB\%\-Werror=clobbered\fP,
  225. \fB\%\-Werror=implicit\-function\-declaration\fP and
  226. \fB\%\-Werror=volatile\-register\-var\fP.
  227. .
  228. .TP
  229. .B canary
  230. This setting (disabled by default) adds dummy canary options to the build
  231. flags, so that the build logs can be checked for how the build flags
  232. propagate and to allow finding any omission of normal build flag settings.
  233. The only currently supported flags are \fBCPPFLAGS\fP, \fBCFLAGS\fP,
  234. \fBOBJCFLAGS\fP, \fBCXXFLAGS\fP and \fBOBJCXXFLAGS\fP with flags set
  235. to \fB\-D__DEB_CANARY_\fP\fIflag\fP_\fIrandom-id\fP\fB__\fP, and
  236. \fBLDFLAGS\fP set to \fB\-Wl,\-z,deb-canary\-\fP\fIrandom-id\fP.
  237. .
  238. .SS sanitize
  239. Several compile-time options (detailed below) can be used to help sanitize
  240. a resulting binary against memory corruptions, memory leaks, use after free,
  241. threading data races and undefined behavior bugs.
  242. .TP
  243. .B address
  244. This setting (disabled by default) adds \fB\-fsanitize=address\fP to
  245. \fBLDFLAGS\fP and \fB\-fsanitize=address \-fno\-omit\-frame\-pointer\fP to
  246. \fBCFLAGS\fP and \fBCXXFLAGS\fP.
  247. .TP
  248. .B thread
  249. This setting (disabled by default) adds \fB\-fsanitize=thread\fP to
  250. \fBCFLAGS\fP, \fBCXXFLAGS\fP and \fBLDFLAGS\fP.
  251. .TP
  252. .B leak
  253. This setting (disabled by default) adds \fB\-fsanitize=leak\fP to
  254. \fBLDFLAGS\fP. It gets automatically disabled if either the \fBaddress\fP
  255. or the \fBthread\fP features are enabled, as they imply it.
  256. .TP
  257. .B undefined
  258. This setting (disabled by default) adds \fB\-fsanitize=undefined\fP to
  259. \fBCFLAGS\fP, \fBCXXFLAGS\fP and \fBLDFLAGS\fP.
  260. .SS hardening
  261. Several compile-time options (detailed below) can be used to help harden
  262. a resulting binary against memory corruption attacks, or provide
  263. additional warning messages during compilation.
  264. Except as noted below, these are enabled by default for architectures
  265. that support them.
  266. .TP
  267. .B format
  268. This setting (enabled by default) adds
  269. .B \-Wformat \-Werror=format\-security
  270. to \fBCFLAGS\fP, \fBCXXFLAGS\fP, \fBOBJCFLAGS\fP and \fBOBJCXXFLAGS\fP.
  271. This will warn about improper format
  272. string uses, and will fail when format functions are used in a way
  273. that represent possible security problems. At present, this warns about
  274. calls to \fBprintf\fP and \fBscanf\fP functions where the format string is
  275. not a string literal and there are no format arguments, as in
  276. \fBprintf(foo);\fP instead of \fPprintf("%s", foo);\fP
  277. This may be a security hole if the format string came from untrusted
  278. input and contains \(oq%n\(cq.
  279. .
  280. .TP
  281. .B fortify
  282. This setting (enabled by default) adds
  283. .B \-D_FORTIFY_SOURCE=2
  284. to \fBCPPFLAGS\fP. During code generation the compiler
  285. knows a great deal of information about buffer sizes (where possible), and
  286. attempts to replace insecure unlimited length buffer function calls with
  287. length-limited ones. This is especially useful for old, crufty code.
  288. Additionally, format strings in writable memory that contain \(oq%n\(cq are
  289. blocked. If an application depends on such a format string, it will need
  290. to be worked around.
  291. Note that for this option to have any effect, the source must also
  292. be compiled with \fB\-O1\fP or higher. If the environment variable
  293. \fBDEB_BUILD_OPTIONS\fP contains \fInoopt\fP, then \fBfortify\fP
  294. support will be disabled, due to new warnings being issued by
  295. glibc 2.16 and later.
  296. .TP
  297. .B stackprotector
  298. This setting (enabled by default if stackprotectorstrong is not in use) adds
  299. .B \-fstack\-protector \-\-param=ssp\-buffer\-size=4
  300. to \fBCFLAGS\fP, \fBCXXFLAGS\fP, \fBOBJCFLAGS\fP, \fBOBJCXXFLAGS\fP,
  301. \fBGCJFLAGS\fP, \fBFFLAGS\fP and \fBFCFLAGS\fP.
  302. This adds safety checks against stack
  303. overwrites. This renders many potential code injection attacks into
  304. aborting situations. In the best case this turns code injection
  305. vulnerabilities into denial of service or into non-issues (depending on
  306. the application).
  307. This feature requires linking against glibc (or another provider of
  308. \fB__stack_chk_fail\fP), so needs to be disabled when building with
  309. \fB\-nostdlib\fP or \fB\-ffreestanding\fP or similar.
  310. .
  311. .TP
  312. .B stackprotectorstrong
  313. This setting (enabled by default) adds
  314. .B \-fstack\-protector\-strong
  315. to \fBCFLAGS\fP, \fBCXXFLAGS\fP, \fBOBJCFLAGS\fP, \fBOBJCXXFLAGS\fP,
  316. \fBGCJFLAGS\fP, \fBFFLAGS\fP and \fBFCFLAGS\fP.
  317. This is a stronger variant of \fBstackprotector\fP, but without significant
  318. performance penalties.
  319. Disabling \fBstackprotector\fP will also disable this setting.
  320. This feature has the same requirements as \fBstackprotector\fP, and in
  321. addition also requires gcc 4.9 and later.
  322. .
  323. .TP
  324. .B relro
  325. This setting (enabled by default) adds
  326. .B \-Wl,\-z,relro
  327. to \fBLDFLAGS\fP. During program load, several ELF memory sections need
  328. to be written to by the linker. This flags the loader to turn these
  329. sections read-only before turning over control to the program. Most
  330. notably this prevents GOT overwrite attacks. If this option is disabled,
  331. \fBbindnow\fP will become disabled as well.
  332. .
  333. .TP
  334. .B bindnow
  335. This setting (disabled by default) adds
  336. .B \-Wl,\-z,now
  337. to \fBLDFLAGS\fP. During program load, all dynamic symbols are resolved,
  338. allowing for the entire PLT to be marked read-only (due to \fBrelro\fP
  339. above). The option cannot become enabled if \fBrelro\fP is not enabled.
  340. .
  341. .TP
  342. .B pie
  343. This setting (disabled by default) adds \fB\-fPIE\fP to \fBCFLAGS\fP,
  344. \fBCXXFLAGS\fP, \fBOBJCFLAGS\fP, \fBOBJCXXFLAGS\fP, \fBGCJFLAGS\fP,
  345. \fBFFLAGS\fP and \fBFCFLAGS\fP,
  346. and \fB\-fPIE \-pie\fP to \fBLDFLAGS\fP. Position Independent
  347. Executable are needed to take advantage of Address Space Layout
  348. Randomization, supported by some kernel versions. While ASLR can already
  349. be enforced for data areas in the stack and heap (brk and mmap), the code
  350. areas must be compiled as position-independent. Shared libraries already
  351. do this (\-fPIC), so they gain ASLR automatically, but binary .text
  352. regions need to be build PIE to gain ASLR. When this happens, ROP (Return
  353. Oriented Programming) attacks are much harder since there are no static
  354. locations to bounce off of during a memory corruption attack.
  355. This is not compatible with \fB\-fPIC\fP so care must be taken when
  356. building shared objects.
  357. Static libraries can be used by programs or other shared libraries.
  358. Depending on the flags used to compile all the objects within a static
  359. library, these libraries will be usable by different sets of objects:
  360. .RS
  361. .TP
  362. none
  363. Cannot be linked into a PIE program, nor a shared library.
  364. .TP
  365. .B \-fPIE
  366. Can be linked into any program, but not a shared library.
  367. .TP
  368. .B \-fPIC
  369. Can be linked into any program and shared library.
  370. .RE
  371. .IP
  372. Unconditionally passing \fB\-fPIE\fP, \fB\-fpie\fP or \fB\-pie\fP to a
  373. build-system using libtool is safe as these flags will get stripped when
  374. building shared libraries.
  375. Otherwise on projects that build both programs and shared libraries you
  376. might need to make sure that when building the shared libraries \fB\-fPIC\fP
  377. is always passed last (so that it overrides any previous \fB\-PIE\fP) to
  378. compilation flags such as \fBCFLAGS\fP, and \fB\-shared\fP is passed last
  379. (so that it overrides any previous \fB\-pie\fP) to linking flags such as
  380. \fBLDFLAGS\fP.
  381. .IP
  382. Additionally, since PIE is implemented via a general register, some
  383. register starved architectures (but not including i386 anymore since
  384. optimizations implemented in gcc >= 5) can see performance losses of up to
  385. 15% in very text-segment-heavy application workloads; most workloads
  386. see less than 1%. Architectures with more general registers (e.g. amd64)
  387. do not see as high a worst-case penalty.
  388. .SS reproducible
  389. The compile-time options detailed below can be used to help improve
  390. build reproducibility or provide additional warning messages during
  391. compilation. Except as noted below, these are enabled by default for
  392. architectures that support them.
  393. .TP
  394. .B timeless
  395. This setting (enabled by default) adds
  396. .B \-Wdate\-time
  397. to \fBCPPFLAGS\fP.
  398. This will cause warnings when the \fB__TIME__\fP, \fB__DATE__\fP and
  399. \fB\%__TIMESTAMP__\fP macros are used.
  400. .
  401. .TP
  402. .B fixdebugpath
  403. This setting (disabled by default) adds
  404. .BI \%\-fdebug\-path\-map= BUILDPATH =.
  405. to \fBCFLAGS\fP, \fBCXXFLAGS\fP, \fBOBJCFLAGS\fP, \fBOBJCXXFLAGS\fP,
  406. \fBGCJFLAGS\fP, \fBFFLAGS\fP and \fBFCFLAGS\fP where \fBBUILDPATH\fP is
  407. set to the top-level directory of the package being built.
  408. This has the effect of removing the build path from any generated debug
  409. symbols.
  410. .
  411. .SH ENVIRONMENT
  412. There are 2 sets of environment variables doing the same operations, the
  413. first one (DEB_\fIflag\fP_\fIop\fP) should never be used within
  414. \fBdebian/rules\fP. It's meant for any user that wants to rebuild the
  415. source package with different build flags. The second set
  416. (DEB_\fIflag\fP_MAINT_\fIop\fP) should only be used in \fBdebian/rules\fP
  417. by package maintainers to change the resulting build flags.
  418. .TP
  419. .BI DEB_ flag _SET
  420. .TQ
  421. .BI DEB_ flag _MAINT_SET
  422. This variable can be used to force the value returned for the given
  423. \fIflag\fP.
  424. .TP
  425. .BI DEB_ flag _STRIP
  426. .TQ
  427. .BI DEB_ flag _MAINT_STRIP
  428. This variable can be used to provide a space separated list of options
  429. that will be stripped from the set of flags returned for the given
  430. \fIflag\fP.
  431. .TP
  432. .BI DEB_ flag _APPEND
  433. .TQ
  434. .BI DEB_ flag _MAINT_APPEND
  435. This variable can be used to append supplementary options to the value
  436. returned for the given \fIflag\fP.
  437. .TP
  438. .BI DEB_ flag _PREPEND
  439. .TQ
  440. .BI DEB_ flag _MAINT_PREPEND
  441. This variable can be used to prepend supplementary options to the value
  442. returned for the given \fIflag\fP.
  443. .TP
  444. .B DEB_BUILD_OPTIONS
  445. .TQ
  446. .B DEB_BUILD_MAINT_OPTIONS
  447. These variables can be used by a user or maintainer to disable/enable
  448. various area features that affect build flags.
  449. The \fBDEB_BUILD_MAINT_OPTIONS\fP variable overrides any setting in the
  450. \fBDEB_BUILD_OPTIONS\fP feature areas.
  451. See the \fBFEATURE AREAS\fP section for details.
  452. .TP
  453. .B DEB_VENDOR
  454. This setting defines the current vendor.
  455. If not set, it will discover the current vendor by reading
  456. \fB\%/etc/dpkg/origins/default\fP.
  457. .
  458. .SH FILES
  459. .SS Configuration files
  460. .TP
  461. .B /etc/dpkg/buildflags.conf
  462. System wide configuration file.
  463. .TP
  464. .BR $XDG_CONFIG_HOME/dpkg/buildflags.conf " or "
  465. .TQ
  466. .BR $HOME/.config/dpkg/buildflags.conf
  467. User configuration file.
  468. .SS Packaging support
  469. .TP
  470. .B /usr/share/dpkg/buildflags.mk
  471. Makefile snippet that will load (and optionally export) all flags
  472. supported by \fBdpkg-buildflags\fP into variables (since dpkg 1.16.1).
  473. .
  474. .SH EXAMPLES
  475. To pass build flags to a build command in a makefile:
  476. .PP
  477. .RS 4
  478. .nf
  479. $(MAKE) $(shell dpkg\-buildflags \-\-export=cmdline)
  480. \&./configure $(shell dpkg\-buildflags \-\-export=cmdline)
  481. .fi
  482. .RE
  483. .PP
  484. To set build flags in a shell script or shell fragment, \fBeval\fP can be
  485. used to interpret the output and to export the flags in the environment:
  486. .PP
  487. .RS 4
  488. .nf
  489. eval "$(dpkg\-buildflags \-\-export=sh)" && make
  490. .fi
  491. .RE
  492. .PP
  493. or to set the positional parameters to pass to a command:
  494. .PP
  495. .RS 4
  496. .nf
  497. eval "set \-\- $(dpkg\-buildflags \-\-export=cmdline)"
  498. for dir in a b c; do (cd $dir && ./configure "$@" && make); done
  499. .fi
  500. .RE
  501. .
  502. .SS Usage in debian/rules
  503. You should call \fBdpkg\-buildflags\fP or include \fBbuildflags.mk\fP
  504. from the \fBdebian/rules\fP file to obtain the needed build flags to
  505. pass to the build system.
  506. Note that older versions of \fBdpkg\-buildpackage\fP (before dpkg 1.16.1)
  507. exported these flags automatically. However, you should not rely on this,
  508. since this breaks manual invocation of \fBdebian/rules\fP.
  509. .PP
  510. For packages with autoconf-like build systems, you can pass the relevant
  511. options to configure or \fBmake\fP(1) directly, as shown above.
  512. .PP
  513. For other build systems, or when you need more fine-grained control
  514. about which flags are passed where, you can use \fB\-\-get\fP. Or you
  515. can include \fBbuildflags.mk\fP instead, which takes care of calling
  516. \fB\%dpkg\-buildflags\fP and storing the build flags in make variables.
  517. .PP
  518. If you want to export all buildflags into the environment (where they
  519. can be picked up by your build system):
  520. .PP
  521. .RS 4
  522. .nf
  523. DPKG_EXPORT_BUILDFLAGS = 1
  524. include /usr/share/dpkg/buildflags.mk
  525. .fi
  526. .RE
  527. .PP
  528. For some extra control over what is exported, you can manually export
  529. the variables (as none are exported by default):
  530. .PP
  531. .RS 4
  532. .nf
  533. include /usr/share/dpkg/buildflags.mk
  534. export CPPFLAGS CFLAGS LDFLAGS
  535. .fi
  536. .RE
  537. .PP
  538. And you can of course pass the flags to commands manually:
  539. .PP
  540. .RS 4
  541. .nf
  542. include /usr/share/dpkg/buildflags.mk
  543. build\-arch:
  544. \& $(CC) \-o hello hello.c $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
  545. .fi
  546. .RE