HOTFIX: Adjust Windows build instructions repo
[foam-extend-3.2.git] / ThirdParty / tools / makeThirdPartyFunctionsForRPM
blobb256f394454f5eb75b79cf7bb57a93113270cc53
1 #---------------------------------*- sh -*-------------------------------------
2 # =========                 |
3 # \\      /  F ield         | foam-extend: Open Source CFD
4 #  \\    /   O peration     |
5 #   \\  /    A nd           | For copyright notice see file Copyright
6 #    \\/     M anipulation  |
7 #------------------------------------------------------------------------------
8 # License
9 #     This file is part of foam-extend.
11 #     foam-extend is free software: you can redistribute it and/or modify it
12 #     under the terms of the GNU General Public License as published by the
13 #     Free Software Foundation, either version 3 of the License, or (at your
14 #     option) any later version.
16 #     foam-extend is distributed in the hope that it will be useful, but
17 #     WITHOUT ANY WARRANTY; without even the implied warranty of
18 #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 #     General Public License for more details.
21 #     You should have received a copy of the GNU General Public License
22 #     along with foam-extend.  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=''
62     _RPMFILENAME=''
64     while getopts p:s:u:f:n:a: flags
65       do
66       case $flags in
67           p)  _PACKAGE=$OPTARG
68               ;;
69           u)  _PACKAGE_URL=$OPTARG
70               ;;
71           s)  _SPECFILE=$OPTARG
72               ;;
73           f)  _ADDITIONALFLAGS=$OPTARG
74               ;;
75           n)  _RPMFILENAME=$OPTARG
76               ;;
77           a)  architecture=$OPTARG
78               ;;
79       esac
80     done
82     echo "Package name      : $_PACKAGE"
83     echo "Package URL       : $_PACKAGE_URL"
84     echo "RPM spec file name: $_SPECFILE"
85     echo "Additional flags  : $_ADDITIONALFLAGS"
87     # Shift options
88     shift `expr $OPTIND - 1`
90     # Make sure the ThirdParty environment is up-to-date
91     echo "Updating the ThirdParty environment variables before building package $_PACKAGE"
92     . $WM_PROJECT_DIR/etc/settings.sh
94     if [ "$_RPMFILENAME" = "" ]; then
95         rpmName=$_PACKAGE-$WM_OPTIONS.$architecture
96     else
97         # Filename for the RPM was overridden from the command line
98         rpmName=$_RPMFILENAME
99     fi
101     rpmFile=$buildBase/RPMS/$architecture/$rpmName.rpm
103     echo "RPM file name     : $rpmFile"
105     # We check immediatly if the RPM binary package is available in the local RPMs vault.
106     # If so, we basically uninstall/reinstall the package. This is handy for installation
107     # on machines with no Internet access, so without downloading capabilities. If one wants to
108     # force the recompilation of a given package, just make sure to move the corresponding RPM
109     # binary package away from the local RPM vault.
110     #
111     if [ ! -e "$rpmFile" ]; then
112         #
113         # The package's RPM is absent. We build from the package source tarball
114         #
115         cd $buildBase
117         #
118         # Do we need to download the package using the supplied URL
119         if [ -n "$_PACKAGE_URL" ]; then
120             packageTarBall=`basename $_PACKAGE_URL`
122             if [ ! -e "SOURCES/$packageTarBall" ]; then
123                 echo "Download $packageTarBall from : $_PACKAGE_URL"
124                 ( cd SOURCES; wget --no-check-certificate $_PACKAGE_URL )
125             fi
126         fi
128         echo "Making package $_PACKAGE using RPM."
129         rpm_build ${_PACKAGE} ${_SPECFILE} ${_ADDITIONALFLAGS} "$@"
130         #rpm_build_install_stage_only ${_PACKAGE} ${_SPECFILE} ${_ADDITIONALFLAGS} "$@"
131     fi
133     # Install RPM package if not done already
134     if [ "$architecture" = "noarch" ]; then
135         installDir=$WM_THIRD_PARTY_DIR/packages/$_PACKAGE/platforms/noarch
136     else
137         installDir=$WM_THIRD_PARTY_DIR/packages/$_PACKAGE/platforms/$WM_OPTIONS
138     fi
140     if [ ! -e "$installDir" ]; then
141         echo "Installing package: $_PACKAGE"
142         rpm_uninstall $_PACKAGE $rpmName
143         rpm_install   $_PACKAGE $rpmName $rpmFile
144     else
145         echo "Package $_PACKAGE is already installed"
146     fi
148     unset _PACKAGE
149     unset _SPECFILE
150     unset _PACKAGE_URL
151     unset _ADDITIONALFLAGS
152     unset _RPMFILENAME
154     echo "Done installing package $_PACKAGE"
155     echo ""
159 # Build a RPM file using the package SPEC file
161 rpm_build()
163     package="$1"
164     specFile="$2"
165     shift 2
167     cd $buildBase
169     [ -e ./SPECS/$specFile ] || {
170         echo "rpm_build: Error: missing SPEC file for package $package. Aborting."
171         exit -1
172     }
174     #Build RPM package
175     echo "Building package $package using SPEC file : $specFile. Optional args: $@"
176     #rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --clean -bb ./SPECS/$specFile "$@"
177     #
178     # Let's keep the compilation directory alive for now in order to facilitate postmortems of failed compilations
179     rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB -bb ./SPECS/$specFile "$@"
183 # Build a RPM file using the package SPEC file. This function will only call the "%install" stage.
184 # Useful for debugging the "%install" stage.
186 rpm_build_install_stage_only()
188     package="$1"
189     specFile="$2"
190     shift 2
192     cd $buildBase
194     [ -e ./SPECS/$specFile ] || {
195         echo "rpm_build: Error: missing SPEC file for package $package. Aborting."
196         exit -1
197     }
199     #Build RPM package
200     echo "Building package $package using SPEC file : $specFile. Optional args: $@"
201     #rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --clean -bb ./SPECS/$specFile "$@"
202     #
203     # Let's keep the compilation directory alive for now in order to facilitate postmortems of failed compilations
204     rpmbuild --define "_topdir $buildBase" --dbpath $buildBase/rpmDB --short-circuit -bi ./SPECS/$specFile "$@"
208 # Uninstall a package using its RPM
210 rpm_uninstall()
212     package="$1"
213     rpmName="$2"
215     cd $buildBase
217     echo "  Uninstalling $package using RPM: $rpmName"
218     ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS} -e $rpmName --dbpath $buildBase/rpmDB --norepackage >& /dev/null
220     # Note: rpm will rant when uninstalling packages with an error message
221     #       starting with "error: LOOP:"
222     #       Googling about this problem shows that this error is benign, and
223     #       is related to the list of the files included in the RPM, and the
224     #       syntax used in the SPEC file. Need to revisit later... MB
228 # Install a package using its relocatable RPM
230 rpm_install()
232     package="$1";
233     rpmName="$2";
234     rpmFile="$3";
236     echo "  Installing $package using RPM file: $rpmFile";
237     ${RPM_CMD} ${RPM_CMD_XTRA_OPTIONS} -ivh              \
238         $rpmFile          \
239         --dbpath $buildBase/rpmDB --force --nodeps;
243 # Populate the local RPM vault with comand-line supplied list of RPMs
245 rpm_makeRPMvault()
247     rpmVault=$buildBase/RPMS/$architecture
249     if [ ! -e $rpmVault ]; then
250         echo ""
251         echo "Making directory for RPM-files $rpmVault"
252         echo ""
254         mkdir -p $rpmVault
255     fi
259 # Populate the local RPM vault with comand-line supplied list of RPMs
261 rpm_populateRPMvault()
263     rpmVault=$buildBase/RPMS/$architecture
265     echo " Local RPM vault location: $rpmVault"
266     echo ""
267     echo " Moving the following RPMs to the local RPM vault: `echo $@`"
269     mv $@ $rpmVault
271     echo ""
272     echo " Current content of the local RPM vault:"
273     ls -axlt $rpmVault
274     echo ""
278 # Remove an installed package
280 uninstallPackage()
282     pkg="$1";
284     echo "Removing ${pkg}"
285     [ -f $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm ] && \
286       rm -f $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm || \
287       echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/RPMS/$architecture/${pkg}*.rpm"
288     [ -f $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz ] && \
289       rm -f $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz || \
290       echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/SOURCES/${pkg}.tar.gz"
291     [ -f $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz ] && \
292       rm -f $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz || \
293       echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/TGZS/$architecture/${pkg}.tgz"
294     [ -d $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}* ] && \
295       rm -rf $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}* || \
296       echo "Not found: $WM_THIRD_PARTY_DIR/rpmBuild/BUILD/${pkg}*"
297     if [ "$2" = "alsoPackage" ]; then
298       [ -d $WM_THIRD_PARTY_DIR/packages/$pkg ] && \
299         rm -rf $WM_THIRD_PARTY_DIR/packages/$pkg || \
300         echo "Not found: $WM_THIRD_PARTY_DIR/packages/$pkg"
301     else
302         echo "Add option alsoPackage to remove the installed files."
303     fi
304     echo
307 # ----------------------------------------------------------------- end-of-file