Incorrect boundary condition
[foam-extend-3.2.git] / bin / tools / foamThirdParty
blob0df42920c766824b198ab7e45644c0a5486014ee
1 #!/usr/bin/perl -w
2 use strict;
3 use File::Spec;
4 use Getopt::Long;
6 #############################################################################
7 # SETTINGS
9 my %config = (
10 thirdParty => "$ENV{WM_PROJECT_INST_DIR}/ThirdParty",
11 project => ( $ENV{WM_PROJECT} || '' ) . "-"
12 . ( $ENV{WM_PROJECT_VERSION} || '' ),
15 my %packages = (
16 cmake => {
17 -opt => 1,
18 url => "http://www.cmake.org/files/v2.6/cmake-2.6.0.tar.gz",
21 lam => {
22 -opt => 1,
23 url => "http://www.lam-mpi.org/download/files/lam-7.1.4.tar.bz2",
26 libccmio => {
27 -opt => 1,
28 url =>
29 "https://wci.llnl.gov/codes/visit/3rd_party/libccmio-2.6.1.tar.gz",
32 openmpi => {
33 url =>
34 "http://www.open-mpi.org/software/ompi/v1.2/downloads/openmpi-1.2.6.tar.bz2",
37 metis => {
38 url =>
39 "http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/metis-5.0pre2.tar.gz"
41 mico => {
42 -opt => 1,
43 url => "http://www.mico.org/mico-2.3.12.tar.gz",
46 mpich => {
47 -opt => 1,
48 url => "ftp://ftp.mcs.anl.gov/pub/mpi/old/mpich-1.2.4.tar.gz",
51 ParMetis => {
52 url =>
53 "http://glaros.dtc.umn.edu/gkhome/fetch/sw/parmetis/ParMetis-3.1.tar.gz",
56 ParMGridGen => {
57 url =>
58 "http://www-users.cs.umn.edu/~moulitsa/download/ParMGridGen-1.0.tar.gz",
61 zlib => { url => "http://www.zlib.net/zlib-1.2.3.tar.gz", },
63 hoard => {
64 -opt => 1,
65 url =>
66 "http://www.cs.umass.edu/%7Eemery/hoard/hoard-3.7.1/hoard-371.tar.gz"
69 ## # this really doesn't work well, but code needs minor patching anyhow:
70 ## fbsdmalloc => {
71 ## url =>
72 ## "http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/lib/libc/stdlib/malloc.c?rev=1.171",
74 ## },
78 # END OF SETTINGS
79 ############################################################################
81 ( my $Script = $0 ) =~ s{^.*/}{};
83 # --------------------------------------------------------------------------
84 sub usage {
85 my ( @req, @opt );
87 for ( sort keys %packages ) {
88 if ( $packages{$_}{-opt} ) {
89 push @opt, $_;
91 else {
92 push @req, $_;
96 $! = 0; # clean exit
97 warn "@_\n" if @_;
98 die <<"USAGE";
99 usage:
100 $Script [OPTION] [package1 .. packageN]
102 options:
103 -help usage
104 -status show status [default]
105 -list list versions and resource locations
106 -version list versions only
107 -dir list unpack directory
108 -reldir list unpack directory relative to cwd
109 -get get packages as required (uses curl)
110 -unpack unpack packages where required and possible
112 Simple management of 3rd party software for '$config{project}'
113 using the directory
114 $config{thirdParty}
116 Packages: @req
117 Optional: @opt
119 Return codes:
120 -status -get -unpack number of missing packages or errors
122 USAGE
125 # --------------------------------------------------------------------------
126 my %opt;
128 # default action is -status
129 @ARGV or $opt{status}++;
130 GetOptions(
131 \%opt, ##
132 "help", "status", "list", "version", "dir",
133 "reldir", "get", "unpack",
135 or usage;
137 $opt{help} and usage;
139 -d $config{thirdParty} or usage "ERROR: no '$config{thirdParty}' dir";
142 # complete the config
144 if ( not exists $config{sources} ) {
145 $config{sources} = "$config{thirdParty}/sources";
146 -d $config{sources} or mkdir $config{sources};
150 # cleanup the packages table
152 for my $name ( keys %packages ) {
153 my $href = $packages{$name};
155 if ( not $href->{url} ) {
156 warn "$name without url\n";
157 delete $packages{$name};
158 next;
161 if ( not exists $href->{file} ) {
162 ( $href->{file} = $href->{url} ) =~ s{^.*/|\?.*$}{}g;
165 if ( not exists $href->{dir} ) {
166 ( $href->{dir} = $href->{file} ) =~ s{\.(zip|tar(\.(gz|bz2))?)$}{};
171 # check for names in the packages
173 sub selectNames {
174 my @names;
175 my $req;
177 while ( @_ and $_[0] =~ /^-/ ) {
178 my $opt = shift;
179 if ( $opt =~ /^-req/ ) {
180 $req++;
184 if (@_) {
185 my ( %seen, @reject );
186 for my $name (@_) {
187 next if $seen{$name}++;
188 if ( exists $packages{$name} ) {
189 push @names, $name;
191 else {
192 push @reject, $name;
196 usage "unknown package(s): @reject" if @reject;
198 else {
199 @names =
200 grep { not $req or not $packages{$_}{-opt} } sort keys %packages;
203 @names or usage "no packages";
205 return @names;
209 # list the current status
211 if ( $opt{status} ) {
212 my @names = selectNames @ARGV;
214 my $nMissing = 0;
216 for my $name (@names) {
217 my $href = $packages{$name};
218 my ( $dir, $file, $url ) = @$href{qw( dir file url )};
220 my @status;
221 if ( -e "$config{sources}/$file" ) {
222 push @status, " packed: $config{sources}/$file";
225 if ( -d "$config{thirdParty}/$dir" ) {
226 push @status, "unpacked: $config{thirdParty}/$dir";
229 unless (@status) {
230 $nMissing++;
231 @status = "missing";
234 for (@status) {
235 printf "%-16s %-16s %s", $name, $dir, $_;
237 if ( $href->{-opt} ) {
238 print " [optional]";
240 print "\n";
244 exit $nMissing;
248 # show an overview of the versions and the resource locations
250 if ( $opt{list} ) {
251 my @names = selectNames @ARGV;
253 for my $name (@names) {
254 my $href = $packages{$name};
255 my ( $dir, $file, $url ) = @$href{qw( dir file url )};
257 printf "%-16s %-16s %s", $name, $dir, $url;
258 if ( $href->{-opt} ) {
259 print " [optional]";
261 print "\n";
265 exit 0;
269 # show the version (directory name) only
271 if ( $opt{version} ) {
272 my @names = selectNames @ARGV;
274 for my $name (@names) {
275 my $href = $packages{$name};
276 my ( $dir, $file, $url ) = @$href{qw( dir file url )};
278 print $dir, "\n";
281 exit 0;
285 # show the unpack directory name
287 if ( $opt{dir} or $opt{reldir} ) {
288 my @names = selectNames @ARGV;
289 my $base = $config{thirdParty};
291 if ( $opt{reldir} ) {
292 $base = File::Spec->abs2rel($base);
293 length $base or $base = '.';
296 for my $name (@names) {
297 my $href = $packages{$name};
298 my ( $dir, $file, $url ) = @$href{qw( dir file url )};
300 print File::Spec->catfile( $base, $dir ), "\n";
303 exit 0;
307 # get and/or unpack packages as required and possible
308 # avoid getting/unpacking optional packages
310 if ( $opt{get} or $opt{unpack} ) {
311 my @names = selectNames -required => @ARGV;
313 my $nError = 0;
315 for my $name (@names) {
316 my $href = $packages{$name};
317 my ( $dir, $file, $url ) = @$href{qw( dir file url )};
319 my $flags = "";
320 if ( $href->{-opt} ) {
321 $flags .= "[optional]";
324 warn '-' x 70, "\n", "$name ($dir) $flags\n";
326 if ( -d "$config{thirdParty}/$dir" ) {
327 warn "unpacked: $config{thirdParty}/$dir\n";
328 next;
331 if ( $opt{get} ) {
332 if ( -e "$config{sources}/$file" ) {
333 warn " packed: $config{sources}/$file\n";
335 else {
336 my $fetch = "curl -k -o $file";
338 # curl seems to hang on anonymous ftp?
339 if ( $url =~ /^ftp:/ ) {
340 $fetch = "wget -v";
343 system "set -x; cd $config{sources} && $fetch $url";
345 if ( not -e "$config{sources}/$file" ) {
346 $nError++;
347 warn " download failed!?\n";
348 next;
353 if ( $opt{unpack} ) {
354 if ( -e "$config{sources}/$file" ) {
355 my $unpack;
356 if ( $file =~ m{\.zip$} ) {
357 $unpack = "unzip";
359 elsif ( $file =~ m{\.tar$} ) {
360 $unpack = "tar -xf";
362 elsif ( $file =~ m{\.tar\.bz2$} ) {
363 $unpack = "tar -xjf";
365 elsif ( $file =~ m{\.(tgz|tar\.gz)$} ) {
366 $unpack = "tar -xzf";
368 else {
369 $nError++;
370 warn " no unpack defined for $file\n";
371 next;
374 system
375 "set -x; cd $config{thirdParty} && $unpack $config{sources}/$file";
377 # catch isolated cases where it unpacks without a version number
378 if ( -d "$config{thirdParty}/$name"
379 and not -d "$config{thirdParty}/$dir" )
381 rename "$config{thirdParty}/$name",
382 "$config{thirdParty}/$dir";
385 unless ( -d "$config{thirdParty}/$dir" ) {
386 $nError++;
387 warn "unpack failed!?\n";
388 next;
394 warn '-' x 70, "\n\n";
395 exit $nError;
398 # --------------------------------------------------------------------------