Blob Blame History Raw
Name:          cernlib
Version:       2005
Release:       21%{?dist}
Summary:       General purpose CERN library and associated binaries
Group:         Development/Libraries
# As explained in the cernlib on debian FAQ, cfortran can be considered LGPL.
# http://borex.princeton.edu/~kmccarty/faq.html#44
License:       GPL/LGPL
URL:           http://cernlib.web.cern.ch/cernlib/
# mandrake
#BuildRequires: libxorg-x11-devel lesstif-devel libblas3-devel liblapack3-devel
#BuildRequires: gcc-g77
#Requires:      libxorg-x11-devel lesstif-devel libblas3-devel liblapack3-devel
# fedora core
BuildRequires: openmotif-devel
%if "%fedora" <= "3"
BuildRequires: lapack blas
%else
BuildRequires: lapack-devel blas-devel
%endif

%if "%fedora" <= "4"
BuildRequires: xorg-x11-devel 
%else
BuildRequires: imake 
# workaround #173530
BuildRequires: libXau-devel
%endif
# for patchy build scripts
BuildRequires: tcsh
BuildRequires: gawk
# there are missing f2c intrinsics in gfortran so gfortran cannot be used to
# build the cernlib
BuildRequires: /usr/bin/g77
BuildRoot:     %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

# these sources are different from the upstream sources as files with 
# GPL incompatible licences are removed. You can use cernlib-remove-deadpool
# and cernlib-deadpool.txt to recreate them from the upstream
# In a directoory with the cernlib sources, issue 
# sh cernlib-remove-deadpool 
Source3: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_geant321.tar.gz
Source4: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_graflib.tar.gz
Source7: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_mclibs.tar.gz
Source8: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_packlib.tar.gz 
Source10: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_pawlib.tar.gz
# not used during the build (if I'm not wrong)
Source15: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_car.tar.gz
# unmodified files
Source0: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_config.tar.gz
Source2: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_Imakefile.tar.gz
Source5: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_include.tar.gz
Source6: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_mathlib.tar.gz 
Source11: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_phtools.tar.gz
Source12: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_scripts.tar.gz
Source9: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_patchy.tar.gz
Source14: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/tar/src_cfortran.tar.gz
Source16: http://wwwasd.web.cern.ch/wwwasd/cernlib/download/2005_source/lib/xsneut95.dat
# The patchy version 4 sources
Source17: patchy.tar.gz
# this is modified with regard with what Mattias gave me. Indeed the file
# containing some other files (p4inceta) was in fortran unformatted format, 
# I believe it is what caused a segfault of rceta on the ppc platform.
# I have recreated the patchy.tar.gz from Mattias tarball by running
# sh patchy-unpack-rceta
Source203: patchy-unpack-rceta 

# Shell scripts that go in /etc/profile.d
Source100: cernlib.sh.in
Source105: cernlib.csh.in
# m4 macros for autoconf
Source101: cernlib.m4
# README file for paw slightly modified from the debian
Source102: paw.README
# README file that lists the changes done in the package
Source103: cernlib.README
# mkdirhier is used to create directories. Taken from xorg-x11
Source104: mkdirhier
# Files that can be used in the SOURCE directory to remove files with
# GPL incompatible licences from upstream sources
Source200: cernlib-remove-deadpool
Source201: cernlib-deadpool.txt

