Skip to content

7. Other build systems ​

Not every user of quad will have FoBiS. Two exports give them a build without it.

fpm ​

The Fortran Package Manager reads an fpm.toml. fobis fpm export writes one from the fobos and the sources (--print shows it without writing):

console
$ fobis fpm export --mode release --print
name = "quad"
version = "0.1.0"
author = "Ada Fortran"

[library]
source-dir = "src"

[build]
auto-executables = false
auto-tests = false
auto-examples = false

[dependencies]
penf = { git = "https://github.com/szaghi/PENF", tag = "v2.0.1" }

[[executable]]
name = "integrate"
source-dir = "src"
main = "integrate.F90"

[[executable]]
name = "integrate_mpi"
source-dir = "src"
main = "integrate_mpi.F90"

[[executable]]
name = "sweep"
source-dir = "src"
main = "sweep.F90"
note: fobos modes, templates, flags and rules are not exported: fpm uses its own profiles (debug, release)
note: the library directory src also holds 3 program(s) (e.g. src/integrate.F90): fpm compiles every file of source-dir into the library; keep programs out of it

The notes say what does not translate: fpm has its own profiles instead of modes, and it compiles every file of the library directory into the library, programs included. fobis fpm import goes the other way, from an fpm.toml to a fobos.

A GNU Makefile ​

--makefile FILE writes a Makefile for the mode instead of building:

console
$ fobis build --mode release --makefile Makefile --quiet && sed -n "1,30p" Makefile

#!/usr/bin/make

#main building variables
DSRC    = src .fobis_deps/penf
DOBJ    = build/release/obj/
DMOD    = build/release/mod/
DEXE    = build/release/
LIBS    =
FC      = gfortran
OPTSC   = -O3 -funroll-loops -c -J build/release/mod
OPTSL   =  -J build/release/mod
VPATH   = $(DSRC) $(DOBJ) $(DMOD)
MKDIRS  = $(DOBJ) $(DMOD) $(DEXE)
LCEXES  = $(shell echo $(EXES) | tr '[:upper:]' '[:lower:]')
EXESPO  = $(addsuffix .o,$(LCEXES))
EXESOBJ = $(addprefix $(DOBJ),$(EXESPO))

#auxiliary variables
COTEXT  = "Compiling $(<F)"
LITEXT  = "Assembling $@"

#building rules
$(DEXE)integrate: $(MKDIRS) $(DOBJ)integrate.o
	@rm -f $(filter-out $(DOBJ)integrate.o,$(EXESOBJ))
	@echo $(LITEXT)
	@$(FC) $(OPTSL) $(DOBJ)*.o $(LIBS) -o $@
EXES := $(EXES) integrate

#compiling rules
$(DOBJ)repro_b_read.o: .fobis_deps/penf/scripts/lfortran-bugs/repro_B_read.f90

The Makefile holds a compile rule for every source the mode scans (the fetched PENF checkout included); its default goal is the mode's target, and make compiles only what that needs:

console
$ rm -rf build/release && make && ./build/release/integrate | tail -n 1
Compiling quad_rules.F90
Compiling integrands.F90
Compiling penf_global_parameters_variables.F90
Compiling penf_b_size.F90
Compiling penf_stringify.F90
Compiling penf_allocatable_memory.F90
Compiling penf.F90
Compiling integrate.F90
Assembling build/release/integrate
Simpson, 64 intervals: 2.0000000645300013

The exports are snapshots: generate them again when the fobos changes, for instance with a rule.

fobis build -m Makefile exports a GNU Makefile that make builds

Recorded on a small demo project, not quad.

What you learned

fobis fpm export (and import), fobis build --makefile. Reference: fpm, Makefile export.

This is the end of the second track. The third leaves quad for a while: a family of projects that depend on each other, managed together.