# Fortran and FreeBSD

**URL:** <https://fortran-lang.discourse.group/t/fortran-and-freebsd/6445>\
**Category:** Uncategorized\
**Created:** [September 2, 2023, 7:15pm UTC](https://fortran-lang.discourse.group/t/fortran-and-freebsd/6445 "2023-09-02T19:15:49Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [September 3, 2023, 9:16pm UTC](https://fortran-lang.discourse.group/t/fortran-and-freebsd/6445/18 "2023-09-03T21:16:21Z")

</div>

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:

```auto
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](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard) (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.

---

_[View the full topic](https://fortran-lang.discourse.group/t/fortran-and-freebsd/6445)._