# debian patchset
Patch0: cernlib_2005.05.09.dfsg-6.diff
# change file to directory to DATADIR
Patch1100: cernlib-enforce-FHS.diff
Patch1: 001-fix-missing-fluka.dpatch
Patch2: 002-fix-missing-mclibs.dpatch
Patch3: 003-geant-dummy-functions.dpatch
Patch100: 100-fix-isajet-manual-corruption.dpatch
Patch101: 101-undefine-PPC.dpatch
Patch102: 102-dont-optimize-some-code.dpatch
Patch103: 103-ignore-overly-long-macro-in-gen.h.dpatch
Patch104: 104-fix-undefined-insertchar-warning.dpatch
Patch105: 105-fix-obsolete-xmfontlistcreate-warning.dpatch 
Patch106: 106-fix-paw++-menus-in-lesstif.dpatch
Patch107: 107-define-strdup-macro-safely.dpatch
Patch108: 108-quote-protect-comis-script.dpatch
# not used as xsneut.dat is at the right place
#Patch109: 109-fix-broken-xsneut95.dat-link.dpatch
Patch110: 110-ignore-included-lapack-rule.dpatch
Patch111: 111-fix-kuesvr-install-location.dpatch
Patch112: 112-remove-nonexistent-prototypes-from-gen.h.dpatch
# a workaround for cups. Applied in doubt.
Patch113: 113-cups-postscript-fix.dpatch
Patch114: 114-install-scripts-properly.dpatch
Patch115: 115-rsrtnt64-goto-outer-block.dpatch
Patch116: 116-fix-fconc64-spaghetti-code.dpatch
Patch117: 117-fix-optimizer-bug-in-gphot.dpatch
Patch200: 200-comis-allow-special-chars-in-path.dpatch
Patch201: 201-update-kuip-helper-apps.dpatch
Patch202: 202-fix-includes-in-minuit-example.dpatch
Patch203: 203-compile-geant-with-ertrak.dpatch
Patch204: 204-compile-isajet-with-isasrt.dpatch
Patch205: 205-max-path-length-to-256.dpatch
Patch206: 206-herwig-uses-DBLE-not-REAL.dpatch
Patch207: 207-compile-temp-libs-with-fPIC.dpatch
# without that patch the binaries are linked with something like
# libzftplib.a /builddir/build/BUILD/cernlib-2005/2005/build/packlib/cspack/programs/zftp/libzftplib.a
Patch208: 208-fix-redundant-packlib-dependencies.dpatch
Patch209: 209-ignore-unneeded-headers-in-kmutil.c.dpatch
Patch210: 210-improve-cfortran-header-files.dpatch
# split in newer debian patchset
Patch2110: 211-fix-comis-on-amd64.dpatch
Patch2111: 211-fix-comis-on-ia64-alpha.dpatch
Patch300: 300-skip-duplicate-lenocc.dpatch
# Use another approach, see cernlib-enforce-FHS
# Patch33: 301-datafiles-comply-with-FHS.dpatch
# use cernlib-gxint-script.diff instead and sed for paw and dzedit.script
# Patch34: 302-scripts-comply-with-FHS.dpatch
Patch303: 303-shadow-passwords-supported.dpatch
Patch304: 304-update-Imake-config-files.dpatch
Patch305: 305-use-POWERPC-not-PPC-as-test.dpatch
# the bug in /usr/include/assert.h seems to be present in FC-4. So a local
# version is provided in that patch. Will have to look at newer glibc-headers
# packages
Patch306: 306-patch-assert.h-for-makedepend.dpatch
Patch307: 307-use-canonical-cfortran.dpatch
Patch308: 308-use-canonical-cfortran-location.dpatch
Patch309: 309-define-dummy-herwig-routines.dpatch
Patch310: 310-define-dummy-fowl-routines.dpatch
# The zebra qnexte is a fake, removing it remove an unneeded dependency.
# the other qnext don't seem to be the same code? They are duplicate symbols
# anyway so one must be removed
Patch311: 311-skip-duplicate-qnext.dpatch
Patch312: 312-skip-duplicate-gamma.dpatch
# It is a departure from upstream. Apply, but may revert if not agreed.  
Patch313: 313-comis-preserves-filename-case.dpatch
Patch314: 314-permit-using-regcomp-for-re_comp.dpatch
Patch315: 315-fixes-for-MacOSX.dpatch
Patch318: 318-additional-gcc-3.4-fixes.dpatch
# certainly not needed, but who knows?
Patch319: 319-work-around-imake-segfaults.dpatch

Patch700: 700-remove-kernlib-from-packlib-Imakefile.dpatch
Patch701: 701-patch-hbook-comis-Imakefiles.dpatch
Patch702: 702-patch-Imakefiles-for-packlib-mathlib.dpatch
# I would have preferred not to move the motif code to toplevel...
Patch703: 703-patch-code_motif-packlib-Imakefiles.dpatch
Patch704: 704-patch-code_kuip-higzcc-Imakefiles.dpatch
# I would have preferred not to move the motif code to toplevel...
Patch705: 705-patch-paw_motif-paw-Imakefiles.dpatch

Patch800: 800-implement-shared-library-rules-in-Imake.dpatch
Patch801: 801-non-optimized-rule-uses-fPIC-g.dpatch
Patch802: 802-create-shared-libraries.dpatch
# in the original cernlib kxterm is built with the C compiler, which cause
# a failure if compiled with the cernlib debian script as -lg2c isn't found. 
# It is corrected in
Patch803: 803-link-binaries-dynamically.dpatch
# 803 depends on 
# 208-fix-redundant-packlib-dependencies.dpatch

