This repository provides a CMake-based build, test, install, and package workflow for the upstream f2c Fortran-to-C converter and its libf2c runtime library.
It does not replace or extend the upstream Fortran translator. The project focuses on maintainability, portability, reproducible source acquisition, and downstream CMake integration.
- The
f2ccommand-line converter - The static
libf2cruntime library - The public
f2c.hheader - An installed CMake package with the
f2c::f2cconverter target and thef2c::f2c_runtimelibrary target - Installed
pkg-configmetadata for the staticlibf2cruntime - End-to-end converter/runtime smoke tests
- Linux and macOS CI with GCC, Clang, AppleClang, and sanitizer coverage
- Online source acquisition by default, with an optional offline workflow
Upstream source archives are downloaded from Netlib during configuration unless archives with the expected filenames are available locally.
- CMake 3.20 or later
- A C compiler such as GCC, Clang, or AppleClang
- A build tool such as Ninja or Make
- Network access during the first configuration, unless local archives are provided
Run the following commands from the repository root:
cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build --parallel
ctest --test-dir build --output-on-failureNetwork fetching is enabled by default with NET_FETCH=ON. Downloaded
archives are cached under .cache/downloads/.
Every selected upstream archive is checked against its pinned SHA256 value,
whether it is supplied under archives/, reused from the download cache, or
downloaded during configuration. A mismatch stops configuration by default.
For deliberate local experiments with changed upstream contents, the mismatch can be acknowledged explicitly:
cmake -S . -B build \
-DF2C_ALLOW_UNVERIFIED_ARCHIVES=ONThis option still calculates and reports the expected and actual hashes, but continues after the mismatch. It is unsafe for normal builds, CI, or releases. The setting is stored in the build directory's CMake cache; return to strict verification explicitly when the experiment is complete:
cmake -S . -B build \
-DF2C_ALLOW_UNVERIFIED_ARCHIVES=OFFThe option does not allow missing files or download failures to be ignored.
Install to a user-local prefix:
cmake --install build --prefix "$HOME/.local"This installs the following primary artifacts on conventional Unix systems:
$HOME/.local/bin/f2c
$HOME/.local/include/f2c.h
$HOME/.local/lib/libf2c.a
$HOME/.local/lib/pkgconfig/libf2c.pc
$HOME/.local/lib/cmake/f2c/
$HOME/.local/share/man/man1/f2c.1
If $HOME/.local/bin is not already on PATH:
export PATH="$HOME/.local/bin:$PATH"Confirm that the installed converter is available:
command -v f2cRead the installed command-line reference with:
man f2cIf the manual-page directory under a custom prefix is not already in the system search path, add it for the command invocation:
MANPATH="$HOME/.local/share/man${MANPATH:+:$MANPATH}" man f2cCreate a fixed-form Fortran source file named hello.f:
PROGRAM HELLO
PRINT *, 'HELLO'
ENDTranslate it to C:
f2c hello.fThe command writes hello.c in the current directory. Compile the generated C
source and link it with libf2c and the platform math library:
cc hello.c \
-I"$HOME/.local/include" \
-L"$HOME/.local/lib" \
-lf2c -lm \
-o hello
./helloExpected output:
HELLO
For a browser-accessible copy of the complete command-line reference, see the upstream f2c manual.
The installed libf2c module describes the static runtime library and its
public header. It does not represent the separate f2c converter executable.
When installing under a non-system prefix, make the module visible to
pkg-config or pkgconf:
export PKG_CONFIG_PATH="$HOME/.local/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"Translate the Fortran source with f2c, then compile and statically link the
generated C source using the module's public and private link requirements:
f2c hello.f
cc hello.c $(pkg-config --cflags --static --libs libf2c) -o hello
./helloThe module version is this repository's package version. It is distinct from the date-based upstream translator version reported through the installed CMake package.
Downstream CMake projects can use the installed converter and runtime through their exported targets:
cmake_minimum_required(VERSION 3.20)
project(example LANGUAGES C)
find_package(f2c CONFIG REQUIRED)
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
file(MAKE_DIRECTORY "${generated_dir}")
add_custom_command(
OUTPUT "${generated_dir}/input.c"
COMMAND "${CMAKE_COMMAND}" -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/input.f"
"${generated_dir}/input.f"
COMMAND "${CMAKE_COMMAND}" -E chdir "${generated_dir}"
"$<TARGET_FILE:f2c::f2c>" input.f
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/input.f" f2c::f2c
VERBATIM
)
add_executable(example "${generated_dir}/input.c")
target_link_libraries(example PRIVATE f2c::f2c_runtime)Run f2c in a build-tree working directory so that its generated files do not
modify the source tree. The complete
examples/cmake project demonstrates this
layout with two Fortran sources, isolated generation directories, exact output
verification, and dependency tracking for incremental rebuilds.
The example sources are independent and do not share a COMMON block. A
portable workflow for coordinating COMMON definitions across independently
translated sources is not currently established.
When f2c is installed under a non-system prefix, pass that prefix while configuring the included example:
cmake -S examples/cmake -B build/cmake-example \
-DCMAKE_PREFIX_PATH="$HOME/.local"
cmake --build build/cmake-example --parallel
ctest --test-dir build/cmake-example --output-on-failuref2c::f2c is the supported imported executable target for native-build custom
commands. f2c::f2c_runtime supplies the installed f2c.h include directory,
the static runtime library, and the platform math-library link requirement on
supported Unix systems. Cross-build host-tool handling is not currently
verified, so the example documents a native-build workflow only.
After find_package(f2c CONFIG REQUIRED), the package also defines two version
variables with deliberately different meanings:
F2C_VERSION_STRINGis this repository's package release version and is the version used byfind_packagecompatibility checks.F2C_UPSTREAM_VERSIONis the version reported by the upstreamf2ctranslator included in the verified source archive.
The internal LIBF77 and LIBI77 component dates are not exposed as a unified
libf2c version because upstream does not define one.
Offline building is supported as a secondary workflow. Place these files under
archives/:
archives/src.tgz
archives/libf2c.zip
Then explicitly disable network fetching:
cmake -S . -B build \
-DNET_FETCH=OFF \
-DBUILD_TESTING=ON
cmake --build build --parallel
ctest --test-dir build --output-on-failureThe archives are not stored in this Git repository.
The continuous-integration matrix currently covers:
- Ubuntu 24.04 with GCC
- Ubuntu 24.04 with Clang and AddressSanitizer/UndefinedBehaviorSanitizer
- Ubuntu 22.04 with GCC
- macOS 15 with AppleClang
- macOS 14 with AppleClang
Ninja and Make-style CMake generators are intended to work. CI is the source of truth for the specific operating-system and compiler combinations verified by the project.
- Windows is currently out of scope.
- The installed runtime is currently a static library; a shared library is not provided.
- The primary use case is legacy Fortran 77 input. This project is not a replacement for a modern Fortran compiler and does not add newer Fortran language features to upstream f2c.
- Cross-compilation is not currently verified because the build runs the
generated
arithchkhost tool while creating platform-specific headers.
See CONTRIBUTING.md for the project scope, development workflow, verification expectations, and pull request guidance.
Report suspected security vulnerabilities privately by following SECURITY.md. Do not include vulnerability details in a public Issue.
Repository-maintained files are available under the MIT License. Downloaded upstream f2c and libf2c sources, and artifacts derived from them, remain subject to the upstream notice. The repository MIT License does not relicense those upstream sources or derived artifacts.