Fortran and FreeBSD

Maybe it will be more encouraging if I describe the one and only change I had to make (and like I said you do that once, then forget it.) I have a generic Makefile like this:

TEST_STRING = $(shell echo "test")
ifeq ($(TEST_STRING),test)
	TARGET_OS = Unix
	ifeq ($(shell uname), Linux)             # GNU/Linux settings:
		MAKE = make -j
		USR_DIR = /usr
		ifeq ($(shell getconf LONG_BIT), 64)
			SYSTEM_LIB_DIR=$(USR_DIR)/lib64
		else
			SYSTEM_LIB_DIR=$(USR_DIR)/lib
		endif
	else ifeq ($(shell uname), FreeBSD)      # FreeBSD settings:
		MAKE = gmake -j
		USR_DIR = /usr/local
		SYSTEM_LIB_DIR=$(USR_DIR)/lib
	endif
	SYSTEM_INC_DIR = $(USR_DIR)/include
else ifeq ($(TEST_STRING), "test")
	# Stuff for... that other "operating system" goes here, if you need it.
endif

include Makefile.$(TARGET_OS)

This defines the system’s include and lib directories. For GNU/Linux it’s basically the FHS (Filesystem Hierarchy Standard) - except the system’s lib directory may differ in 64-bit. As you can see, settings for FreeBSD are even easier.

This generic Makefile loads Makefile.Unix in the end, which is the normal Makefile you would use on GNU/Linux, except include and lib directories are predefined in the generic Makefile above as $SYSTEM_INC_DIR and $SYSTEM_LIB_DIR, respectively.
The actual Makefile that does the building job is named “Makefile.Unix” because it is exactly the same for GNU/Linux and FreeBSD.

In this example, I use gmake for the actual building in FreeBSD, which is basically GNU Make. The makefiles would be slightly different if you use BSD’s make, but if you switch from one operating to another often (as I do) using gmake is more practical.

And… that’s pretty much it. Everything in your code should be exactly the same. In other words: use a generic makefile like the one above to set directories, and that’s it. The rest is the same for both GNU/Linux and FreeBSD.

I’m sure there are other ways to do the same thing, but the one I tried to describe here just works. Every time. This is why I said with very little effort done once, transition to FreeBSD programming is seamless.

1 Like