# no idea about what this does
Patch804: 804-workaround-for-comis-mdpool-struct-location.dpatch
Patch805: 805-expunge-missing-mathlib-kernlib-symbols.dpatch 
# not needed but keep sync with debian, that'll avoid bumping sonames
Patch806: 806-bump-mathlib-and-dependents-sonames.dpatch

# not applied in newer debian patchset
Patch3006: 022-no-assign-string-literals
# fixed upstream
Patch3007: 027-use-tmpfile-not-mktemp
# not applied in the newer debian patchset
Patch3008: 031-fix-varargs-use
# fixed upstream 
Patch3009: 048-log-to-var-log-not-tmp
# fixed upstream
Patch3010: 049-fix-kuesvr-security-hole
# fixed upstream
Patch3011: 050-make-secure-comis-tmpdir
# fixed upstream
Patch3012: 051-fix-miscellaneous-tmp-uses

# change the cernlib script such that -llapack -lblas is used instead of 
# cernlib lapack
# depend explicitely on libkernlib now that it is out of packlib
# use lesstif-pawlib and lesstif-packlib
# the modified script is renamed cernlib-static later and the debian cernlib
# script is used instead.
Patch1200: cernlib-cernlib_kernlib.patch
# don't stop if the CERN variable isn't defined
Patch1201: cernlib-gxint-script.diff
Patch1203: cernlib-hwuli2_use_dimag.diff 
Patch1204: cernlib-hwhiga_use_dimag.diff
Patch1205: cernlib-gfortran.diff 
Patch1207: cernlib-v107z0_X_before_string.diff

# patchy 4
# not applied as it has allready been done by the sed one-liner in 
# patchy-unpack-rceta
Patch1500: patchy-rceta.patch

Patch1501: patchy-insecure_tmp_use.diff
Patch1502: patchy-fcasplit.patch
Patch1503: patchy-p4comp.patch

# patchy 5 (included in cernlib)
Patch1504: patchy-case.patch
Patch1505: patchy-perror.patch
Patch1506: patchy-yexpand.diff

%description
CERN program library is a large collection of general purpose libraries
and modules maintained and offered on the CERN. Most of these programs 
were developed at CERN and are therefore oriented towards the needs of a 
physics research laboratory that is general mathematics, data analysis, 
detectors simulation, data-handling etc... applicable to a wide range 
of problems.

The main and devel packages are parallel installable, but not the helper
scripts from the utils subpackage.

%package devel
Summary:       General purpose CERN library static libraries and headers
Requires:      openmotif-devel
%if "%fedora" <= "3"
Requires:       lapack blas
%else
Requires:       lapack-devel blas-devel
%endif

%if "%fedora" > "4"
# workaround #173530
Requires:      libXau-devel
%endif
Requires:      %{name} = %{version}-%{release}
Group:         Development/Libraries

%description devel
CERN program library is a large collection of general purpose libraries
and modules maintained and offered on the CERN. Most of these programs 
were developed at CERN and are therefore oriented towards the needs of a 
physics research laboratory that is general mathematics, data analysis, 
detectors simulation, data-handling etc... applicable to a wide range 
of problems.

The cernlib-devel package contains the header files and libraries needed  
to develop programs that use the CERN library.  

%package utils
Summary:   CERN library compilation and environment setting scripts
Group:     Applications/System
Requires:  %{name}-devel = %{version}-%{release}

%description utils
CERN library compilation and environment setting scripts.

This package will conflict with other versions, therefore if you 
want to have different compile script and different environments for 
different versions of the library you have to set them by hand.

%package -n paw
Group: Applications/Engineering
Summary: A program for the analysis and presentation of data

%description -n paw
PAW is conceived as an instrument to assist physicists in the analysis and 
presentation of their data. It provides interactive graphical presentation 
and statistical or mathematical analysis, working on objects familiar to 
physicists like histograms, event files (Ntuples), vectors, etc. PAW is 
based on several components of the CERN Program Library.

%package -n geant321
Summary:  Particle detector description and simulation tool
Group:    Applications/Engineering
Requires: cernlib-devel cernlib-utils
%description -n geant321
Geant simulates the passage of subatomic particles through matter, for 
instance, particle detectors. For maximum flexibility, Geant simulations 
are performed by linking Fortran code supplied by the user with the Geant 
libraries, then running the resulting executable.

This package includes gxint, the script used to perform this linking step. 

%package -n kuipc
Summary:  Cernlib's Kit for a User Interface Package (KUIP) compiler
Group:    Development/Languages
Requires: cernlib-devel

