CERNLIB

From StrelaWiki
Jump to navigation Jump to search
CERNLIB copr package repository for Fedora and CentOS
CERNLIB GitHub source repository (cernlib.spec)

CERNLIB in Fedora

 28974483 2010-05-05 20:29:33 cernlib-2006-35.fc14.src.rpm
  • Original cernlib.spec subor a posledny %changelog v nom
    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 s gfortran-om (a nie g77).

Build CERNLIB in Fedora

  • Fedora 29 (x86_64), GNU Fortran and gcc (GCC) 8.3.1 20190223
  • 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
$ # rpmbuild --define "_topdir /tmp/musinsky/rpmbuild" --rebuild cernlib-2006-40.fc29.src.rpm
$ rpmbuild -ra cernlib-2006-35.fc14.src.rpm

# many errors
  • 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)
  • Zaciname build-ovat a postupne patch-ovat spec file
$ cp -p $HOME/rpmbuild/SPECS/cernlib.spec $HOME/rpmbuild/SPECS/cernlib.spec.orig

error01

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

+ 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).
  • cernlib.spec edit 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

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

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 problemu error01
        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).
  • cernlib.spec add 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 zakomentovat. "Vyriesi sa" naraz error01 aj error02. Kompilacia prejde, ale bude s inymi options ako kompilacia ostatneho kodu. Options zo suboru $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 (po patch-ovani) na 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

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

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.
  • cernlib.spec add 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

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

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
  • Fedora pouziva pri build-ovani -Werror=format-security option (from %{optflags})
  • cernlib.spec add lines 960-961 (see also)
# fix printf (flis_name[i])
sed -i 's/printf (flis_name/printf ("\%s", flis_name/' packlib/kuip/code_kuip/kmenu.c

error05

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

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
  • libnsl2-devel potrebna pre Fedora 28 a vyssie
  • cernlib.spec add lines 94-96
%if 0%{?fedora} >= 28
BuildRequires: libnsl2-devel
%endif
  • cernlib.spec add lines 365-367
%if 0%{?fedora} >= 28
Requires: libnsl2-devel
%endif

previous Fedora

  • Fedora 25 (my old PC), 2017-03 gcc asi 6.4
  • Fedora 26 (strela205), 2019-04 gcc (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2)
  • Fedora 27 (strela07), 2019-04 gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6)
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 (from testing geant321) exam*. 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
  • cernlib.spec v Fedore pouziva default options pre kompilaciu definovane pomocou rpm makra %{optflags} a nie ako v Debian default -O3
# Fedora 26, gcc (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 -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
  • Stale vsak nie je jasne v com je problem (mozno gcc, mozno cernlib) ?!
  • 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.
  • cernlib.spec add 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

notes

  • 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 zlyha kompilacia, mozno manualne editovat, 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_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
  • Povodny cernlib.spec umoznuje (umoznoval) kompilaciu s g77 a gfortran a este k tomu aj cernlib 2005 alebo cernlib 2006, takze spolu znacna variabilita. Tento spec file postupne transformoval patchs 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.


  • CERNLIB in Fedora 25 (2017-03), problem s date after %changelog => zmazat cely changelog v spec subore
  • static => potrebuje static gfortran
  • /usr/lib64/cernlib <=> /usr/lib64/cernlib/ (slash at trailing)
  • changelog
* Wed May 05 2010 Jon Ciesla <limb@jcomserv.net> 2006-35
* Wed May 05 2010 Jon Ciesla <limb@jcomserv.net> - 2006-35

RPM

  • RPM pouziva mnozstvo roznych macros, ktore sa vyuzivaju pri build-ovani
  • Macro Configuration subory su definovane na viacerych miestach /usr/lib/rpm/macros, /usr/lib/rpm/redhat/macros pripadne ~/.rpmmacros
  • rpmrc Configuration subory analogicky /usr/lib/rpm/rpmrc, /usr/lib/rpm/redhat/rpmrc alebo ~/.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)
$ 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, informacie (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}
-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}

full complement of flags
$ rpmbuild --showrc | grep optflags

$ rpm --eval %{set_build_flags}   # fc29.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 aktualne info pre Fedoru
  • %{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.


$ rpmbuild -ba --define "optflags -O" $HOME/rpmbuild/SPECS/cernlib.spec
$ rpmbuild --define "optflags -ABC" --showrc | grep optflags
$ rpm --define "optflags -XYZ" --eval %{optflags}
  • 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


$ rpmspec -q --queryformat "%{optflags}\n" $(rpm --eval %{_specdir})/cernlib.spec
# spec file 
%define optflags XYZ321
%global optflags %{optflags} ADD123

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