Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f2c: new recipe #23417

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
30 changes: 30 additions & 0 deletions recipes/f2c/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Based on https://github.com/valgur/f2c/blob/20240312/makefile.u
cmake_minimum_required(VERSION 3.15)
project(f2c C)

# Configure sysdep.hd. Only sets NO_MKDTEMP and NO_MKSTEMP, if necessary.
if(MSVC)
file(WRITE sysdep.hd "#define NO_MKDTEMP\n#define NO_MKSTEMP\n")
else()
file(WRITE sysdep.hd "")
endif()

# Generate tokdefs.h
# grep -n . <tokens | sed "s/\([^:]*\):\(.*\)/#define \2 \1/" >tokdefs.h
file(STRINGS tokens TOKENS)
set(COUNTER 1)
set(TOKDEFS "")
foreach(TOKEN ${TOKENS})
string(APPEND TOKDEFS "#define ${TOKEN} ${COUNTER}\n")
math(EXPR COUNTER "${COUNTER} + 1")
endforeach()
file(WRITE tokdefs.h ${TOKDEFS})

add_executable(f2c
main.c init.c gram.c lex.c proc.c equiv.c data.c format.c
expr.c exec.c intr.c io.c misc.c error.c mem.c names.c
output.c p1output.c pread.c put.c putpcc.c vax.c formatdata.c
parse_args.c niceprintf.c cds.c sysdep.c version.c
)

install(TARGETS f2c DESTINATION bin)
61 changes: 61 additions & 0 deletions recipes/f2c/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
sources:
"20240312":
f2c:
url:
- "https://github.com/valgur/f2c/releases/download/f2c-20240312/f2c-20240312.tgz"
- "https://netlib.org/f2c/src.tgz"
sha256: "4d33ef7b67dedf5fc077ec45016cba35421eb36432522e8d8c5b9c374a5d6f99"
fc:
url:
- "https://salsa.debian.org/debian/f2c/-/raw/b17b7c087db97f96ef9f603dcea5424093669799/fc"
- "https://github.com/valgur/f2c/releases/download/f2c-20240312/fc"
- "https://www.netlib.org/f2c/fc"
sha256: "f0dced9b581a5808bd2d0d5e4716997043960a56333d5f4c44b201b870aa0ea8"
libf2c:
url:
- "https://github.com/valgur/f2c/releases/download/libf2c-20240130/libf2c-20240130.zip"
- "https://www.netlib.org/f2c/libf2c.zip"
sha256: "cc84253b47b5c036aa1d529332a6c218a39ff71c76974296262b03776f822695"
patches:
"20240312":
# https://salsa.debian.org/debian/f2c/-/tree/b17b7c087db97f96ef9f603dcea5424093669799/debian/patches
- patch_file: "patches/f2c/0002-prototype-rmdir.patch"

Check warning on line 22 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: f2c ^ (line: 23)
base_path: "f2c"
- patch_file: "patches/f2c/0004-fc-script-path-and-tmpfile.patch"

Check warning on line 24 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: f2c ^ (line: 23)
base_path: "f2c"
- patch_file: "patches/f2c/0005-sysdep-tmpfiles.patch"

Check warning on line 26 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: f2c ^ (line: 25)
base_path: "f2c"
- patch_file: "patches/f2c/0008-typos.patch"
base_path: "f2c"

Check warning on line 29 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: f2c ^ (line: 27)
# CCI
- patch_file: "patches/f2c/0009-fc-pass-libf2c-flags.patch"
base_path: "f2c"
patch_type: "conan"
patch_description: "Pass libf2c flags to cc in fc"
- patch_file: "patches/f2c/0010-fc-respect-CC-envvar.patch"
base_path: "f2c"
patch_type: "conan"
patch_description: "Respect CC environment variable"

# https://salsa.debian.org/debian/libf2c2/-/tree/7de354efec5312e15deab83affdaa620ae75849a/debian/patches
- patch_file: "patches/libf2c/0003-C-tweaks.patch"

