# Suggestions for a safe compiler options for buildworld/kernel/ports?



## mrjayviper (Aug 12, 2015)

So I used an old /etc/make.conf and it had the option
CXXFLAGS+=-fconserve-space which cause build world to fail, so I removed this option.

So I guess I'm asking what your recommended/suggestion compiler option that still optimize my system a bit but without being overkill.

This is what I currently have.


```
CPUTYPE?=athlon64
CFLAGS= -O2 -fno-strict-aliasing -pipe
CXXFLAGS+=
MAKE_SHELL?=sh
COPTFLAGS= -O -pipe
```

Thanks a lot!


----------



## wisdown (Aug 12, 2015)

From weeks lost compiling stuff and losing because set the things on /etc/make.conf I would say for let this empty or enable only in some situations:

The reason:

Mostly programs have defaults for get build correctly, and when you set something on /etc/make.conf you would override the defaults and failed at some point.


----------



## kpa (Aug 12, 2015)

I would keep only CPUTYPE. The others are too dangerous to set globally. You never know what kind of bugs you'll be triggering on code that is hand tailored to produce the expected output and depend on the exact combination of compiler flags set in the kernel's own Makefiles. If you must set compiler flags do it conditionally for specific targets, for example (from /usr/share/examples/etc/make.conf):


```
.if ${.CURDIR:M*/irc/irssi-devel*}
WITH_DEBUG=YES
.endif
```

That would compile the port irc/irssi-devel with WITH_DEBUG option set.

The usefulness of compiler optimization is a difficult and controversial topic. I'm strongly in the opinion that the compiler is never capable of improving any code enough to justify the optimizations other than the most basic ones, unrolling loops etc that all the compilers do almost by default now unless you use -O0. It's much more beneficial to spend time searching for better algorithms for the task at hand. This of course if you are the programmer working on the code.


----------



## wblock@ (Aug 12, 2015)

That CFLAGS setting will actually make things less optimized, not more.  Some ports have the option to use custom CFLAGS settings that have been tested with the port.  Forcing a certain CFLAGS setting in /etc/make.conf overrides those port options and prevents them from being used.


----------

