CERNLIB

From MukeWiki
CERNLIB Fedora copr package repository for Fedora and CentOS
CERNLIB GitHub source repository (file cernlib.spec and examples)

CERNLIB in Fedora

CERNLIB v Fedora Package Sources je oznaceny ako dead package, posledny udrziavany balik CERNLIB bol v Fedore 14 cernlib-2006-35.fc14.src.rpm (archive). Tento CERNLIB balik je stale pritomny v Koji Fedora building and tracking system, resp. jeho posledny release 35 cernlib-2006-35.fc14.src.rpm (koji). Source rpm baliky (archive a koji) su absolutne identicke, minimalny rozdiel vo velkosti suboru je sposobeny inymi casmi build-ovania (a teda ina Signature vnutri balika). Fungujem dalej s Koji source rpm balikom.

$ wget https://kojipkgs.fedoraproject.org/packages/cernlib/2006/35.fc14/src/cernlib-2006-35.fc14.src.rpm

  28974483 2010-05-05 20:29:33 cernlib-2006-35.fc14.src.rpm

Original cernlib.spec (release 35) subor a jeho posledny %changelog

     59057 2010-05-05 18:46:36 cernlib.spec

%changelog
* Wed May 05 2010 Jon Ciesla <limb@jcomserv.net> 2006-35
- Apply debian cernlib 2006.dfsg.2-14 patchset.