Check warning on line 41 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in # https://salsa.debian.org/d ... ^ (line: 40)
base_path: "libf2c"
- patch_file: "patches/libf2c/0004-add-clapack-files.patch"

Check warning on line 43 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: libf2c ^ (line: 42)
base_path: "libf2c"
- patch_file: "patches/libf2c/0006-weak-MAIN__.patch"

Check warning on line 45 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: libf2c ^ (line: 44)
base_path: "libf2c"
- patch_file: "patches/libf2c/0007-format-security-sprintf.patch"

Check warning on line 47 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: libf2c ^ (line: 46)
base_path: "libf2c"
- patch_file: "patches/libf2c/0008-XintXX_t.patch"

Check warning on line 49 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: libf2c ^ (line: 48)
base_path: "libf2c"
- patch_file: "patches/libf2c/0009-F77_aloc-type.patch"

Check warning on line 51 in recipes/f2c/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in base_path: libf2c ^ (line: 50)
base_path: "libf2c"
- patch_file: "patches/libf2c/0010-largefile_source-redefinition.patch"
base_path: "libf2c"
- patch_file: "patches/libf2c/0011-cross.patch"
base_path: "libf2c"
# CCI
- patch_file: "patches/libf2c/0012-enable-shared.patch"
base_path: "libf2c"
patch_description: "Enable building of shared library"
patch_type: "conan"
198 changes: 198 additions & 0 deletions recipes/f2c/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMakeToolchain, CMake
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import get, copy, download, export_conandata_patches, apply_conandata_patches, chdir, mkdir, rename, replace_in_file, load, save
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, NMakeToolchain, VCVars, unix_path

required_conan_version = ">=1.54.0"


class F2cConan(ConanFile):
name = "f2c"
description = "Fortran 77 to C/C++ translator"
license = "SMLNJ"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://netlib.org/f2c/"
topics = ("fortran", "translator")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"cxx_support": [True, False],
"fc_wrapper": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"cxx_support": True,
"fc_wrapper": True,
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, os.path.join(self.export_sources_folder, "src", "f2c"))
export_conandata_patches(self)

def layout(self):
basic_layout(self, src_folder="src")

def package_id(self):
del self.info.options.fc_wrapper

def validate(self):
if self.settings.os == "Windows" and self.options.shared:
raise ConanInvalidConfiguration("shared builds are not supported on Windows")

def build_requirements(self):
if self.settings.os != "Linux":
self.tool_requires("gnu-getopt/2.40", visible=True)

@staticmethod
def _chmod_plus_x(name):
if os.name == "posix":
os.chmod(name, os.stat(name).st_mode | 0o111)

def source(self):
mkdir(self, "f2c")
mkdir(self, "libf2c")
with chdir(self, "f2c"):
get(self, **self.conan_data["sources"][self.version]["f2c"], strip_root=True)
download(self, **self.conan_data["sources"][self.version]["fc"], filename="fc")
self._chmod_plus_x("fc")
with chdir(self, "libf2c"):
get(self, **self.conan_data["sources"][self.version]["libf2c"])

def generate(self):
VirtualBuildEnv(self).generate()

# f2c
tc = CMakeToolchain(self)
tc.generate()

# libf2c
if is_msvc(self):
VCVars(self).generate()
tc = NMakeToolchain(self)
tc.generate()
else:
tc = AutotoolsToolchain(self)
defines = list(tc.defines)
if self.settings.os == "Linux":
defines.append("NON_UNIX_STDIO")
elif not is_apple_os(self) and self.settings.os != "Windows":

Check failure on line 98 in recipes/f2c/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Undefined variable 'is_apple_os'
defines.append("USE_STRLEN")
cflags = list(tc.cflags)
if self.options.get_safe("fPIC", True):
cflags.append("-fPIC")
cflags += [f"-D{d}" for d in defines]
tc.make_args += [
f"CFLAGS={' '.join(cflags)}",
f"LDFLAGS={' '.join(tc.ldflags)}"
]
tc.generate()

@property
def _target(self):
if not self.options.shared:
return "static"
if is_apple_os(self):