%description -n kuipc
KUIPC, the Kit for a User Interface Package Compiler, is a tool to simplify 
the writing of a program's user interface code. It takes as input a Command 
Definition File (CDF) that describes the commands to be understood by the 
program, and outputs C or FORTRAN code that makes the appropriate function 
calls to set up the user interface. This code can then be compiled and linked 
with the rest of the program. Since the generated code uses KUIP routines, 
the program must also be linked against the Packlib library that contains them.

%package packlib
Group: Applications/Archiving
Summary: I/O, network and other utilities from the cernlib

%description packlib
I/O, network and miscalleneous utilities based on the CERN Program 
Library. 
According to the responsible of the cernlib debian package, some
of these utilities may have security flaws.

%package -n patchy
Group: Applications/Archiving
Summary: The patchy utilities

%description -n patchy
Utilities for extracting sources from patchy cards and cradles.


%prep
%setup -c 
%setup -T -D -a 2
%setup -T -D -a 3
%setup -T -D -a 4
%setup -T -D -a 5
%setup -T -D -a 6
%setup -T -D -a 7
%setup -T -D -a 8
%setup -T -D -a 9
%setup -T -D -a 10
%setup -T -D -a 11
%setup -T -D -a 12
%setup -T -D -a 14
%setup -T -D -a 15
%setup -T -D -a 17

# patch patchy 4 installer fortran generator script
# avtually it is unusefull, because the unpacking has been done
# offline, see comment above.
#%patch -P 1500

%patch -P 1501

# unpack the patchy version 4 sources is done offline,
# see comment above
#pushd patchy
#        ./rceta.sh
#popd

%patch -P 1502
%patch -P 1503


%patch -p1
cd %{version}
%patch -P 1100 -p2
%patch -P 1 -p1
%patch -P 2 -p1
%patch -P 3 -p1
%patch -P 100 -p1
%patch -P 101 -p1
%patch -P 102 -p1
%patch -P 103 -p1
%patch -P 104 -p1
%patch -P 105 -p1
%patch -P 106 -p1
%patch -P 107 -p1
%patch -P 108 -p1
#%patch -P 109 -p1
%patch -P 110 -p1
%patch -P 111 -p1
%patch -P 112 -p1
%patch -P 113 -p1
%patch -P 114 -p1
%patch -P 115 -p1
%patch -P 116 -p1
%patch -P 117 -p1
%patch -P 200 -p1
%patch -P 201 -p1
%patch -P 202 -p1
%patch -P 203 -p1
%patch -P 204 -p1
%patch -P 205 -p1
%patch -P 206 -p1
%patch -P 207 -p1
%patch -P 208 -p1
%patch -P 209 -p1
%patch -P 210 -p1
%patch -P 2110 -p1
%patch -P 2111 -p1
%patch -P 300 -p1
#%patch -P 301 -p1
#%patch -P 302 -p1
%patch -P 303 -p1
%patch -P 304 -p1
%patch -P 305 -p1
%patch -P 306 -p1
%patch -P 307 -p1
%patch -P 308 -p1
%patch -P 309 -p1
%patch -P 310 -p1
%patch -P 311 -p1
%patch -P 312 -p1
%patch -P 313 -p1
%patch -P 314 -p1
%patch -P 315 -p1

# copy a paw include file to include directory (debian
# 317-copy-converter.h-to-installed-headers-dir.sh.dpatch)
cp src/pawlib/paw/tree/converter.h src/pawlib/paw/paw/

%patch -P 318 -p1
%patch -P 319 -p1

# move kernlib out of packlib (debian 700-move-kernlib-to-top-level.sh.dpatch)
mv src/packlib/kernlib src/kernlib

%patch -P 700 -p1

# move hkf1q.F and hkfill.F out of packlib/hbook and into
# pawlib/comis where they obviously belong (it even says so in the files!)
# (debian 701-move-packlib-hkfill-to-comis.sh.dpatch)
pushd src
                mv packlib/hbook/code/hkf1q.F  pawlib/comis/code/
                mv packlib/hbook/code/hkfill.F pawlib/comis/code/
                # these files also need some headers to go with them:
                mkdir pawlib/comis/hbook
                cp -p packlib/hbook/hbook/pilot.h    pawlib/comis/hbook/
                cp -p packlib/hbook/hbook/hcbook.inc pawlib/comis/hbook/
                cp -p packlib/hbook/hbook/hcbits.inc pawlib/comis/hbook/
                cp -p packlib/hbook/hbook/hcfast.inc pawlib/comis/hbook/
popd

%patch -P 701 -p1

# Must create dirs before applying following patch. 
# Corresponds with 702-fix-packlib-mathlib-circular-mess.sh.dpatch

