Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / bin / foamPackMake
blobc4b6841301876d07a63f3da0c14bb795741108b7
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
7 # \\/ M anipulation |
8 #-------------------------------------------------------------------------------
9 # License
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamPackMake [OPTION] <archOptions>
28 # Description
29 # Pack and compress OpenFOAM Make/<archOptions> directories
31 # Script
32 # foamPackThirdPartyMake [OPTION] <archOptions>
34 # Description
35 # Pack and compress OpenFOAM ThirdParty Make/<archOptions> directories
37 #------------------------------------------------------------------------------
38 toolsDir="${0%/*}/tools" # this script is located in the tools/ parent dir
40 case "${0##*/}" in
41 *ThirdParty*)
42 # for ThirdParty
43 codeBase="OpenFOAM ThirdParty"
44 packDir=ThirdParty-$WM_PROJECT_VERSION
47 # regular
48 codeBase="OpenFOAM"
49 packDir=$WM_PROJECT-$WM_PROJECT_VERSION
51 esac
54 usage() {
55 exec 1>&2
56 while [ "$#" -gt 0 ]; do echo "$1"; shift; done
57 cat <<USAGE
58 Usage: ${0##*/} [OPTION] <archOptions>
59 ${0##*/} [OPTION] -current
60 options:
61 -b, -bzip2 use bzip2 instead of gzip compression
62 -c, -current use current value of \$WM_OPTIONS
63 -o, -output <dir> specify alternative output directory
65 * Pack and compress $codeBase Make/<archOptions> directories
67 The value of 'archOptions' normally corresponds to \$WM_OPTIONS
68 The current value of \$WM_OPTIONS = $WM_OPTIONS
70 USAGE
71 exit 1
75 unset archOptions outputDir
76 packExt=tgz
78 # parse options
79 while [ "$#" -gt 0 ]
81 case "$1" in
82 -h | -help)
83 usage
85 -b | -bzip2)
86 packExt=tbz
87 shift
89 -c | -current) # use $WM_OPTIONS - eg, 'linux64GccDPOpt'
90 archOptions="$WM_OPTIONS"
91 shift
93 -o | -output)
94 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
95 outputDir=${2%%/}
96 shift 2
98 -*)
99 usage "unknown option: '$*'"
102 break
104 esac
105 done
107 if [ -n "$archOptions" ]
108 then
109 [ $# -eq 0 ] || usage "Error: cannot specify both -current and architecture"
110 else
111 archOptions="$1"
112 [ $# -eq 1 ] || usage "Error: specify architecture"
116 #------------------------------------------------------------------------------
117 timeStamp=$(date +%Y-%m-%d)
118 packBase=${packDir}.Make-${archOptions}_${timeStamp}
120 # add optional output directory
121 [ -d "$outputDir" ] && packBase="$outputDir/$packBase"
122 packFile=$packBase.$packExt
124 # avoid overwriting old pack file
125 if [ -f $packFile ]
126 then
127 echo "Error: $packFile already exists" 1>&2
128 exit 1
131 cat <<INFO 1>&2
132 -------------------------------------------------------------------------------
133 Pack and compress Make/$archOptions* directories into $packFile
135 INFO
138 # bzip2 or gzip compression
139 case "$packFile" in
140 *tbz)
141 tarOpt=cpjf
144 tarOpt=cpzf
146 esac
149 # Clean up on Ctrl-C
150 trap 'rm -f $packFile 2>/dev/null' INT
152 find -H $packDir -depth -name Make -type d -print | \
153 xargs -i find '{}' -depth -name "$archOptions*" -type d -print | \
154 tar $tarOpt $packFile -T -
156 if [ $? -eq 0 ]
157 then
158 echo "Finished packing Make/$archOptions directories into $packFile" 1>&2
159 else
160 echo "Error: failure packing Make/$archOptions directories into $packFile" 1>&2
161 rm -f $packFile 2>/dev/null
164 #------------------------------------------------------------------------------