Check failure on line 114 in recipes/f2c/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Undefined variable 'is_apple_os'
return "shared_dylib"
return "shared_so"

def _build_libf2c(self):
with chdir(self, os.path.join(self.source_folder, "libf2c")):
if self.options.cxx_support:
# Do the 'make hadd' command here, since it is missing in the .vc makefile
# cat f2c.h0 f2ch.add >f2c.h
save(self, "f2c.h", load(self, "f2c.h0") + load(self, "f2ch.add"))
if is_msvc(self):
self.run("nmake /f makefile.vc")
else:
autotools = Autotools(self)
autotools.make(args=["-f", "makefile.u"], target=self._target)

def _build_f2c(self):
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, "f2c"))
cmake.build()

fc = os.path.join(self.source_folder, "f2c", "fc")
if is_msvc(self) or self.settings.compiler == "apple-clang":
# '-u __MAIN' is not understood correctly by automake wrapper and cl
replace_in_file(self, fc, " -u MAIN__", "")
if is_msvc(self):
replace_in_file(self, fc, '.o"', '.obj"')
replace_in_file(self, fc, "`.o", "`.obj")
if self.settings.os not in ["Linux", "FreeBSD"]:
replace_in_file(self, fc, "-lf2c -lm", "-lf2c")

def build(self):
apply_conandata_patches(self)
self._build_libf2c()
self._build_f2c()

def package(self):
copy(self, "Notice", os.path.join(self.source_folder, "f2c"), os.path.join(self.package_folder, "licenses"))

#f2c
cmake = CMake(self)
cmake.install()
copy(self, "fc", os.path.join(self.source_folder, "f2c"), os.path.join(self.package_folder, "bin"))

# libf2c
libf2c_dir = os.path.join(self.source_folder, "libf2c")
if is_msvc(self):
copy(self, "vcf2c.lib", libf2c_dir, os.path.join(self.package_folder, "lib"))
rename(self, os.path.join(self.package_folder, "lib", "vcf2c.lib"),
os.path.join(self.package_folder, "lib", "f2c.lib"))
elif not self.options.shared:
copy(self, "libf2c.a", libf2c_dir, os.path.join(self.package_folder, "lib"))
elif is_apple_os(self):

Check failure on line 166 in recipes/f2c/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Undefined variable 'is_apple_os'
copy(self, "libf2c.dylib", libf2c_dir, os.path.join(self.package_folder, "lib"))
else:
copy(self, "libf2c.so.2.1", libf2c_dir, os.path.join(self.package_folder, "lib"))
self.run("ln -s libf2c.so.2.1 libf2c.so.2", cwd=os.path.join(self.package_folder, "lib"))
self.run("ln -s libf2c.so.2.1 libf2c.so", cwd=os.path.join(self.package_folder, "lib"))
copy(self, "f2c.h", libf2c_dir, os.path.join(self.package_folder, "include"))

def package_info(self):
self.cpp_info.libs = ["f2c"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]

f2c_path = os.path.join(self.package_folder, "bin", "f2c")
self.buildenv_info.define_path("F2C", f2c_path)

fc_path = os.path.join(self.package_folder, "bin", "fc")
if self.options.fc_wrapper:
self.buildenv_info.define_path("FC", fc_path)
self.env_info.FC = fc_path

includedir = unix_path(self, os.path.join(self.package_folder, "include"))
libdir = unix_path(self, os.path.join(self.package_folder, "lib"))
cflags = f"-I{includedir} -L{libdir}"
if is_msvc(self):
cflags += " -DMAIN__=main"
self.buildenv_info.define("CFLAGSF2C", cflags)

# TODO: Legacy, to be removed on Conan 2.0
bin_folder = os.path.join(self.package_folder, "bin")
self.env_info.PATH.append(bin_folder)
self.env_info.F2C = f2c_path
self.env_info.CFLAGSF2C = cflags
21 changes: 21 additions & 0 deletions recipes/f2c/all/patches/f2c/0002-prototype-rmdir.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
From: "Barak A. Pearlmutter" <barak+git@cs.nuim.ie>
Date: Tue, 14 Feb 2012 14:52:48 +0000
Subject: prototype rmdir

