12.11. Respect `CFLAGS`
前一頁 | 章 12. Dos and Don'ts | 下一頁

## 12.11. Respect `CFLAGS`

The port should respect the `CFLAGS` variable. What we mean by this is that the port should not set the value of this variable absolutely, overriding the existing value; instead, it should append whatever values it needs to the existing value. This is so that build options that affect all ports can be set globally.

If it does not, please add `NO_PACKAGE=ignores cflags` to the `Makefile`.

An example of a `Makefile` respecting the `CFLAGS` variable follows. Note the `+=`:

CFLAGS+= -Wall -Werror

Here is an example which does not respect the `CFLAGS` variable:

CFLAGS= -Wall -Werror

The `CFLAGS` variable is defined on FreeBSD systems in `/etc/make.conf`. The first example appends additional flags to the `CFLAGS` variable, preserving any system-wide definitions. The second example clobbers anything previously defined.

You should remove optimization flags from the third party `Makefile`s. System `CFLAGS` contains system-wide optimization flags. An example from an unmodified `Makefile`:

CFLAGS= -O3 -funroll-loops -DHAVE_SOUND

Using system optimization flags, the `Makefile` would look similar to the following example:

CFLAGS+= -DHAVE_SOUND

前一頁 | 上一層 | 下一頁
12.10. Respect both `CC` and `CXX` | 起始頁 | 12.12. Threading libraries

本文及其他文件，可由此下載： ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。

若有 FreeBSD 方面疑問，請先閱讀 FreeBSD 相關文件，如不能解決的話，再洽詢 <questions@FreeBSD.org>。
關於本文件的問題，請洽詢 <doc@FreeBSD.org>。