# Porting (creating, maintaining, etc)



## PacketMan (Dec 7, 2016)

While my knowledge of the inner workings of FreeBSD is still fragmented, and I have some skills I need to work on, I am interested in learning more about porting; meaning how to create and maintain ports.

Obviously my first starting point is the Porter's Handbook.
https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/

And there is a little tidbit at:
https://forums.freebsd.org/threads/36243/

But what else would be good sources for me to read? Sources that detail the internal workings of FreeBSD, coding, etc.  I'm guessing learning C, C++, Phython, and a few other programing languages will be mandatory.  Can someone suggest some threads in this forum, some books, and maybe some other www url's?

I did some searching on Porting in the forum but of course came up with way too many hits.

Thanks.


----------



## kpa (Dec 7, 2016)

In my opinion the best way to learn is to take some medium sized non-trivial port and take it apart to see how the different parts of the build process work and relate to each other. As a starter I recommend that you nail down the sequence described in the "How Things Work" section in the Porter's Handbook:

https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/slow-porting.html#slow-work

For example you could take the mail/mutt port and run only the patch target:

`# make patch`

The output would be something like:


```
===>  License GPLv2+ accepted by the user
===>   mutt-1.7.1_2 depends on file: /usr/local/sbin/pkg - found
===> Fetching all distfiles required by mutt-1.7.1_2 for building
===>  Extracting for mutt-1.7.1_2
=> SHA256 Checksum OK for mutt/mutt-1.7.1.tar.gz.
=> SHA256 Checksum OK for mutt/patch-1.7.1.rr.compressed.gz.
=> SHA256 Checksum OK for mutt/patch-1.5.1.dgc.deepif.1.
=> SHA256 Checksum OK for mutt/patch-1.7.0.ats.date_conditional.1.
=> SHA256 Checksum OK for mutt/patch-1.7.1.vvv.initials.gz.
=> SHA256 Checksum OK for mutt/patch-1.7.1.vvv.quote.gz.
===>  Patching for mutt-1.7.1_2
===>  Applying distribution patches for mutt-1.7.1_2
===>  Applying extra patch /usr/ports/mail/mutt/files/extra-patch-reverse_reply
===>  Applying extra patch /usr/ports/mail/mutt/files/extra-patch-smartdate
===>  Applying extra patch /usr/ports/mail/mutt/files/extra-patch-smime-outlook
===>  Applying FreeBSD patches for mutt-1.7.1_2
```

You'll immediately notice that the patch target also implies the previous targets in the sequence, the fetch (already done in my case) and extract targets. This would give you the patched source at the ${WRKDIR} (defaults to the work subdirectory of the port directory) directory ready to be used in the next configure and build targets.

You can keep experimenting like this and try different targets, run them and see what the results are and go back to the starting point by just running `# make clean`.

Your next step in learning would be then to nail down how make(1) works because that's imo the biggest hurdle in understanding the build process, without understanding make(1) and its idiosyncracies nothing will make sense. This is from the FreeBSD Developer's Handbook but there are probably better tutorial for make, unfortunately most of them are for GNU make that uses different syntax for just about everything else but the most basic target definitions:

https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/tools-make.html


----------