pushd src
                # Hdiff depends upon a bunch of mathlib files; move it into
                # mathlib.
                mkdir mathlib/hbook
                mv packlib/hbook/hdiff mathlib/hbook/
                cp -r packlib/hbook/hbook mathlib/hbook/

                # Meanwhile, other packlib files depend upon these mathlib
                # files which are easily moved:
                mkdir packlib/hbook/d
                mv mathlib/gen/d/rgmlt*.F packlib/hbook/d/
                mv mathlib/gen/n          packlib/hbook/
                cp -r mathlib/gen/gen     packlib/hbook/
popd

%patch -P 702 -p1

# Script to move packlib/kuip/code_motif to top level, splitting it out
# from packlib.  But keep kmutil.c in packlib, it's otherwise used.
# debian 703-move-code_motif-to-top-level.sh.dpatch

pushd src
                mv packlib/kuip/code_motif/kmutil.c packlib/kuip/code_kuip/
                mv packlib/kuip/code_motif          ./
                cp -r packlib/kuip/kuip             code_motif/
popd

%patch -P 703 -p1

# Script to move the file kuwhag.c from packlib/kuip/code_kuip/kuwhag.c
# into graflib/higz/higzcc.  It appears to be the only file in code_kuip
# that depends upon grafX11 and libX11, so it fits in better here.
# debian 704-move-kuwhag.c-to-grafX11.sh.dpatch

pushd src
                mv packlib/kuip/code_kuip/kuwhag.c graflib/higz/higzcc/
                cp -r packlib/kuip/kuip            graflib/higz/
popd

%patch -P 704 -p1

# Script to move Lesstif-dependent Paw code into its own library.
# debian 705-move-paw++-code-to-top-level.sh.dpatch

pushd src
                mkdir paw_motif
                mv pawlib/paw/?motif pawlib/paw/fpanels? paw_motif/
                mv pawlib/paw/tree pawlib/paw/uimx pawlib/paw/xbae* paw_motif/
                cp -p pawlib/paw/Imakefile paw_motif/
                
                mkdir paw_motif/code
                mv pawlib/paw/code/pawpp.F   paw_motif/code/
                mv pawlib/paw/code/pawintm.F paw_motif/code/

                mkdir paw_motif/cdf
                mv pawlib/paw/cdf/pamcdf.cdf paw_motif/cdf/

                cp -pr pawlib/paw/paw paw_motif/
                cp -pr pawlib/paw/hpaw paw_motif/
popd

%patch -P 705 -p1

%patch -P 800 -p1
%patch -P 801 -p1
%patch -P 802 -p1
%patch -P 803 -p1

# Shell script to link pawlib/comis/comis into the top-level include directory.
# debian 804-link-to-comis-includes.sh.dpatch
pushd src
                ln -s ../pawlib/comis/comis include/comis
popd

%patch -P 804 -p1
%patch -P 805 -p1
%patch -P 806 -p1

%patch -P 1504 -p1
%patch -P 1505 -p1
%patch -P 1506 -p1

%patch -P 1200
%patch -P 1201
%patch -P 1203
%patch -P 1204
# use gfortran
#%patch -P 1205 -p1
# workaround gfortran bug
%patch -P 1207

# remove CVS directories
find . -depth -type d -name CVS -exec rm -rf {} ';' 

# unset executable bit on source files
chmod a-x src/kernlib/kerngen/ccgencf/cfstati.c \
  src/cfortran/cfortran.*

# remove empty header file not needed anywhere to shut up rpmlint
rm src/pawlib/paw/ntuple/dbmalloc.h

%build

CERN=$RPM_BUILD_DIR/cernlib-%{version}
CERN_LEVEL=%{version}
CERN_ROOT=$CERN/$CERN_LEVEL
CVSCOSRC=$CERN/$CERN_LEVEL/src
PATH=$CERN_ROOT/bin:$PATH

export CERN
export CERN_LEVEL
export CERN_ROOT 
export CVSCOSRC
export PATH

LIB_SONAME=1
export LIB_SONAME

# set the CERN and CERN_LEVEL environment variables in shell scripts
# meant to go to /etc/profile.d
sed -e 's/==CERN_LEVEL==/%{version}/' -e 's:==CERN==:%{_libdir}/cernlib:' %{SOURCE100} > cernlib-%{version}.sh
sed -e 's/==CERN_LEVEL==/%{version}/' -e 's:==CERN==:%{_libdir}/cernlib:' %{SOURCE105} > cernlib-%{version}.csh

cp %{SOURCE101} .
cp %{SOURCE102} .
cp %{SOURCE103} .