---
sysdep.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/sysdep.c b/sysdep.c
index 93a1e5b..a692b4a 100644
--- a/sysdep.c
+++ b/sysdep.c
@@ -22,6 +22,8 @@ use or performance of this software.
****************************************************************/
#include "defs.h"
#include "usignal.h"
+#include <stdlib.h>
+// #include <unistd.h>

char binread[] = "rb", textread[] = "r";
char binwrite[] = "wb", textwrite[] = "w";
78 changes: 78 additions & 0 deletions recipes/f2c/all/patches/f2c/0004-fc-script-path-and-tmpfile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
From: "Barak A. Pearlmutter" <barak+git@cs.nuim.ie>
Date: Wed, 18 Jul 2012 11:14:01 +0200
Subject: fc script path and tmpfile

---
fc | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/fc b/fc
index 1f71e59..46d13c7 100644
--- a/fc
+++ b/fc
@@ -11,7 +11,7 @@
# may be useful as way to pass system-specific stuff to the C compiler.
# The script below simply appends to the initial CFLAGS value.

-PATH=/usr/local/bin:/bin:/usr/bin
+

# f77-style shell script to compile and load fortran, C, and assembly codes

@@ -80,12 +80,18 @@ PATH=/usr/local/bin:/bin:/usr/bin

# -U def passed to C compiler (for .c files)
# or to cpp (for .F files) to remove def
-
# -v show current f2c version
# --version same as -v

-s=/tmp/stderr_$$
-t=/tmp/f77_$$.o
+if command -v tempfile >/dev/null; then
+ s=`tempfile --prefix=stderr` || { echo "$0: Cannot create temporary file" ; exit 1; }
+ t=`tempfile --suffix=.o --prefix=f77` || { echo "$0: Cannot create temporary file" ; exit 1; }
+else
+ s=/tmp/stderr_$$
+ t=/tmp/f77_$$.o
+fi
+trap "rm -f $s $t; exit \$rc" 0
+
### On some systems (e.g., IRIX), -common prevents complaints
### about multiple definitions of COMMON blocks.
#CC=${CC_f2c:-'cc -common'}
@@ -94,7 +100,7 @@ EFL=${EFL:-efl}
EFLFLAGS=${EFLFLAGS:-'system=portable deltastno=10'}
RATFOR=${RATFOR:-ratfor}
RFLAGS=${RFLAGS:-'-6&'}
-F2C=${F2C:-/usr/local/bin/f2c}
+F2C=${F2C:-/usr/bin/f2c}
show_fc_help=0
case $1 in
--help) show_fc_help=1;;
@@ -116,14 +122,11 @@ case $show_fc_help in
F2CFLAGS=${F2CFLAGS:='-ARw8 -Nn802 -Nq300 -Nx400'}
CPP=${CPP:-/lib/cpp}
rc=0
-trap "rm -f $s $t; exit \$rc" 0
OUTF=a.out
OUTO=
cOPT=1
set -- `getopt acCD:gI:L:m:N:O:U:o:r:sSt:uw6 "$@"`
case $? in 0);; *) rc=$?; exit;; esac
-CPPFLAGS=${CPPFLAGS:-'-I/usr/local/include'}
-CFLAGSF2C=${CFLAGSF2C:-'-I/usr/local/include'}
OFILES=
trapuv=
strip=
@@ -358,8 +361,8 @@ done

case $cOPT in 2)
# case $trapuv in 1) OFILES="$OFILES -lfpe";; esac
-# $CC -Wl,-dont_warn_unused -o $OUTF -u MAIN__ -L/usr/local/lib $OFILES $LIBS
- $CC -o $OUTF -u MAIN__ -L/usr/local/lib $OFILES $LIBS
+# $CC -Wl,-dont_warn_unused -o $OUTF -u MAIN__ $OFILES $LIBS
+ $CC -o $OUTF -u MAIN__ $OFILES $LIBS
case $strip in 1) strip $OUTF;; esac
;; esac
rc=$?
Loading
Loading