Dawid Bautsch Dev Blog

No category

FreeBSD ports mechanism: fast start

dbautsch

Since the beggining of my developer carrer (or at least since couple years) I tried to use many Linux distributions. Like it has been said in an earlier post, I had begun my way with MS-DOS “operating system”, next it was the time for Windows 3.1, 95, 98 and so on. But I’ve always missed something from those operating systems. Maybe they weren’t stable enough or even not “PRO” enough? Don’t know, but four years ago I gave a chance and tried to install & run PC-BSD, a fork of FreeBSD. Without success, but with a faith that it could be someday possible to throw out Windows “through window”. The problem was caused by AMDGPU device driver which isn’t very well implemented (actually ported from Linux).
My next step will be to try a new incarnation of FreeBSD which is GhostBSD (https://www.ghostbsd.org/). I didn’t tried it on my hardware yet, but successfully run it on Virtualbox instance. I had an occasion to work with ports and since there are many myths about BSD’s over internet I decided to write something about the whole mechanism.
The very first thing we need to discuss is the meaning of “ports”. As you probably know, almost entire opensource world is built using GCC and G++. The BSD is built using CLANG. But that’s not the main problem since both of the tools are highly portable. The second problem is an API & ABI compatibility. If you want to use some app on Linux, let’s say “p7zip” it has to be compiled, and there is a very high chance, that it will work on (almost) any other Linux distro (as long as the dependencies are satisfied). But BSD is not the case here. You need to recompile the program and probably modify the source code in order to fit slightly different system API. Here comes “ports” mechanism. It downloads original source code of your app from SVN or GIT repository (and dependencies), then SVN or GIT patches are applied and the program is built. That’s (almost) all. There is also the middle step which is configure, but you don’t need to worry about it since it is a program built on “curses” library and you can easily select the options you want (see screenshot).


Let’s start with the very basic command which is an initialization of ports tree for the first time and extraction:

portsnap fetch
portsnap extract

You will not need to extract the ports in the future, just run fetch and update.

portsnap fetch
portsnap update

The next step is to build the program or library you want to use. If you’re familiar with GNU MAKE you will find yourself very well with ports mechanism.
Let’s say you want to build “coedit” program. In order to do that, you need to type:

cd /usr/ports/editors/coedit
make
make install
make clean

It may take some time, CLANG seems to be a little slower at compiling in comparison with G++.
The clean step is important because you will spare some space on your harddrive. The intermediate build directory will be deleted.
When the process is finished you should be able to see a new entry in your system menu.
And thats all. Happy BSD days!

Short disclaimer: this is an experimental post written in english. I’m not a native speaker and thus it may be harmful to read my words. I will probably switch to en in order to reach higher amount of readers.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top