# make.conf optimizations? (optimizing builds)



## poorandunlucky (Nov 28, 2017)

Hey... is there any way to optimize builds further than through the ports' options menu?  Like some options in make.conf...  I've read of some, but their use was disputed, and it was an old thread...

I have a Core i7, if that's relevant...


----------



## rigoletto@ (Nov 28, 2017)

poorandunlucky

You should really start getting used to use `man`. make.conf(5)

Just a word of advise, do not try to mess with `CFLAGS` and `CXXFLAGS` like we usually do in Gentoo, for instance.

In FreeBSD the things are usually already set to have the best configuration. Trying to change those without actually knowing exactly what you are doing can led you to some very sad situations.

As reference, this is my make.conf optimizations, what some could argue it already have too many "optimizations".

Most of them bring little to no advantages, but as a former Gentoo user I just can't resist.


```
CPUTYPE?=native
OPTIMIZED_CFLAGS=YES
BUILD_OPTIMIZED=YES
WITH_CPUFLAGS=YES
```

*Some of those may be deprecated. I indeed need to look for it later.


----------



## poorandunlucky (Nov 28, 2017)

lebarondemerde said:


> Some of those may be deprecated. I indeed need to look for it later.



You should get used to reading the manual pages  : P

Also, I've never used Gentoo...  Guys on 4chan use it, though, but I never...  I've just used Ubuntu from a live cd for a while...

Also manual pages explain what things are, but often they're not entirely representative of what people actually do, and don't include what people at large have come up with...


----------



## ShelLuser (Nov 28, 2017)

poorandunlucky said:


> Also manual pages explain what things are, but often they're not entirely representative of what people actually do, and don't include what people at large have come up with...


Maybe on Linux, but FreeBSD does this a "little" different. Manual pages are actually what they claim to be: pages which provide an actual manual.

(edit)

Guess I can do a little better than that: see, although you're right that generally speaking you get a lot of options which you can use, they're also explaining what those options are and do. Thus providing you with enough information to determine if the option is applicable to your situation or not.

Another very important section, one which I think is often overlooked, is SEE ALSO. Generally speaking (there are always exceptions) those will point you to other resources which can provide more detailed and/or extra information about the task at hand.

And when it comes to general tasks, such as optimizing, then it can honestly help.


----------



## rigoletto@ (Nov 28, 2017)

After some reading and doing some quick questions in #freebsd (IRC), I come with a better solution:

```
CPUTYPE?=bdver1
```

Yeah, just that.

There is no `native` option in /usr/src/share/mk/bsd.cpu.mk for "CPUTYPE".

So, running `make -C /usr/src CPUTYPE=native -V MACHINE_CPU` show a very small set of instructions.

It should be probably ok, if using for ports, because at least it changes -march in CFLAGS/CXXFLAGS, if checking:

`make -C /usr/src CPUTYPE=native -V`

The best option would be setting the correct/actual one, but first we need to discover what is that:

`sh -c "clang -v -fsyntax-only -march=native -x c /dev/null 2>&1 | grep -e '-target-cpu' | sed -e 's|.*-target-cpu \([[:alnum:]]*\) .*|\1|'"`

For me it is *bdver1*, as pointed earlier.

Running `make -C /usr/src CPUTYPE=bdver1 -V MACHINE_CPU` show all supported instructions set. 

And match with is in /usr/share/mk/bsd.cpu.mk :

```
. elif ${CPUTYPE} == "bdver3" || ${CPUTYPE} == "bdver2" || \
${CPUTYPE} == "bdver1"
MACHINE_CPU = xop avx sse42 sse41 ssse3 sse4a sse3
```

Now, time to rebuild EVERYTHING to see if this change will break anything.


----------



## rigoletto@ (Nov 28, 2017)

ShelLuser

Op is coming from Windows, he is not too familiar with unix{-like} things.


----------



## poorandunlucky (Nov 30, 2017)

ShelLuser said:


> Maybe on Linux, but FreeBSD does this a "little" different. Manual pages are actually what they claim to be: pages which provide an actual manual.
> 
> (edit)
> 
> ...



It's not what I mean... physicians get to cram massive textbooks, yet, even though they assimilated tons of theory and texts and journals and stuff like that, they still have to do a clerkship for three years where someone takes them by the hand or watches behind a curtain while they pretend to be on their own, and also do things as groups with other pupils, etc. so they study for four years to learn what's what and how things are done, and then they do a clerkship for another three to learn what things actually are how things are really done.

That's what I meant...

It's a great textbook, but textbooks are safe...  They're made that way...  *shrugs*



lebarondemerde said:


> After some reading and doing some quick questions in #freebsd (IRC), I come with a better solution:
> 
> ```
> CPUTYPE?=bdver1
> ...



Mine is a Nehalem!

Shweet.  Now I can add something to make.conf.  i'm a 733t h@x0r.  : x




lebarondemerde said:


> ShelLuser
> 
> Op is coming from Windows, he is not too familiar with unix{-like} things.



That's not true...  I first started with Slackware to have the best "authentic UNIX experience" I could have without biting off more than I could chew, and then I ran Windows, then MacOS X came, and I realized it was FreeBSD, but you could boot into console mode with root access holding down two buttons, so I was like "lawl no", but that was fixed and I had one of those iMacs with the articulated screen... they looked like a lamp... people called them lamps...  It was awesome, and the man pages read "FreeBSD", and I learned about the licenses, and I thought what they did was not cool, so I tried to install FreeBSD on the PowerPC machine, but it wouldn't take it, and eventually I got a cheap amd64 laptop to replace the dying iMac (pretty sure it was remotely deactivated, tbqh, but that's an old story, and quite possibly just a fact of life, so... moving on) but it had Intel integrated graphics, and the KMS/DRM modules were still being written... that was FreeBSD 8.2, I think, but I ran it in stretched screen and in 80-chars wide console on a 15.6" 16:10 screen for quite some time until the CPU would constantly overheat and I couldn't build anything anymore, barely could run Chrome...  Then I think I ran Ubuntu off a Live Memstick for a long time because I was very poor, not very interested, and I didn't want to erase my hard drive...  I never got into Ubuntu much, though, and just used Firefox...  Everything I did always got erased when it'd crash, anyway, so I never bothered even changing the wallpaper that had a weird hue... it's like the screen was reflective, somehow...  It was hurting my eyes...  It was uncomfortable to watch, and kind of weird...  Then I understood that even if two software do the same thing, they're different in how they do it, and the way Linux did things wasn't appropriate to me, so I just waited, and I didn't really have a need for more than a web browser, anyway... wasn't really interested in computers for a while...

But I read The UNIX Bible (a huge red book) cover to cover, that covered Redhat and Solaris, and I've used FreeBSD for some time now...

Anyway, all that to say I'm not exactly a n3wb.  : [


----------



## Alain De Vos (Nov 6, 2022)

rigoletto@ said:


> poorandunlucky
> 
> You should really start getting used to use `man`. make.conf(5)
> 
> ...


OPTIONS_SET+=OPTIMIZED_CFLAGS


----------

