fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / ThirdParty / tools / makeThirdPartyFunctionsForRPM
blob87d82d441c52ac69dac030361b3f63e87e996db7
1 #---------------------------------*- sh -*-------------------------------------
2 # =========                 |
3 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4 #  \\    /   O peration     |
5 #   \\  /    A nd           | Copyright held by original author
6 #    \\/     M anipulation  |
7 #------------------------------------------------------------------------------
8 # License
9 #     This file is part of OpenFOAM.
11 #     OpenFOAM is free software: you can redistribute it and/or modify it
12 #     under the terms of the GNU General Public License as published by
13 #     the Free Software Foundation, either version 3 of the License, or
14 #     (at your option) any later version.
16 #     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 #     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 #     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19 #     for more details.
21 #     You should have received a copy of the GNU General Public License
22 #     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 # File
25 #     makeThirdPartyFunctionsForRPM
27 # Description
28 #     Functions for managing the third-party packages with RPM
30 #------------------------------------------------------------------------------
32 # define the build and the system architecture type
33 buildBase=$WM_THIRD_PARTY_DIR/rpmBuild
34 architecture=`rpm --eval "%{_target_cpu}"`
36 RPM_CMD='rpm' 
37 RPM_CMD_XTRA_OPTIONS='' 
39 # Adjust the rpm command options on Ubuntu/Debian based systems
40 ${RPM_CMD} --force-debian >& /dev/null
42 RETVAL=$?
43 [ $RETVAL -eq 0 ] && RPM_CMD_XTRA_OPTIONS="--force-debian" #Success : Debian system
45 echo ""
46 echo "This system rpm command: ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS}"
47 echo ""
50 # Download/Build/Uninstall/Install a package
52 rpm_make()
54     # Avoid word splitting on 'space'
55     IFS=$'\n'
57     # sort arguments
58     _PACKAGE=''
59     _SPECFILE=''
60     _PACKAGE_URL=''
61     _ADDITIONALFLAGS=''
63     while getopts p:s:u:a: flags
64       do
65       case $flags in
66           p)  _PACKAGE=$OPTARG
67               ;;
68           u)  _PACKAGE_URL=$OPTARG
69               ;;
70           s)  _SPECFILE=$OPTARG
71               ;;
72           a)  _ADDITIONALFLAGS=$OPTARG
73               ;;
74       esac
75     done
77     echo "Package name      : $_PACKAGE"
78     echo "Package URL       : $_PACKAGE_URL"
79     echo "RPM spec file name: $_SPECFILE"
80     echo "Additional flags  : $_ADDITIONALFLAGS"
82     # Shift options
83     shift `expr $OPTIND - 1`
85     # Make sure the ThirdParty environment is up-to-date
86     echo "Updating the ThirdParty environment variables before building package $_PACKAGE" 
87     . $WM_PROJECT_DIR/etc/settings.sh
89     rpmName=$_PACKAGE-$WM_OPTIONS.$architecture
90     rpmFile=$buildBase/RPMS/$architecture/$rpmName.rpm
92     # We check immediatly if the RPM binary package is available in the local RPMs vault.
93     # If so, we basically uninstall/reinstall the package. This is handy for installation
94     # on machines with no Internet access, so without downloading capabilities. If one wants to
95     # force the recompilation of a given package, just make sure to move the corresponding RPM
96     # binary package away from the local RPM vault.
97     #
98     if [ ! -e "$rpmFile" ]; then
99         #
100         # The package's RPM is absent. We build from the package source tarball 
101         #
102         cd $buildBase
104         #
105         # Do we need to download the package using the supplied URL
106         if [ -n "$_PACKAGE_URL" ]; then  
107             packageTarBall=`basename $_PACKAGE_URL`
109             if [ ! -e "SOURCES/$packageTarBall" ]; then
110                 echo "Download $packageTarBall from : $_PACKAGE_URL"
111                 ( cd SOURCES; wget --no-check-certificate $_PACKAGE_URL )
112             fi
113         fi
115         echo "Making package $_PACKAGE using RPM."
116         rpm_build ${_PACKAGE} ${_SPECFILE} ${_ADDITIONALFLAGS} "$@"
117     fi
119     # Install RPM package if not done already
120     if [ ! -e "$WM_THIRD_PARTY_DIR/packages/$_PACKAGE/platforms/$WM_OPTIONS" ]; then
121         echo "Installing package: $_PACKAGE"
122         rpm_uninstall $_PACKAGE
123         rpm_install   $_PACKAGE
124     else
125         echo "Package $_PACKAGE is already installed"
126     fi
128     unset _PACKAGE
129     unset _SPECFILE
130     unset _PACKAGE_URL
131     unset _ADDITIONALFLAGS
133     echo "Done installing package $_PACKAGE"
134     echo ""
138 # Build a RPM file using the package SPEC file
140 rpm_build()
142     package="$1"
143     specFile="$2"
144     shift 2
146     cd $buildBase
148     [ -e ./SPECS/$specFile ] || {
149         echo "rpm_build: missing SPEC file for package $package. Aborting."
150         return 1
151     }
153     #Build RPM package
154     echo "Building package $package using SPEC file : $specFile. Optional args: $@"
155     #rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --clean -bb ./SPECS/$specFile "$@"
156     #
157     # Let's keep the compilation directory alive for now in order to facilitate postmortems of failed compilations
158     rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB -bb ./SPECS/$specFile "$@"
162 # Uninstall a package using its RPM
164 rpm_uninstall()
166     package="$1"
167     rpmName=$package-$WM_OPTIONS.$architecture
169     cd $buildBase
171     echo "  Uninstalling $package using RPM: $rpmName"
172     ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS} -e $rpmName --dbpath $buildBase/rpmDB --norepackage >& /dev/null
174     # Note: rpm will rant when uninstalling packages with an error message
175     #       starting with "error: LOOP:"
176     #       Googling about this problem shows that this error is benign, and
177     #       is related to the list of the files included in the RPM, and the
178     #       syntax used in the SPEC file. Need to revisit later... MB
182 # Install a package using its relocatable RPM
184 rpm_install()
186     package="$1";
187     rpmName=$package-$WM_OPTIONS.$architecture;
188     rpmFile=$buildBase/RPMS/$architecture/$rpmName.rpm;
190     echo "  Installing $package using RPM file: $rpmFile";
191     ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS} -ivh              \
192         $rpmFile          \
193         --dbpath $buildBase/rpmDB --force --nodeps;
198 # Populate the local RPM vault with comand-line supplied list of RPMs
200 rpm_populateRPMvault()
202     rpmVault=$buildBase/RPMS/$architecture
204     echo " Local RPM vault location: $rpmVault"
205     echo ""
206     echo " Moving the following RPMs to the local RPM vault: `echo $@`" 
208     mkdir -p $rpmVault
209     mv $@ $rpmVault
211     echo ""
212     echo " Current content of the local RPM vault:"
213     ls -axlt $rpmVault
214     echo ""
217 # ----------------------------------------------------------------- end-of-file