# compiling optimization for a specific processor when using ports



## jronald (Sep 23, 2018)

For example, how to add compiling option "-march=native" globally?

Thanks


----------



## zirias@ (Sep 23, 2018)

See make.conf(5), just set `CFLAGS` there. But I'm not sure this is the greatest idea ...


----------



## jronald (Sep 23, 2018)

Zirias said:


> See make.conf(5), just set `CFLAGS` there. But I'm not sure this is the greatest idea ...


Optimzation for specific CPU, just like what JIT does. Why not the greatest idea? What is the greatest one?


----------



## zirias@ (Sep 24, 2018)

jronald said:


> Why not the greatest idea?


Speed benefits are minimal (at least in the x86 family) but you can't ever use your compiled binaries on a different machine. Even worse, some software has very subtle bugs that are only "discovered" by optimizing -- you might just break your system.


----------



## SirDice (Sep 24, 2018)

Ports (and everything else) already tend to use the most optimal compiler options. There's very little to gain here.


----------



## diizzy (Sep 24, 2018)

Setting CPUTYPE isn't a bad idea,


```
/usr/share/examples/etc/make.conf
```


```
/etc/make.conf
CPUTYPE?=nehalem
```

Not an optimization of binaries but setting MAKE_JOBS_NUMBER to something sane for your system speeds up things tremendously.

```
MAKE_JOBS_NUMBER=4
```

Do not play around with CFLAGS or COPTFLAGS etc however


----------