Fedora balik pouziva pre-patch-ovanu verziu CERNLIB 2006 z Debian distribucie (aka new Debian's cernlib) s poslednym patchset-om 2006.dfsg.2-14. Balik sa build-uje len s gfortran-om (a nie g77).

Build CERNLIB in Fedora

Instalacia zavislosti (ako root)

$ dnf builddep cernlib-2006-35.fc14.src.rpm

Zaciname s build-ovanim cernlib (dalej vsetko ako user)

$ # rpmbuild --rebuild cernlib-2006-35.fc14.src.rpm   # for RPM version < 4.12 (< Fedora 21)
$ # rpmbuild --define "_topdir /tmp/musinsky/rpmbuild" --rebuild cernlib-2006-35.fc14.src.rpm

$ rpmbuild -ra cernlib-2006-35.fc14.src.rpm
# many, many errors
$ cp -p $HOME/rpmbuild/SPECS/cernlib.spec $HOME/rpmbuild/SPECS/cernlib.spec.orig

Vsetky subory su teraz v $HOME/rpmbuild/ vratane $HOME/rpmbuild/SPECS/cernlib.spec (definovane pomocou rpm makier rpm --eval %{_topdir}, resp. $(rpm --eval %{_specdir})/cernlib.spec). Dalej postupne patch-ujeme cernlib.spec file a znova build-ujeme packages.

2019-04 release-40

Fedora 29 (x86_64), gcc and GNU Fortran (GCC) 8.3.1 20190223. Vsetky nizsie uvedene chyby opravene v ramci release 40, s ktorym boli vytvorene baliky nie len pre Fedora 29, ale aj pre Fedora 28, 30, 31 a pre CentOS 6 a 7.

$ rm -rf $HOME/rpmbuild/BUILD/; rpmbuild -ba $HOME/rpmbuild/SPECS/cernlib.spec

error01

+ sed -i.optflags -e 's/FOPT \+=.*/FOPT = "-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection"/' -e 's/COPT  \+=.*/COPT = "-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE"/' p4boot.sh
sed: -e expression #1, char 183: unknown option to `s'

Nekorektna zamena FOPT a COPT parametrov v subore $HOME/rpmbuild/BUILD/cernlib-2006/patchy/p4boot.sh. sed vo vyraze pouziva premenu, ktora obsahuje slashes (char / ). Riesenie je pouzit alternativny regex delimiter, t.j. namiesto sed "s/$var/replace/g" file_name pouzit napr. sed "s~$var~replace~g" file_name. V principe prikaz sed umoznuje pouzit lubovolny char ako delimeter, separator (pozor, aby sa ten "novy" seprator char nevyskytoval vo vyraze, ktory pouziva premennu, co je prave tento problem).

Replace in cernlib.spec lines 918 - 919

   sed -i.optflags -e 's/FOPT \+=.*/FOPT = "'"$FC_OPTFLAGS"'"/' \
            -e 's/COPT  \+=.*/COPT = "%{optflags} -D_GNU_SOURCE"/' p4boot.sh
   sed -i.optflags -e 's~FOPT \+=.*~FOPT = "'"$FC_OPTFLAGS"'"~' \
            -e 's~COPT  \+=.*~COPT = "%{optflags} -D_GNU_SOURCE"~' p4boot.sh

error02

gfortran -c -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -m-cypatch.f
gfortran: fatal error: no input files

Chybne generovanie Fortran a CC options programom $HOME/rpmbuild/BUILD/cernlib-2006/patchy/fcasplit. Su to presne tie options, ktore boli zamenene (uz korektne) pri rieseni predchadzajuceho (error01) problemu.

        Fortran    name : gfortran
        Fortran options : -c -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -m-c
             CC    name : cc
             CC options : -c -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -m

Tieto options su zjavne "umelo useknute", co je sposobene malou hodnotou velkosti parametra pola PARAMETER (MXLENG=256, MXMKLN=128) v subore $HOME/rpmbuild/BUILD/cernlib-2006/patchy/fcasplit.f (dlzka options string je cca 350 znakov).

Add in cernlib.spec line 920

        sed -i.mxleng -e 's/MXLENG=256/MXLENG=1024/' fcasplit.f

POZOR teoreticky mozno obidva riadky 918 a 919 s prikazom sed -i.optflags (error01) zakomentovat. "Vyriesi sa" naraz error01 aj error02. Kompilacia prejde, ale bude s inymi options ako kompilacia ostatneho kodu, co moze neskor priviest k roznym a necakanym chybam, problemom. Options su ulozene v subore $HOME/rpmbuild/BUILD/cernlib-2006/patchy/p4boot.sh.

default hodoty

set  FOPT  = "-O2"                # Fortran compiler options
set  FOPTC = "-c $FOPT -posix"
set  COPT  = "-O2"                # C compiler options
set  COPTC =  "-c $COPT -posix"

cernlib.spec zamiena (niekolkonasobne patch-ovanie) options pre kompilaciu definovane pomocou rpm makra rpm --eval %{optflags}

set  FOPT = "-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection"
set  FOPTC = "-c $FOPT -posix"
set  COPT = "-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE"
set  COPTC =  "-c $COPT -posix"

error03

GFORTRAN   -c -o kuipcc.o /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/programs/kuipc/kuipcc.c
In file included from /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/kuip/kuip.h:10,
                 from /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/programs/kuipc/kuipcc.c:46:
/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/kuip/kstring.h:77:14: error: conflicting types for 'strfromd'
 extern char* strfromd( double d, size_t prec );
              ^~~~~~~~
In file included from /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/kuip/ksys.h:419,
                 from /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/kuip/kuip.h:9,
                 from /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/programs/kuipc/kuipcc.c:46:
/usr/include/stdlib.h:212:12: note: previous declaration of 'strfromd' was here
 extern int strfromd (char *__dest, size_t __size, const char *__format,
            ^~~~~~~~

Funkcia extern char* strfromd( double d, size_t prec ) zo suboru $HOME/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/code_kuip/kkern.c je v konflikte so standardnou glibc funkciou extern int strfromd (char *__dest, size_t __size, const char *__format, double __f), tato funkcia sa celkovo vyskytuje v 12 suboroch. The GNU C Library version 2.25 (glibc-2.25, 2017-02) added, among other things, function strfromd.

Add in cernlib.spec lines 945 - 958

# dirty fix strfromd
cd $CERN_ROOT/src
sed -i 's/strfromd/strfromd9/g' graflib/higz/kuip/kstring.h
sed -i 's/strfromd/strfromd9/g' code_motif/mkdcmp.c
sed -i 's/strfromd/strfromd9/g' code_motif/kuip/kstring.h
sed -i 's/strfromd/strfromd9/g' packlib/kuip/kuip/kstring.h
sed -i 's/strfromd/strfromd9/g' packlib/kuip/ykuip/kmath.y
sed -i 's/strfromd/strfromd9/g' packlib/kuip/code_kuip/kmath.c
sed -i 's/strfromd/strfromd9/g' packlib/kuip/code_kuip/kuwhat.c
sed -i 's/strfromd/strfromd9/g' packlib/kuip/code_kuip/kexec.c
sed -i 's/strfromd/strfromd9/g' packlib/kuip/code_kuip/kkern.c
sed -i 's/strfromd/strfromd9/g' packlib/kuip/code_kuip/kmacro.c
sed -i 's/strfromd/strfromd9/g' packlib/kuip/code_kuip/kmenu.c
sed -i 's/strfromd/strfromd9/g' packlib/kuip/code_kuip/kvect.c

error04

GFORTRAN /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/code_kuip/kmenu.c -o archive/kmenu.o
/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/code_kuip/kmenu.c: In function 'interactive_find':
/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/code_kuip/kmenu.c:1070:20: warning: variable 'cmd0' set but not used [-Wunused-but-set-variable]
         KmCommand *cmd0, *cmd;
                    ^~~~
/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/code_kuip/kmenu.c:1407:14: error: format not a string literal and no format arguments [-Werror=format-security]
              printf (flis_name[i]);
              ^~~~~~

Chybne formatovanie prikazom printf v subore $HOME/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/code_kuip/kmenu.c (forum). Fedora pouziva pri build-ovani -Werror=format-security option (from %{optflags}).

Add in cernlib.spec lines 960 - 961

# fix printf (flis_name[i])
sed -i 's/printf (flis_name/printf ("\%s", flis_name/' packlib/kuip/code_kuip/kmenu.c

error05

gmake[2]: Leaving directory '/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/build/kernlib/umon'
rebuild shared library libkernlib.so.1_gfortran.2006 in /kernlib
Mon 29 Apr 21:05:27 MSK 2019
/usr/bin/ld: cannot find -lnsl
collect2: error: ld returned 1 exit status

Nenainstalovana potrebna kniznica, hladam pomocou dnf provides \*libnsl.so.

$ dnf list libnsl\*64
Installed Packages
libnsl2.x86_64
Available Packages
libnsl.x86_64          # legacy (not needed)
libnsl2-devel.x86_64   # required this package

Kniznica libnsl2-devel potrebna (aj pre build proces) pre Fedora 28 a vyssie.

Add in cernlib.spec lines 94 - 96

%if 0%{?fedora} >= 28
BuildRequires: libnsl2-devel
%endif

Add in cernlib.spec lines 365 - 367

%if 0%{?fedora} >= 28
Requires: libnsl2-devel
%endif

older Fedora

Fedora 26 (strela205, 2019-04) gcc 7.3.1, resp. Fedora 27 (strela07, 2019-04) gcc 7.3.1 alebo testovane uz skor na Fedora 25 (my PC, 2017-03) gcc 6.4.1.

Testing geant321
  ... using exam1

# exam1 doesn't terminate

Problem s $HOME/rpmbuild/BUILD/cernlib-2006/2006/build/geant321/examples/gexam1/exam1, ktory je sucastou testing geant321. Program exam1 sa nezakoncuje. Tento problem je aj s dalsimi programami exam* (from testing geant321). Vo Fedore 29 (gcc 8.3.1) tento problem uz nie je (Fedoru 28 nemam kde testovat). S najvacsou pravdepodobnostou je to ten isty problem ako Feb 03, 2019: CERNLIB 2006 on newer Linux systems. Until a proper fix is found, one needs to make sure that all FORTRAN code is compiled with "-O" (i.e. "-O1") and not with the default "-O3" (even "-O2" results in misbehavior). Patch pre Debian cernlib-20061220+dfsg3.patches.2019.02.03.txt. Fedora pre kompilaciu pouziva default options definovane pomocou rpm makra %{optflags} (Fedora pouziva -O2 na rozdiel od Debian -O3).

# Fedora 26 (gcc 7.3.1)
$ rpm --eval %{optflags}
-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic

Zamena default -O2 na -O tento problem riesi a vsetky exam* programy (from testing geant321) v Fedora 26 uspesne zbehnu

$ rm -rf $HOME/rpmbuild/BUILD/; rpmbuild -ba --define "optflags -O -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic" $HOME/rpmbuild/SPECS/cernlib.spec

Problem bol medzitym v gcc vyrieseny a preto sa uz v novsich verziach neobjavuje. Teoreticky mozno vykomentovat gexam* v subore $HOME/rpmbuild/BUILD/cernlib-2006/2006/src/geant321/examples/Imakefile a teda testing programs exam* sa ani nebudu spustat. Samotna kompilacia CERNLIB prejde uspesne a baliky sa z-build-uju. V kazdom pripade to nie je riesenie, kedze zostava moznost, ze potom ani vlastne programy (kompilovane s CERNLIB) nebudu fungovat korektne.

Add in cernlib.spec lines 895 - 905

# replace gcc optimization flags
# for gcc < 8 must be -O (no -O2 or -O3)
#
# gcc -dumpversion => older 4.8.5 => newer 8
%define gcc_dump_ver %(gcc -dumpversion | sed 's/[.].*$//')

%if 0%{?gcc_dump_ver} >= 8
echo default optflags
%else
%global optflags %(echo %{optflags} | sed 's/-O[0-3]/-O/')
%endif

2020-05 release-41

Fedora 32 (x86_64), gcc and GNU Fortran (GCC) 10.1.1 20200507. Nizsie uvedene chyby opravene v ramci release 41, s ktorym boli vytvorene baliky pre Fedora 32.

$ rm -rf $HOME/rpmbuild/BUILD/; rpmbuild -ba $HOME/rpmbuild/SPECS/cernlib.spec

error01

Full error output CERNLIB gcc 10

gfortran -g -c -O2 #many more options# /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/kernlib/kerngen/tcgen/sortzv.F

/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/kernlib/kerngen/tcgen/sortzv.F:26:72:

   26 |    10 CALL SORTTI (A,INDEX,N)
      |                                                                        1
Error: Type mismatch in argument 'a' at (1); passed REAL(4) to INTEGER(4)

GCC od verzie 10 mismatch in argument vracia ako chybu. Pridat novu option -fallow-argument-mismatch pre gfortran (vid nizsie), ktora znizi error na warning.

error02

Full error output CERNLIB gcc 10

gfortran -g -c -O2 #many more options# /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/kernlib/kerngen/tcgens/ublow.F

/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/kernlib/kerngen/tcgens/lnxgs/ublow.F:19:20:

   19 |       data iblan1/x'20202000'/
      |                    1
Error: Hexadecimal constant at (1) uses nonstandard X instead of Z [see '-fno-allow-invalid-boz']

Analogicky problem ako error01 pre GCC od verzie 10. Pridat option -fallow-invalid-boz pre gfortran.

Replace in cernlib.spec line 918

# 2020-05-23
FC_OPTFLAGS="%{optflags} -fallow-argument-mismatch -fallow-invalid-boz"

error03

Full error output CERNLIB gcc 10

rebuild shared library libpacklib.so.1_gfortran.2006 in /packlib
/usr/bin/ld: kuip/code_kuip/shared/kbrow.o:/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/kuip/klink1.h:11: multiple definition of `klnkaddr'; kuip/code_kuip/shared/kalias.o:/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/kuip/kuip/klink1.h:11: first defined here

/usr/bin/ld: cspack/sysreq/shared/serror.o: in function `sstrerror':
/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/cspack/sysreq/serror.c:180: warning: `sys_errlist' is deprecated; use `strerror' or `strerror_r' instead
/usr/bin/ld: /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/cspack/sysreq/serror.c:179: warning: `sys_nerr' is deprecated; use `strerror' or `strerror_r' instead
collect2: error: ld returned 1 exit status

GCC od verzie 10 zacal pouzivat -fno-common by default. Viac info napr. aj tu. Pridat option -fcommon pre gcc (t.j. nie len pre gfortran). Je to aj oficialne odporucanie ako portovat na GCC 10. Pravdepodobne bude s tymto viacero problemov, preto aj do redhat-rpm-config balika bola commit-nuta moznost pridania noveho flag-u %define _legacy_common_support 1.

Add in cernlib.spec lines 911 - 914

# 2020-05-23
%if 0%{?gcc_dump_ver} >= 10
%global optflags %{optflags} -fcommon
%endif

Podmienka gcc >= 10 asi zbytocna, resp. taktiez by mala byt analogicky podmienka aj pre error01 a error02. Mozne vyuzitie do buducna pre pripad build-ovania sucasne s CentOS 8 so starsimi gcc kompilatormi ?! S pridanim noveho flag-u %define _legacy_common_support 1 sa tento problem riesi automaticky a korektne.

2020-10 release-42

Fedora 33 (x86_64), gcc and GNU Fortran (GCC) 10.2.1 20201005. Nizsie uvedene chyby opravene v ramci release 42, s ktorym boli vytvorene baliky pre Fedora 33.

$ rm -rf $HOME/rpmbuild/BUILD/; rpmbuild -ba $HOME/rpmbuild/SPECS/cernlib.spec

error01

Full error output [cernlib] 2020-10 release-42

lto-wrapper: fatal error: execvp: No such file or directory
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
chmod a+x fcasplit
chmod: cannot access 'fcasplit': No such file or directory

Potrebne doinstalovat program make. Pravdepodobne sa pomenili zavislosti medzi balikmi, doteraz sa balik make instaloval implicitne.

Edit in cernlib.spec lines 94 - 96

%if 0%{?fedora} >= 28
BuildRequires: libnsl2-devel make
%endif

error02

Full error output [cernlib] 2020-10 release-42

gcc -g -c -O2 #many more options# /root/rpmbuild/BUILD/cernlib-2006/2006/src/kernlib/kernbit/z268/systems.c -o archive/systems.o

/root/rpmbuild/BUILD/cernlib-2006/2006/src/kernlib/kernbit/z268/systems.c: In function 'shift_systems':
/root/rpmbuild/BUILD/cernlib-2006/2006/src/kernlib/kernbit/z268/systems.c:137:45: error: 'sys_errlist' undeclared (first use in this function)
  137 |   fprintf(stderr,"systems(): popen(): %s\n",sys_errlist[errno] );
      |                                             ^~~~~~~~~~~
/root/rpmbuild/BUILD/cernlib-2006/2006/src/kernlib/kernbit/z268/systems.c:137:45: note: each undeclared identifier is reported only once for each function it appears in

The GNU C Library version 2.32 (glibc-2.32, 2020-08) sys_errlist and sys_nerr, among other things, are no longer available (deprecated) and should use strerror instead. Zamena je potrebna v 3 suboroch.

Add in cernlib.spec lines 988 - 994

# replace deprecated sys_errlist and sys_nerr by strerror
cd $CERN_ROOT/src
sed -i 's/sys_errlist\[errno\]/strerror\(errno\)/g' kernlib/kernbit/z268/systems.c # 2x
sed -i 's/n<sys_nerr/n<strerror\(\)/g'              packlib/cspack/sysreq/serror.c
sed -i 's/sys_errlist\[n\]/strerror\(n\)/g'         packlib/cspack/sysreq/serror.c
sed -i 's/sys_errlist\[errno\]/strerror\(errno\)/g' packlib/cspack/sysreq/socket.c

2021-04 release-43

Fedora 34 (x86_64), gcc and GNU Fortran (GCC) 11.0.1 20210405 (Red Hat 11.0.1-0). Kompilacia presla bez chyby ?! Ziadne zmeny (oproti 42) v ramci release 43, s ktorym boli vytvorene baliky pre Fedora 34.

2021-11 release-44

Fedora 35 (x86_64), gcc and GNU Fortran (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1). Nizsie uvedene chyby opravene v ramci release 44, s ktorym boli vytvorene baliky pre Fedora 35. Full error output [cernlib] 2021-11 release-44.

error 01

rebuild archive library libkernlib.a in /kernlib
Tue Nov  9 02:40:17 PM CET 2021
ar: libdeps specified more than once
gmake[1]: *** [Makefile:445: libkernlib.a] Error 123
gmake[1]: Leaving directory '/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/build/kernlib'
make: *** [Makefile:340: install.lib] Error 2

Program ar (archives) je sucastou rpm balika binutils. Binutils od verzie 2.36: The ar tool's previously unused l modifier is now used for specifying dependencies of a static library. V subore config/Imake.tmpl vynechat pouzivanie modifikatora l [1], [2], t.j. pouzivat ar cq namiesto ar clq (rul a xl modifikatory nie su podstatne).

Add in cernlib.spec lines 999 - 1002

# binutils >= 2.36 (2021-11) replace "ar clq" by "ar cq"
sed -i 's/ArCmd ArCmdBase clq/ArCmd ArCmdBase cq/g'       config/Imake.tmpl
sed -i 's/ArAddCmd ArCmdBase rul/ArAddCmd ArCmdBase ru/g' config/Imake.tmpl
sed -i 's/ArExtCmd ArCmdBase xl/ArExtCmd ArCmdBase x/g'   config/Imake.tmpl

error 02

/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/cspack/tcpaw/tcpaw.c: In function 'getpass':
/home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/cspack/tcpaw/tcpaw.c:2617:10: error: argument 'prompt' doesn't match prototype
 2617 | char    *prompt;
      |          ^~~~~~
In file included from /usr/include/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /home/musinsky/rpmbuild/BUILD/cernlib-2006/2006/src/packlib/cspack/tcpaw/tcpaw.c:226:
/usr/include/unistd.h:977:14: error: prototype declaration
  977 | extern char *getpass (const char *__prompt) __nonnull ((1));
      |              ^~~~~~~

Funkcia extern char *getpass (const char *__prompt) __nonnull ((1));, ktora je deklarovana v subore /usr/include/unistd.h je uz niekolko rokov bez zmeny, preco teraz vznikol problem sa nepodarilo vypatrat ?! Existuju asi dve riesenia, funkciu premenovat na getpass9(prompt) alebo pouzit const char *prompt; ako v prototype funkcii.

Add in cernlib.spec lines 1004 - 1007

# 2021-11 replace "char *prompt" by "const char *prompt"
# be careful with sed (4 spaces and *)
#sed -i "s/char\s\{4,\}\*prompt/const char    *prompt/g" packlib/cspack/tcpaw/tcpaw.c
sed -i "s/char    \*prompt/const char    *prompt/g" packlib/cspack/tcpaw/tcpaw.c

2023-04 release-45

Fedora 38 (x86_64), gcc (GCC) 13.1.1 20230426 (Red Hat 13.1.1-1). Nizsie uvedene chyby opravene v ramci release 45, s ktorym boli vytvorene baliky pre Fedora 38. Full error output [cernlib] 2023-04 release-45.

error 01

gfortran -c -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fcommon -fallow-argument-mismatch -fallow-invalid-boz -posi\360\276^A^E
gfortran: error: unrecognized command-line option '-posi�'

Analogicka chyba ako 2019-04 release-40 error02, Fortran options (FOPT a FOPTC) su "umelo useknute", co je sposobene, teraz pre zmenu, malou hodnotou velkosti parametra CHARACTER CHLINE*80, CHNAME*80, CHTEXT*511 v subore $HOME/rpmbuild/BUILD/cernlib-2006/patchy/fcasplit.f.

Add in cernlib.spec

        sed -i.chtext -e 's/CHTEXT\*511/CHTEXT\*1022/' fcasplit.f

2023-10 release-46

Fedora 39 (x86_64), gcc and GNU Fortran (GCC) 13.2.1 20231011. Kompilacia presla bez chyby. Ziadne zmeny (oproti 45) v ramci release 46, s ktorym boli vytvorene baliky pre Fedora 38.

2024-03 release-47

Fedora 40 (x86_64), gcc and GNU Fortran (GCC) 14.0.1 20240316. Vsetky chyby opravene v ramci release 47, s ktorym boli vytvorene baliky pre Fedora 40. Oficialne odporucania ako porting to GCC 14.

# 2024-03-27 gcc14
%if 0%{?gcc_dump_ver} >= 14
%global optflags %{optflags} -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=return-mismatch
%endif

2024-10 release-48

Fedora 41 (x86_64), gcc and GNU Fortran (GCC) 14.2.1 20240912. Kompilacia "takmer" presla bez chyby. Bolo potrebne upravit komentare #%wrong na korektne #%%OK v cernlib.spec subore. Inak ziadne zmeny (oproti 47) v ramci release 48, s ktorym boli vytvorene baliky pre Fedora 40.

CERNLIB notes

CERNLIB Fedora copr download results directory and automatically created git repository (each release has a git branch, master is empty).

Recreate SRPM (source with new spec)

$ wget https://kojipkgs.fedoraproject.org/packages/cernlib/2006/35.fc14/src/cernlib-2006-35.fc14.src.rpm
$ rpmbuild --noprep --rmspec -rp cernlib-2006-35.fc14.src.rpm
$ wget https://raw.githubusercontent.com/musinsky/config/master/CERNLIB/cernlib.spec -P $(rpm --eval %{_specdir})
$ rpmbuild -bs $(rpm --eval %{_specdir})/cernlib.spec
$ ls $(rpm --eval %{_srcrpmdir})
cernlib-2006-40.fc29.src.rpm

Ak zlyhava kompilacia, mozno manualne editovat a nasledne znova kompilovat v $HOME/rpmbuild/BUILD/cernlib-2006/2006/build/ dir, resp. subdirs, no je potrebne exportovat premenne

export CVSCOSRC=$HOME/rpmbuild/BUILD/cernlib-2006/2006/src
export CERN=$HOME/rpmbuild/BUILD/cernlib-2006
export CERN_LEVEL=2006
export CERN_VER=$CERN_LEVEL
export CERN_ROOT=$HOME/rpmbuild/BUILD/cernlib-2006/2006
export CVSCOSRC=$HOME/rpmbuild/BUILD/cernlib-2006/2006/src
export PATH=$PATH:$HOME/rpmbuild/BUILD/cernlib-2006/2006/bin
cd $HOME/rpmbuild/BUILD/cernlib-2006/2006/build/

Povodny cernlib.spec umoznoval (umoznuje) kompilaciu s g77 a gfortran a este k tomu aj cernlib 2005 alebo cernlib 2006, takze spolu znacna variabilita. Tento spec file postupne transformoval patches z Debian-u, kde sa tento balik viac menej do dnesneho dna aj udrzuje. Debian je vsak vzdy s gcc "dost pozadu", takze ak vznikne na Fedora s najnovsim gcc nejaky problem, tazko sa dopatrat nejakeho patch-u. Suma summarum, principialne CERNLIB moze "drzat krok" s Debian-om a postupne implementovat vsetky jeho dalsie patches (od 2010-05, resp. 2006.dfsg.2-14 patchset) avsak "salenota", o to viac, ze CERNLIB je viac menej mrtvy.

Kompletna dokumentacia k vsetkym CERNLIB knizniciam je stale pristupna na CERN Document Server, napr. HBOOK Statistical Analysis and Histogramming Reference Manual (v subore hbook.tar.gz sa okrem samotnej dokumentacii nachadzaju aj rozne funkcne fortran priklady) alebo GEANT Detector Description and Simulation Tool.

TODO
  • Preferovat cestu vytvarania patch-ov, pokial menim nieco v source code (cd source => git init => change => patch), a nie ako teraz, pomocou sed-u v spec subore "editujem" source code
  • Options pre kompilatory asi bude rozumnejsie zadavat zjednodusene, manualne a "prepisat" to, co je v rpm macros (obzvlast pre gfortran)
  • Cely spec subor radikalne precistit, len pre gfortran (vynechat g77) a len pre systemy napr. od roku 2015 (ponechat CentOS)
  • Ako kompilovat so static, resp. static gfortran

RPM

RPM pouziva mnozstvo roznych macros, ktore sa vyuzivaju pri build-ovani. RPM configuration file (macro) subory su definovane na viacerych miestach /usr/lib/rpm/macros, /usr/lib/rpm/redhat/macros pripadne $HOME/.rpmmacros. RPM configuration file (rpmrc) subory analogicky /usr/lib/rpm/rpmrc, /usr/lib/rpm/redhat/rpmrc alebo $HOME/.rpmrc. For definitions of more macros, examine the output of rpm --showrc. To see the expanded definition of a macro use the command rpm --eval %{macro_name}, more info in man rpm.

$ cp -i /usr/lib/rpm/redhat/macros $HOME/.rpmmacros   # now can edit and customize user options

$ rpm --eval "default arch = %{_arch}"
default arch = x86_64
$ rpm -E "system prefix = %{_prefix}"   # -E same as --eval
system prefix = /usr
$ rpm --eval %{optflags}   # Fedora 29 (x86_64)
-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
$ rpm --eval %{optflags}   # Fedora 26 (x86_64)
-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic

Z RPM balika mozeme ziskat (dopytat sa ho --query) mnozstvo tag-ov, informacii, more info in man rpm.

$ rpm --querytags | grep -i flag   # list of all tags (and grep)
$ rpm -q astyle
astyle-3.1-6.fc29.x86_64
$ rpm -q --queryformat "name=%{NAME} ver=%{VERSION} rel=%{RELEASE} arch=%{ARCH}\n" astyle
name=astyle ver=3.1 rel=6.fc29 arch=x86_64
$ rpm -q --queryformat "%{OPTFLAGS}\n" astyle
-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
$ rpm -q --queryformat "%{OPTFLAGS}\n" cernlib-2006-35.fc25.x86_64.rpm
-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic

Analogicky pre spec file, rpmspec is a tool for querying a spec file, more info in man rpmspec.

$ rpmspec -q --srpm $HOME/rpmbuild/SPECS/cernlib.spec
cernlib-2006-35.fc29.x86_64
$ rpmspec -q --queryformat "%{OPTFLAGS}\n" $(rpm --eval %{_specdir})/cernlib.spec
-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection

RPM build flags

The %{optflags} macro contains flags that determine CFLAGS, CXXFLAGS, FFLAGS, etc. (%{__global_cflags} macro evaluates to the same string)

$ rpm --eval %{__global_cflags}   # Fedora 29 (x86_64)
-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
$ rpm --eval %{configure}

$ rpmbuild --showrc | grep optflags

$ rpm --eval %{set_build_flags}   # Fedora 29 (x86_64)
CFLAGS="${CFLAGS:--O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection}" ; export CFLAGS ;
CXXFLAGS="${CXXFLAGS:--O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection}" ; export CXXFLAGS ;
FFLAGS="${FFLAGS:--O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules}" ; export FFLAGS ;
FCFLAGS="${FCFLAGS:--O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules}" ; export FCFLAGS ;
LDFLAGS="${LDFLAGS:--Wl,-z,relro   -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld}" ; export LDFLAGS

Using RPM build flags in redhat-rpm-config package in Fedora (actual info).

%{build_cflags} for the C compiler flags (also known as the CFLAGS variable). Also historically available as %{optflags}. The environment variable RPM_OPT_FLAGS is set to this value.
%{build_cxxflags} for the C++ compiler flags (usually assigned to the CXXFLAGS shell variable).
%{build_fflags} for the Fortran compiler flags (also known as FFLAGS or FCFLAGS variable).
%{build_ldflags} for the link editor (ld) flags (usually known as LDFLAGS). Note that the contents quotes linker arguments using -Wl, so this variable is intended for use with the gcc compiler driver. The environment variable RPM_LD_FLAGS is set to this value.
NOTES
$ diff -urNa file.orig file > file-patch.patch   # -u, -U NUM, --unified[=NUM] => output NUM (default 3) lines of unified context
$ git diff origin/HEAD > patch-file.patch              # -U<n>, --unified=<n> => Generate diffs with <n> lines of context instead of the usual three. Implies --patch.

ToDo: https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04.html https://unix.stackexchange.com/questions/478122/removing-root-slash-with-p1-and-so-forth

# patch0
--- brlaser.drv.in.orig>2021-01-29 20:22:32.833757102 +0100
+++ brlaser.drv.in<---->2021-01-13 23:06:04.383382397 +0100
# patch0 -p1
--- a/brlaser.drv.in
+++ b/brlaser.drv.in
  • Using %{buildroot} and %{optflags} (macro style) vs $RPM_BUILD_ROOT and $RPM_OPT_FLAGS (variable style). V principe je jedno, ktory styl pouzit, ale netreba ich navzajom miesat.
  • Comments, octothorp (#) at the start of the line, can be placed in any section of the spec file. Note that macros are expanded everywhere, so with multiline macros which would only have the first line commented also escape the percent (%) character
# This is the spec file
# %%configure

#%forgemeta          wrong
##%forgemeta         wrong
#%%forgemeta         OK (real comment)
#%%%forgemeta        wrong
%dnl anything        OK ('discard to next line' macro, rpm >= 4.15, 2019-09)
  • Opatrne s %changelog directive, syntax by mala byt nasledovna (prvy riadok)
Day-of-Week Month Day Year Name Surname <email> - Version-Release
Mon May 06 2019 Jan Musinsky <musinsky@gmail.com> - 2006-40
Wed May 05 2010 Jon Ciesla <limb@jcomserv.net> - 2006-35
$ rpmbuild -ba --define "optflags -O" $HOME/rpmbuild/SPECS/cernlib.spec
$ rpmbuild --define "optflags -ABC" --showrc | grep optflags
$ rpm --define "optflags -XYZ" --eval %{optflags}
  • Overwrite, override optflags in spec file
# spec file 
%define optflags XYZ321
%global optflags %{optflags} ADD123

%global optflags %(echo %{optflags} | sed 's/-O[0-3]/-O/')

$ rpmspec -q --queryformat "%{optflags}\n" $(rpm --eval %{_specdir})/cernlib.spec
$ rpmspec -P cernlib.spec   # !!! PARSING SPEC FILES TO STDOUT

2024-10

Build-ovanie napr. root balika je znacne narocne na samotnu kompilaciu (cca 0.5 hodiny). V pripade, ze kompilacia (cmake) prejde korektne, a nastane problem az pri samotnom build-ovani, je vhodne pri dalsom zapusteny rpmbuild -ba $HOME/rpmbuild/SPECS/root.spec proces kompilacie "preskocit". Pouzit pre %setup scriptlet option -D (do not delete the build directory prior to unpacking), pripadne aj option -T (skip the default unpacking of the first source), see [3].

%setup -q -a 1           # original
%setup -D -T -q -a 1     # skip