# Compiling Freebsd 12 from source - Error and Questions



## FabricioGuzzy (Mar 21, 2019)

Hello Everyone,
I am trying to compile the Freebsd 12 from Source code and I am facing some issues. Also, I would really appreciate if someone could inform me where to find the "Minimum/Mandatory requirements" for Compiling Version 12.
Background - I am using a Dual XEON CPU (24 Cores) - 100 GB RAM - with FreeBSD freebsd12 12.0-RELEASE FreeBSD 12.0-RELEASE r341666 GENERIC  amd64 - Tried openssl111 and openssl: 1.0.2r,1 - I aso tried CLANG/LLVM40 LLVM50 LLVM60 and LLVM70 - No success.

Here is the Error log: (it seems it is stopping while compiling "/tools/cryptotest"

```
/usr/Kontrol/tmp/obj/usr/Kontrol/tmp/FreeBSD-src/amd64.amd64/tmp/usr/bin/cc -O2 -pipe -DNDEBUG -g -std=gnu99 -fstack-protector-strong -Qunused-arguments   -o cryptotest.full cryptotest.o
objcopy --only-keep-debug cryptotest.full cryptotest.debug
objcopy --strip-debug --add-gnu-debuglink=cryptotest.debug  cryptotest.full cryptotest
(cd /usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto &&  DEPENDFILE=.depend.cryptokeytest  NO_SUBDIR=1 make -f /usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto/Makefile _RECURSING_PROGS=t  PROG=cryptokeytest )
/usr/Kontrol/tmp/obj/usr/Kontrol/tmp/FreeBSD-src/amd64.amd64/tmp/usr/bin/cc  -O2 -pipe   -DNDEBUG -g -MD  -MF.depend.cryptokeytest.cryptokeytest.o -MTcryptokeytest.o -std=gnu99 -fstack-protector-strong    -Qunused-arguments  -c /usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto/cryptokeytest.c -o cryptokeytest.o
/usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto/cryptokeytest.c:113:26: error: incomplete definition of type 'struct bignum_st'
        for (i = 0, j = 0; i < n->top; i++) {
                               ~^
/usr/Kontrol/tmp/obj/usr/Kontrol/tmp/FreeBSD-src/amd64.amd64/tmp/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of
      'struct bignum_st'
typedef struct bignum_st BIGNUM;
               ^
/usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto/cryptokeytest.c:117:17: error: incomplete definition of type 'struct bignum_st'
                        rd[j + k] = n->d[i] >> (k * 8);
                                    ~^
/usr/Kontrol/tmp/obj/usr/Kontrol/tmp/FreeBSD-src/amd64.amd64/tmp/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of
      'struct bignum_st'
typedef struct bignum_st BIGNUM;
               ^
/usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto/cryptokeytest.c:147:25: warning: assigning to 'caddr_t' (aka 'char *') from 'u_int8_t *'
      (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
        kop.crk_param[0].crp_p = ale;
                               ^ ~~~
/usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto/cryptokeytest.c:149:25: warning: assigning to 'caddr_t' (aka 'char *') from 'u_int8_t *'
      (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
        kop.crk_param[1].crp_p = ble;
                               ^ ~~~
/usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto/cryptokeytest.c:151:25: warning: assigning to 'caddr_t' (aka 'char *') from 'u_int8_t *'
      (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
        kop.crk_param[2].crp_p = cle;
                               ^ ~~~
/usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto/cryptokeytest.c:153:25: warning: assigning to 'caddr_t' (aka 'char *') from 'u_int8_t *'
      (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
        kop.crk_param[3].crp_p = cle;
                               ^ ~~~
4 warnings and 2 errors generated.
*** Error code 1

Stop.
make[1]: stopped in /usr/Kontrol/tmp/FreeBSD-src/tools/tools/crypto
*** Error code 1
```
Any help will be very appreciated.

Thanks Much!
Fabricio.


----------



## SirDice (Mar 22, 2019)

FabricioGuzzy said:


> Tried openssl111 and openssl: 1.0.2r,1 - I aso tried CLANG/LLVM40 LLVM50 LLVM60 and LLVM70 - No success.


None of these are used. Those are all external packages. FreeBSD has everything included to build itself. 

Handbook: 23.5. Updating FreeBSD from Source


----------



## Emrion (Mar 22, 2019)

FabricioGuzzy said:


> I am using a Dual XEON CPU (24 Cores) - 100 GB RAM


Concerning requirements I think you are ok... 
You need some GiB left on disk but I'm sure you have that, lol.

Perhaps you should begin by telling us what commands or tuto you used...

Build and install FreeBSD from FreeBSD is usually trivial and straightforward.


----------



## PMc (Mar 22, 2019)

Are You sure the OP is trying to build "FreeBSD from FreeBSD"? The path of the source code looks rather like one would try to compile an application - on whatever OS...


----------



## SirDice (Mar 22, 2019)

It actually doesn't matter where the source tree is. It's typically stored in /usr/src/ but you can build it from any directory. There's no specific setting to adjust, you only need to be in the correct directory. This is especially useful if you need to build different release(7) versions.


----------



## PMc (Mar 22, 2019)

Ah, now I see. Didnt read the OP carefully enough. Sorry.


----------



## FabricioGuzzy (Mar 24, 2019)

Emrion said:


> Concerning requirements I think you are ok...
> You need some GiB left on disk but I'm sure you have that, lol.
> 
> Perhaps you should begin by telling us what commands or tuto you used...
> ...



That´s the pfSense (freebsd) source version 2.5 that is now based on Freebsd 12 - It is supposed to have the same source code as I compared both.
Just not sure where that error is coming from and why it is coming at all. Code for /tools/cryptotest/ is exactly the same. That´s why I asked about the minimum requirements (version and etc) to compile it.
I am still reading and learning from the link sent by SirDice. Could not find anything wrong at this moment.

ps: forget about ask for tips at pfsense forum. Nobody gives a s...

Thanks!!
Fabricio.


----------



## FabricioGuzzy (Mar 24, 2019)

SirDice said:


> None of these are used. Those are all external packages. FreeBSD has everything included to build itself.
> 
> Handbook: 23.5. Updating FreeBSD from Source


Thanks SirDice... I am reading it and comparing it to my processes.
Fabricio.


----------



## Emrion (Mar 24, 2019)

FabricioGuzzy said:


> That´s the pfSense (freebsd) source version 2.5


Alas, we were all talking about pure FreeBSD and the link *SirDice *gave you is about FreeBSD not pfSense. And believe me, this is not the same thing at all from a pratical point of view.

This is not the right place to ask such a question. You should try the Netgate forum.

I don't know and if this is of some importance for what you want to accomplish but there are 2.5 snapshots available since a few time.


----------



## FabricioGuzzy (Mar 24, 2019)

Emrion said:


> Alas, we were all talking about pure FreeBSD and the link *SirDice *gave you is about FreeBSD not pfSense. And believe me, this is not the same thing at all from a pratical point of view.
> 
> This is not the right place to ask such a question. You should try the Netgate forum.
> 
> I don't know and if this is of some importance for what you want to accomplish but there are 2.5 snapshots available since a few time.



Emrion,
Thanks for the message, although I am not asking "pfsense" stuff, but the minimum requirements for compiling FreeBSD 12 like minimum/recommended llvm/clang version, Minimum HW and OS level, etc.  
Like I already mentioned: Forget about pfsense forum. They won't give you a single word on how to do that. 
I´ve been compiling the source for years, now it started to show errors.

Thanks!
Fabricio.


----------



## FabricioGuzzy (Mar 24, 2019)

oh, and by the way... maybe this is relevant... It seems something related to the usage of openssl 1.1.1

https://wiki.freebsd.org/OpenSSL/Base  (see heimdal part)


----------



## FabricioGuzzy (Mar 28, 2019)

OK.. I decided to make a different test.
I tried to compile the same tool but using actual freebsd code (100% pure) and got exactly the same error message for  freebsd/tools/tools/crypto/cryptotest.c

/FreeBSD-src/tools/tools/crypto/cryptokeytest.c:117:17: error: incomplete definition of type 'struct bignum_st'

Does anyone tried to compile this "guy" recently?

Thanks!!
Fabricio.


----------



## kpa (Mar 29, 2019)

Sorry to be this blunt but you're very much asking pfSense questions here and correct place to ask for help is the Netgate forums. PfSense employs a large amount of custom code and patches that turn the system into a quite different animal compared to a vanilla FreeBSD.


----------



## FabricioGuzzy (Mar 29, 2019)

kpa said:


> Sorry to be this blunt but you're very much asking pfSense questions here and correct place to ask for help is the Netgate forums. PfSense employs a large amount of custom code and patches that turn the system into a quite different animal compared to a vanilla FreeBSD.



Well, I don't think you read most of my messages including the last one where i said "*pure freebsd code*" - forget about pfsense.
You don't believe me? so Try to compile  Freebsd/tools/tools/crypto  using openssl111 and see what happens.
Give it a "make" command and wait for it.
So as you can see here, i am having an issue with a "freebsd" component using openssl111 and I don't know how to fix it.

Thanks anyway.


----------



## SirDice (Mar 29, 2019)

The FreeBSD 12.0 source tree contains OpenSSL 1.1.1. The security/openssl111 port has nothing to do with this.


```
dice@case:~ % openssl version
OpenSSL 1.1.1a-freebsd  20 Nov 2018
dice@case:~ % uname -a
FreeBSD case.dicelan.home 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC  amd64
dice@case:~ % pkg version -vR | grep openssl
py27-openssl-18.0.0                =   up-to-date with remote
```






						[base] Revision 340711
					






					svnweb.freebsd.org
				




I also have several 12-STABLE machines that I update on a regular basis, this can only be done from source. They all build just fine.


----------



## FabricioGuzzy (Mar 29, 2019)

SirDice said:


> The FreeBSD 12.0 source tree contains OpenSSL 1.1.1. The security/openssl111 port has nothing to do with it.
> 
> 
> ```
> ...



Hi SirDice,
Thanks for the message. Much appreciated!

I am using the same openssl version here, but see what happens when I try to "make" the crypto:


```
root@freebsd:/usr/src/FreeBSD/tools/tools/crypto # uname -a
FreeBSD freebsd 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC  amd64
root@freebsd:/usr/src/FreeBSD/tools/tools/crypto # openssl version
OpenSSL 1.1.1a-freebsd  20 Nov 2018
root@freebsd:/usr/src/FreeBSD/tools/tools/crypto # ll
total 66
-rw-r--r--  1 root  wheel   2180 Mar 29 10:21 Makefile
-rw-r--r--  1 root  wheel   2503 Mar 29 10:21 README
-rw-r--r--  1 root  wheel  37041 Mar 29 10:21 cryptocheck.c
-rw-r--r--  1 root  wheel   5530 Mar 29 10:21 cryptokeytest.c
-rwxr-xr-x  1 root  wheel    796 Mar 29 10:21 cryptorun.sh*
-rw-r--r--  1 root  wheel   3796 Mar 29 10:21 cryptostats.c
-rw-r--r--  1 root  wheel  17502 Mar 29 10:21 cryptotest.c
-rw-r--r--  1 root  wheel   2423 Mar 29 10:21 hifnstats.c
-rw-r--r--  1 root  wheel   6987 Mar 29 10:21 ipsecstats.c
-rw-r--r--  1 root  wheel   2895 Mar 29 10:21 safestats.c
-rw-r--r--  1 root  wheel   2915 Mar 29 10:21 ubsecstats.c
root@freebsd:/usr/src/FreeBSD/tools/tools/crypto # make
(cd /usr/src/FreeBSD/tools/tools/crypto &&  DEPENDFILE=.depend.cryptocheck  NO_SUBDIR=1 make -f /usr/src/FreeBSD/tools/tools/crypto/Makefile _RECURSING_PROGS=t  PROG=cryptocheck )
(cd /usr/src/FreeBSD/tools/tools/crypto &&  DEPENDFILE=.depend.cryptotest  NO_SUBDIR=1 make -f /usr/src/FreeBSD/tools/tools/crypto/Makefile _RECURSING_PROGS=t  PROG=cryptotest )
(cd /usr/src/FreeBSD/tools/tools/crypto &&  DEPENDFILE=.depend.cryptokeytest  NO_SUBDIR=1 make -f /usr/src/FreeBSD/tools/tools/crypto/Makefile _RECURSING_PROGS=t  PROG=cryptokeytest )
cc  -O2 -pipe   -g -MD  -MF.depend.cryptokeytest.cryptokeytest.o -MTcryptokeytest.o -std=gnu99 -fstack-protector-strong    -Qunused-arguments  -c /usr/src/FreeBSD/tools/tools/crypto/cryptokeytest.c -o cryptokeytest.o
/usr/src/FreeBSD/tools/tools/crypto/cryptokeytest.c:113:26: error: incomplete definition of type 'struct bignum_st'
        for (i = 0, j = 0; i < n->top; i++) {
                               ~^
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of 'struct bignum_st'
typedef struct bignum_st BIGNUM;
               ^
/usr/src/FreeBSD/tools/tools/crypto/cryptokeytest.c:117:17: error: incomplete definition of type 'struct bignum_st'
                        rd[j + k] = n->d[i] >> (k * 8);
                                    ~^
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of 'struct bignum_st'
typedef struct bignum_st BIGNUM;
               ^
/usr/src/FreeBSD/tools/tools/crypto/cryptokeytest.c:147:25: warning: assigning to 'caddr_t' (aka 'char *') from 'u_int8_t *'
      (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
        kop.crk_param[0].crp_p = ale;
                               ^ ~~~
/usr/src/FreeBSD/tools/tools/crypto/cryptokeytest.c:149:25: warning: assigning to 'caddr_t' (aka 'char *') from 'u_int8_t *'
      (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
        kop.crk_param[1].crp_p = ble;
                               ^ ~~~
/usr/src/FreeBSD/tools/tools/crypto/cryptokeytest.c:151:25: warning: assigning to 'caddr_t' (aka 'char *') from 'u_int8_t *'
      (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
        kop.crk_param[2].crp_p = cle;
                               ^ ~~~
/usr/src/FreeBSD/tools/tools/crypto/cryptokeytest.c:153:25: warning: assigning to 'caddr_t' (aka 'char *') from 'u_int8_t *'
      (aka 'unsigned char *') converts between pointers to integer types with different sign [-Wpointer-sign]
        kop.crk_param[3].crp_p = cle;
                               ^ ~~~
4 warnings and 2 errors generated.
*** Error code 1

Stop.
make[1]: stopped in /usr/src/FreeBSD/tools/tools/crypto
*** Error code 1

Stop.
make: stopped in /usr/src/FreeBSD/tools/tools/crypto
```

I have no idea how to work around this.

Thanks much for your attention. it is VERY MUCH appreciated!

Fabricio.


----------



## SirDice (Mar 29, 2019)

Does /etc/src.conf and/or /etc/make.conf exist? If so, what do they contain?


----------



## FabricioGuzzy (Mar 29, 2019)

SirDice said:


> Does /etc/src.conf and/or /etc/make.conf exist? If so, what do they contain?



No, they don't exist.  
By the way, I am using your instructions from here:  https://forums.freebsd.org/threads/creating-an-iso-image-from-source.49222/  to understand the process and to create an ISO file.

Once again, thanks much!

Fabricio.


----------



## SirDice (Mar 29, 2019)

Which source did you checkout?


----------



## FabricioGuzzy (Mar 29, 2019)

SirDice said:


> Which source did you checkout?



I made a git clone from github :  releng/12.0  to  /usr/src/freebsd


```
git clone -b releng/12.0 https://github.com/freebsd/freebsd.git FreeBSD
```

but let me clarify one thing... the error I mentioned just happens if I go straight to /usr/src/FreeBSD/tools/tools/crypto  and try the "make" command.
That was the way I found to easily reproduce the initial error i mentioned.

Thanks!
Fabricio.


----------



## SirDice (Mar 29, 2019)

FabricioGuzzy said:


> but let me clarify one thing... the error I mentioned just happens if I go straight to /usr/src/FreeBSD/tools/tools/crypto and try the "make" command.


Don't. Follow the proper procedures to build FreeBSD. The source tree is set up to be treated as a whole. There are all sorts of bootstrap and tool-chains that need to be set up. 

What I suggest:

```
rm -rf /usr/src/*   # remove all 
chflags -R noschg /usr/obj/* && rm -rf /usr/obj/*  # remove half-built leftovers

svnlite co https://svn.freebsd.org/base/releng/12.0 /usr/src
# Or
git clone -b releng/12.0 https://github.com/freebsd/freebsd.git /usr/src

cd /usr/src
make buildworld buildkernel
```

See build(7).


----------



## FabricioGuzzy (Mar 29, 2019)

SirDice said:


> Don't. Follow the proper procedures to build FreeBSD. The source tree is set up to be treated as a whole. There are all sorts of bootstrap and tool-chains that need to be set up.
> 
> What I suggest:
> 
> ...



Can I run the following?:

```
make release

make install DESTDIR=/var/freebsd-snapshot
```

after all that to produce my ISO and IMG files?

Thanks Much!!
Fabricio.


----------



## FabricioGuzzy (Mar 29, 2019)

Nevermind..   
All right!  I could successfully create my own ISO and IMG files. 
Just tested/boot/installed it and it worked really fine. (*awesome!*)

Now the hard part - I have created it using classic GENERIC kernel/ original conf files with absolutelly no customizations.

Next step is to add my "customized" kernel options and conf files.
that´s when the problems start...
I will separate the files and post them here prior to re compile it all.

Thanks Very Much for the help! I really appreciate it!

Fabricio.


----------



## SirDice (Apr 1, 2019)

You can add more kernels if you set KERNCONF while building the kernels and the release. First kernel listed is the default, the others are added to the install media. 

For example I use: `make -DNOPORTS -DNODOC -DNOPKGS KERNCONF="GENERIC VBOX" release`
This gives me the GENERIC kernel as default and adds a VBOX kernel to the install media.


----------



## FabricioGuzzy (Apr 1, 2019)

SirDice said:


> You can add more kernels if you set KERNCONF while building the kernels and the release. First kernel listed is the default, the others are added to the install media.
> 
> For example I use: `make -DNOPORTS -DNODOC -DNOPKGS KERNCONF="GENERIC VBOX" release`
> This gives me the GENERIC kernel as default and adds a VBOX kernel to the install media.




Yes, I am using it already.  In fact, I have created a new thread/post with the complete situation  " Full Custom kernel/base/release process"

Thanks a lot!
Fabricio


----------