# Regenerate the copyright file (from debian/rules)
grep -v DEADPOOL_LIST_GOES_HERE debian/copyright.in > copyright
sed -e 's/#.*//g' -e '/^[[:space:]]*$$/d' %{SOURCE200} | \
                sort | uniq >> copyright

# copy xsneut.data in 2005/share/lib, where geant expects it to be
# there is a link from 2005/lib
mkdir -p %{version}/share/lib
cp %{SOURCE16} %{version}/share/lib

cd $CERN_ROOT

# substitude the right defaults in the scripts
sed -i -e 's:"/cern":"%{_libdir}/cernlib/":' -e 's:"pro":"%{version}":' \
	src/scripts/paw src/scripts/cernlib src/graflib/dzdoc/dzedit/dzedit.script \
	../patchy/ylist ../patchy/yindex

# substitute version in gxint with the right version
# substitute includedir in gxint to conform to FHS, and gxint.o to gxint.f
sed -i -e 's/"pro"/%{version}/' -e 's:\${CERN}/\${ver}/lib/gxint\${gvs}\.\$_o:%{_includedir}/cernlib/\${ver}/gxint.f:' src/scripts/gxint 

# substitute DATADIR in source files to conform to FHS
sed -i -e 's:DATADIR:%{_datadir}/cernlib/%{version}:' \
  src/geant321/miface/gmorin.F src/mclibs/cojets/test/test.F src/mclibs/eurodec/eurodec/eufiles.inc src/mclibs/isajet/test/isajett.F

# substitute bindir in ylist and yindex to conform to FHS
sed -i -e 's:\$CERN/patchy/\$PATCHY_VERSION/bin:%{_bindir}:' ../patchy/ylist ../patchy/yindex

# Create the build directory structure
mkdir -p build bin lib shlib

# rename the cernlib script cernlib-static and use the debian cernlib
# script for dynamic libraries support
# remove -lg2c to the link commands, because libg2c.so isn't available, 
# it is found by g77 if needed
mv src/scripts/cernlib bin/cernlib-static
sed -e 's:@PREFIX@:%{_prefix}:g' \
  -e 's:@LIBPREFIX@:%{_libdir}/cernlib/%{version}:g' \
  -e 's/-lg2c//' \
  ../debian/add-ons/bin/cernlib.in > src/scripts/cernlib
chmod 0755 src/scripts/cernlib

# install mkdirhier which is needed to make directories
cp %{SOURCE104} bin/
chmod a+x bin/mkdirhier

PATHSAVE=$PATH
# Build patchy version 4
pushd ../patchy
#        export PATH="$CERN/patchy:$CERN/patchy/p4sub:$PATH" 
        export PATH=".:..:$PATH" 
        p4boot.sh 0
popd
find ../patchy -name y* -a -perm -755 -exec install {} bin ';'
export PATH=$PATHSAVE

# Create the top level Makefile with imake

cd $CERN_ROOT/build
$CVSCOSRC/config/imake_boot

# the RPM optflags are not used during the build

# Install kuipc and the scripts (cernlib, paw and gxint) in $CERN_ROOT/bin

make %{?_smp_mflags} bin/kuipc
make patchy/Makefile
make scripts/Makefile
cd scripts
make install.bin

# Install the libraries

cd $CERN_ROOT/build
#  %{?_smp_mflags} breaks the build
make
make install.shlib
chmod a+x ../shlib/*.so.*

# Build dynamic paw
cd $CERN_ROOT/build/pawlib
make %{?_smp_mflags} install.bin
cd $CERN_ROOT/
mv bin/pawX11 bin/pawX11.dynamic
mv bin/paw++ bin/paw++.dynamic
# Build static paw
g77 $CERN_ROOT/build/pawlib/paw/programs/0pamain.o \
  `cernlib -G X11 pawlib` -Wl,-E -o bin/pawX11
g77 $CERN_ROOT/build/pawlib/paw/programs/0pamainm.o \
  `cernlib -G Motif pawlib` -Wl,-E -o bin/paw++

# Build packlib
cd $CERN_ROOT/build/packlib
make %{?_smp_mflags} install.bin

# Build npatchy
# The build of patchy is completly messed up on ppc
%ifnarch ppc
cd $CERN_ROOT/build/patchy
make %{?_smp_mflags} install.bin
%endif

%install

rm -rf $RPM_BUILD_ROOT

%{__install} -d -m755 $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
%{__install} -m755 cernlib-%{version}.sh $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
%{__install} -m755 cernlib-%{version}.csh $RPM_BUILD_ROOT%{_sysconfdir}/profile.d

%{__install} -d -m755 cfortran/Examples
%{__install} -m644 %{version}/src/cfortran/Examples/*.c cfortran/Examples/

%{__install} -d -m755 $RPM_BUILD_ROOT%{_datadir}/aclocal
%{__install} -m644 cernlib.m4 $RPM_BUILD_ROOT%{_datadir}/aclocal/cernlib.m4

cd %{version}
%{__install} -d -m755 $RPM_BUILD_ROOT%{_libdir}/cernlib/%{version}/lib
%{__install} -d -m755 $RPM_BUILD_ROOT%{_datadir}/cernlib/%{version}
%{__install} -d -m755 $RPM_BUILD_ROOT%{_includedir}/cernlib/%{version}
%{__install} -d -m755 $RPM_BUILD_ROOT%{_includedir}/cernlib/%{version}/cfortran
%{__install} -d -m755 $RPM_BUILD_ROOT%{_bindir}/

%{__install} -m644 lib/*.dat $RPM_BUILD_ROOT%{_datadir}/cernlib/%{version}
%{__install} -m644 lib/gxint321.f $RPM_BUILD_ROOT%{_includedir}/cernlib/%{version}
%{__install} -m644 src/cfortran/*.h $RPM_BUILD_ROOT%{_includedir}/cernlib/%{version}/

%{__install} -m755 bin/* $RPM_BUILD_ROOT%{_bindir}/

# add a link to pawX11 from %{_libdir}/cernlib/%{version}/bin
%{__install} -d -m755 $RPM_BUILD_ROOT%{_libdir}/cernlib/%{version}/bin/
%{__ln_s} %{_bindir}/pawX11 $RPM_BUILD_ROOT%{_libdir}/cernlib/%{version}/bin/pawX11

# to preserve symlinks
(cd lib && tar cf - *.a) | (cd $RPM_BUILD_ROOT%{_libdir}/cernlib/%{version}/lib && tar xf -)
(cd shlib && tar cf - *.so*) | (cd $RPM_BUILD_ROOT%{_libdir}/cernlib/%{version}/lib && tar xf -)

rm -f $RPM_BUILD_ROOT%{_bindir}/mkdirhier

# add links for cfortran header files in the top include directory
pushd $RPM_BUILD_ROOT%{_includedir}/cernlib/%{version}
for file in *.h; do
	%{__ln_s} ../$file cfortran/$file
done
%{__ln_s} gxint321.f gxint.f
popd

cd src
# install include directories for the cernlib libraries
base_include=$RPM_BUILD_ROOT%{_includedir}/cernlib/%{version}
for dir in `cat ../../debian/add-ons/includelist.txt`; do
	basedir=`basename $dir`
	rm -rf $base_include/$basedir
	cp -Rp $dir $base_include/
done

%{__install} -d -m755 $RPM_BUILD_ROOT/etc/ld.so.conf.d
echo %{_libdir}/cernlib/%{version}/lib > $RPM_BUILD_ROOT/etc/ld.so.conf.d/cernlib-%{version}-%{_arch}.conf

find $RPM_BUILD_ROOT%{_includedir}/cernlib/%{version} -name Imakefile -exec rm -f \{\} \;
rm -f $RPM_BUILD_ROOT%{_includedir}/cernlib/%{version}/ntuple/*.c

%clean
rm -rf $RPM_BUILD_ROOT

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%files
%defattr(-,root,root,-)
/etc/ld.so.conf.d/*
%dir %{_libdir}/cernlib/
%dir %{_libdir}/cernlib/%{version}
%dir %{_libdir}/cernlib/%{version}/lib
%dir %{_libdir}/cernlib/%{version}/bin
%{_libdir}/cernlib/%{version}/lib/*.so.*
%{_datadir}/cernlib/
%doc cernlib.README copyright
%doc debian/debhelper/geant321.README.debian 
%doc debian/debhelper/libpdflib804-2-dev.README.debian
%doc debian/debhelper/montecarlo-base.README.debian

# the utils and devel are separated to have the possibility to install
# parallel versions of the library
%files devel
%defattr(-,root,root,-)
%{_libdir}/cernlib/%{version}/lib/*.a
%{_libdir}/cernlib/%{version}/lib/*.so
%{_includedir}/cernlib/
%{_datadir}/aclocal/cernlib.m4
%doc cfortran 

%files utils
%defattr(-,root,root,-)
%{_bindir}/cernlib*
%{_sysconfdir}/profile.d/cernlib-%{version}.sh
%{_sysconfdir}/profile.d/cernlib-%{version}.csh

%files -n paw
%defattr(-,root,root,-)
%{_bindir}/paw++
%{_bindir}/paw
%{_bindir}/pawX11
%{_bindir}/pawX11.dynamic
%{_bindir}/paw++.dynamic
%dir %{_libdir}/cernlib/%{version}/bin
%{_libdir}/cernlib/%{version}/bin/pawX11
%doc paw.README 

%files -n geant321
%defattr(-,root,root,-)
%{_bindir}/gxint

%files -n kuipc
%defattr(-,root,root,-)
%{_bindir}/kuipc

%files packlib
%defattr(-,root,root,-)
%{_bindir}/cdbackup
%{_bindir}/cdserv
%{_bindir}/fatmen
%{_bindir}/fatsrv
%{_bindir}/kuesvr
%{_bindir}/zserv
%{_bindir}/cdmake
%{_bindir}/fatnew
%{_bindir}/pawserv
%{_bindir}/cdmove
%{_bindir}/fatback
%{_bindir}/fatsend
%{_bindir}/hepdb
%{_bindir}/kxterm
%{_bindir}/zftp
%doc debian/debhelper/zftp.README.debian

%files -n patchy
%defattr(-,root,root,-)
%ifnarch ppc
%{_bindir}/fcasplit
%{_bindir}/nycheck
%{_bindir}/nydiff
%{_bindir}/nyindex
%{_bindir}/nylist
%{_bindir}/nymerge
%{_bindir}/nypatchy
%{_bindir}/nyshell
%{_bindir}/nysynopt
%{_bindir}/nytidy
%{_bindir}/yexpand
%endif
%{_bindir}/ycompar
%{_bindir}/yedit
%{_bindir}/yfrceta
%{_bindir}/yindex
%{_bindir}/yindexb
%{_bindir}/ylist
%{_bindir}/ylistb
%{_bindir}/ypatchy
%{_bindir}/ysearch
%{_bindir}/yshift
%{_bindir}/ytobcd
%{_bindir}/ytobin
%{_bindir}/ytoceta


%changelog
* Wed May 24 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-21
- compile paw statically against the cernlib (paw binaries dynamically 
  compiled against the cernlib are still shiped). Fix 192866

* Wed May 17 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-20
- use new debian patchset. Fix 191631

* Tue Apr 13 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-19
- add a patch to yexpand, to avoid using $HOME.

* Tue Apr 13 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-17
- npatchy don't build on ppc.

* Wed Apr 12 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-16
- unpack patchy offline because the files are within an unformatted
  fortran file which won't be right on all the arches.

* Tue Apr 11 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-15.1
- add conditionals in spec to have only one for all fedora versions.

* Tue Apr 11 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-14
- add patchy version 4 and build cernlib patchy. From Mattias Ellert.
- update to newer debian patchset

* Thu Feb 16 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-13
- rebuild for fc5

* Tue Jan 17 2006 Patrice Dumas <dumas at centre-cired.fr> - 2005-12.1
- attempt a rebuild against newer openmotif

* Tue Dec 20 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-11.4
- add a symlink from /usr/lib/cernlib/2005/bin/pawX11 to /usr/bin/pawX11
- fix gxint

* Tue Dec 20 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-10
- add file in /etc/ld.so.conf.d required for dynamic linking

* Wed Dec 14 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-9.1
- use new debian patchset

* Fri Dec  9 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-8.1
- use new debian patchset
- enable 64 bit fixes patch

* Fri Dec  2 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-7
- use updated beta debian patchset
- remove the BSD in the licence because there is no library nor binary
  under a BSD licence and someone could get the idea that there is 
  some dual BSD/GPL licenced binaries or libraries. The LGPL is kept
  because of cfortran

* Tue Nov 29 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-6.1
- update with newer debian patchset for cernlib, fix licence issues
- don't use the include.tar.gz source, instead get include files from
  the source files
- build shared libraries
- simplify the scripts modifications
- add BuildRequires: libXau-devel to workaround #173530

* Tue Nov 15 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-4
- add a .csh file
- correct defaults in cernlib scripts

* Sun Sep 11 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-3
- add rm -rf $RPM_BUILD_ROOT

* Thu Sep  1 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-2
- minor update of cernlib.README
- modify the cernlib script patch to use /usr/X11R6/lib64 if existing

* Tue Jun 09 2005 Patrice Dumas <dumas at centre-cired.fr> - 2005-1
- full rewrite of the spec file from Scientific Linux
- use some ideas and many patches from debian cernlib