1#!/usr/bin/perl
2
3############################################################################
4# This file is part of FreeFEM.                                            #
5#                                                                          #
6# FreeFEM is free software: you can redistribute it and/or modify          #
7# it under the terms of the GNU Lesser General Public License as           #
8# published by the Free Software Foundation, either version 3 of           #
9# the License, or (at your option) any later version.                      #
10#                                                                          #
11# FreeFEM is distributed in the hope that it will be useful,               #
12# but WITHOUT ANY WARRANTY; without even the implied warranty of           #
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
14# GNU Lesser General Public License for more details.                      #
15#                                                                          #
16# You should have received a copy of the GNU Lesser General Public License #
17# along with FreeFEM. If not, see <http://www.gnu.org/licenses/>.          #
18############################################################################
19# SUMMARY : Download third-party packages independently of FF configuration
20# LICENSE : LGPLv3
21# ORG     : LJLL Universite Pierre et Marie Curie, Paris, FRANCE
22# AUTHORS : Antoine Le Hyaric
23# E-MAIL  : http://www.ljll.math.upmc.fr/lehyaric
24
25use strict;
26use Getopt::Std;
27use Digest::MD5 qw(md5_hex); # [[http://perldoc.perl.org/Digest/MD5.html]]
28
29# This download script needs to be able to work on platforms that do not have threads (eg Mingw).
30
31my $can_use_threads=eval 'use threads;use threads::shared;1';
32
33my %opts;
34getopts('afho:',\%opts);
35
36if($opts{h}){
37	print <<EOF;
38getall [options]: Download third-party packages independently of the FreeFEM configuration procedure
39
40Available options:
41
42-a = accept all licences without further user interaction
43-f = force downloads even if packages are already present locally
44-h = this help
45-o name,name,... = only download packages with the given names
46
47EOF
48	exit 0;
49}
50
51# Accumulate errors and print them all at the end of the script
52
53my $errors='';
54if($can_use_threads){share(\$errors)}
55
56# Accumulate errors and print them all at the end of the script
57
58my $errors='';
59if($can_use_threads){share(\$errors)}
60
61# list required packages
62my $only=0;
63my %packs;
64if(defined $opts{o}){
65	$only=1;
66	foreach(split(/,/,$opts{o})){$packs{$_}=1}
67}
68
69# can be run from the parent directory
70
71if(-x "3rdparty/getall"){chdir "3rdparty"}
72
73# can be run from any of the child directories
74
75if(-x "../getall"){chdir ".."}
76
77system "mkdir -p pkg";
78my @downloads;
79
80download('ARPACK','http://www.caam.rice.edu/software/ARPACK/SRC/arpack96.tar.gz',
81 	'http://www.caam.rice.edu/software/ARPACK',
82	'arpack96.tar.gz',
83	'fffaa970198b285676f4156cebc8626e');
84download('ARPACK','http://www.caam.rice.edu/software/ARPACK/SRC/patch.tar.gz',
85	'http://www.caam.rice.edu/software/ARPACK',
86	'patch.tar.gz',
87	'14830d758f195f272b8594a493501fa2');
88download('BLAS','http://www.netlib.org/blas/blas-3.7.1.tgz',
89	'http://www.netlib.org/blas',
90	'blas-3.7.1.tgz',
91	'cd132aea6f7055a49aa48ca0a61e7cd5');
92download('BLAS','http://www.netlib.org/blas/blast-forum/cblas.tgz',
93	'http://www.netlib.org/blas/blast-forum',
94	'cblas.tgz',
95	'1e8830f622d2112239a4a8a83b84209a');
96download('OpenBLAS','http://github.com/xianyi/OpenBLAS/archive/v0.3.6.tar.gz',
97	'http://www.openblas.net/',
98	'OpenBLAS.tar.gz',
99	'8a110a25b819a4b94e8a9580702b6495',
100	'BAD_CERT');
101
102# downloading the binary package is required for Windows because
103# compiling requires big amounts of RAM (more than 4GB). This is not a
104# big package so we download it in any situation just in case an
105# offline Windows compile follows.
106
107download('OpenBLAS-Win64','http://downloads.sourceforge.net/project/openblas/v0.2.14/OpenBLAS-v0.2.14-Win64-int64.zip',
108	'http://www.openblas.net/',
109	'OpenBLAS-v0.2.14-Win64-int64.zip',
110	'9f2d41076857a514b921bf0bf03b5d39');
111download('OpenBLAS-Win32','http://downloads.sourceforge.net/project/openblas/v0.2.14/OpenBLAS-v0.2.14-Win32.zip',
112	'http://www.openblas.net/',
113	'OpenBLAS-v0.2.14-Win32.zip',
114	'eefdf170439620d78fabb3139b7aeb2f');
115
116download('FFTW','http://www.fftw.org/fftw-3.3.8.tar.gz',
117	'http://www.fftw.org',
118	'fftw-3.3.8.tar.gz','8aac833c943d8e90d51b697b27d4384d');
119# 3.3.2	'6977ee770ed68c85698c7168ffa6e178');
120download('freeYams','https://www.ljll.math.upmc.fr/frey/ftp/archives/freeyams.2012.02.05.tgz',
121	'https://www.ljll.math.upmc.fr/frey/software.html',
122	'freeyams.2012.02.05.tgz',
123	'b7c82a256a3e59beeb2b578de93a4e0b');
124download('Gmm++','http://download.gna.org/getfem/stable/gmm-4.2.tar.gz',
125	'http://download.gna.org/getfem/html/homepage/download.html',
126	'gmm-4.2.tar.gz',
127	'35fe900f7459c49f4b4337dc691c8cdf');
128download('Ipopt','http://www.coin-or.org/download/source/Ipopt/Ipopt-3.12.4.tgz',
129	'https://projects.coin-or.org/Ipopt',
130	'Ipopt-3.12.4.tgz',
131	'12a8ecaff8dd90025ddea6c65b49cb03');
132download('METIS','http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/metis-5.1.0.tar.gz',
133	'http://www.netlib.org/linalg/',
134	'metis-5.1.0.tar.gz',
135	'5465e67079419a69e0116de24fce58fe');
136download('ParMETIS','http://glaros.dtc.umn.edu/gkhome/fetch/sw/parmetis/parmetis-4.0.3.tar.gz',
137	'http://glaros.dtc.umn.edu/gkhome/fetch/sw/parmetis/',
138	'ParMetis-4.0.3.tar.gz',
139	'f69c479586bf6bb7aff6a9bc0c739628');
140download('MMG3D','http://www.math.u-bordeaux1.fr/~dobrzyns/logiciels/download/mmg3d4.0.tgz',
141	'http://www.math.u-bordeaux1.fr/~dobrzyns/logiciels/mmg3d.php',
142	'mmg3d4.0.tgz',
143	'bfc2b0373bc208e0512415d1aa2e76a1');
144download('mshmet','https://www.ljll.math.upmc.fr/frey/ftp/archives/mshmet.2012.04.25.tgz',
145	'https://www.ljll.math.upmc.fr/frey/software.html',
146	'mshmet.2012.04.25.tgz',
147	'427f397e0602efc56aa897d38a8e9bfa');
148download('MUMPS','http://mumps.enseeiht.fr/MUMPS_5.0.2.tar.gz',
149	'http://mumps.enseeiht.fr/',
150	'MUMPS_5.0.2.tar.gz',
151	'591bcb2c205dcb0283872608cdf04927');
152download('NLopt','http://ab-initio.mit.edu/nlopt/nlopt-2.2.4.tar.gz',
153	'http://ab-initio.mit.edu/wiki/index.php/NLopt',
154	'nlopt-2.2.4.tar.gz',
155	'9c60c6380a10c6d2a06895f0e8756d4f');
156download('ScaLAPACK','http://www.netlib.org/scalapack/scalapack-2.0.2.tgz',
157	'http://www.netlib.org/scalapack/',
158	'scalapack-2.0.2.tgz',
159	'2f75e600a2ba155ed9ce974a1c4b536f');
160download('Scotch','https://gforge.inria.fr/frs/download.php/file/34618/scotch_6.0.4.tar.gz',
161	'https://gforge.inria.fr/projects/scotch/',
162	'scotch_6.0.4.tar.gz',
163	'd58b825eb95e1db77efe8c6ff42d329f',
164	'BAD_CERT'); # web certificate from gforge.inria.fr is rejected
165download('SuiteSparse','http://faculty.cse.tamu.edu/davis/SuiteSparse/SuiteSparse-4.4.4.tar.gz',
166	'http://faculty.cse.tamu.edu/davis/SuiteSparse/',
167	'SuiteSparse-4.4.4.tar.gz',
168	'e0af74476935c9ff6d971df8bb6b82fc') ;
169download('SuperLU','http://crd-legacy.lbl.gov/~xiaoye/SuperLU/superlu_5.2.1.tar.gz',
170	'http://crd-legacy.lbl.gov/~xiaoye/SuperLU/',
171	'superlu_5.2.1.tar.gz',
172	'3a1a9bff20cb06b7d97c46d337504447');
173download('TetGen','http://www.tetgen.org/1.5/src/tetgen1.5.1-beta1.tar.gz',
174	'http://www.tetgen.org/1.5/src/',
175	'tetgen1.5.1-beta1.tar.gz',
176	'3d55c197bcbfc611b7ced6f343643756');
177download('mmg','https://github.com/MmgTools/mmg/archive/cb8dfe0f6794ae839f415d7753fc97fc62858d78.zip',
178        'https://github.com/MmgTools',
179        'mmg.zip',
180        'cf56025ee05721795d4bc4e610cb2019');
181download('parmmg','https://github.com/MmgTools/ParMmg/archive/ca99325cd238bcd7a3ce5344ae3331e85594ed84.zip',
182        'https://github.com/MmgTools',
183        'parmmg.zip',
184        '6949a48720ffa8fae9d676fe68dd77c9');
185download('PETSc','http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-3.13.0.tar.gz',
186	'http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/',
187	'petsc-lite-3.13.0.tar.gz',
188	'8ea59cc9e329611d73eb1be56cc32fda');
189
190download('htool','https://github.com/PierreMarchand20/htool/archive/0ba76eaca05217fceabf3f0269548b354590eef3.zip',
191		'https://github.com/PierreMarchand20/',
192		'htool.zip',
193		'1fc76ca089bb76f668a935d0d3678bf9');
194
195
196download('hpddm','https://github.com/hpddm/hpddm/archive/e8639ff91fe0a5d462a62e8764355d7d5cd40de3.zip',
197	'https://github.com/hpddm',
198	'hpddm.zip',
199	'095f8d0c2f93982290b23cf04ef03d38');
200
201download('bemtool','https://github.com/PierreMarchand20/BemTool/archive/9e139de60fe27d46936b5e8a7d2e9f0de8fce460.zip',
202	'https://github.com/PierreMarchand20/BemTool',
203	'bemtool.zip',
204	'c21a79bd66b58025bd5a0a0012fbd444');
205
206download('Boost','https://www.ljll.math.upmc.fr/~tournier/boost_for_bemtool.tar.gz',
207	'https://www.boost.org',
208	'boost_for_bemtool.tar.gz',
209	'bb0e3ee1ad06174c80a69bc0756034e7');
210
211
212
213
214# run all downloads concurrently
215
216if($can_use_threads){
217	my @threads;
218	foreach(@downloads){push @threads,threads->create(\&downloadone,$_)}
219	foreach(@threads){$_->join()}
220}
221else{
222	foreach(@downloads){downloadone($_)}
223}
224
225if($errors ne ''){
226	print "\n$errors";
227	exit 1;
228}
229
230sub download{
231	my($title,$url,$lic,$pkg,$md5,$opts)=@_;
232
233	# skip packages that have not been requested explicitely
234	return if($only && !defined $packs{$title});
235
236	# skip packages that are already present
237	if(-f "pkg/$pkg" && !$opts{f}){
238		my $md5check=md5_hex(`cat pkg/$pkg`);
239		if( ( $md5 eq "none") || ($md5check eq $md5)){
240			print "$title $pkg done\n";
241			return;
242		}
243		else {
244			print "$title $pkg  md5 change => reget \n";
245		}
246	}
247
248	# we do not store the answers to these questions. To repeat the same downloads without manual input, options "-a" and
249	# "-o names" are provided.
250
251	if(!$opts{a}){
252		print "$title: please check the licence at $lic. Do you want to download $url? (yN)\n";
253		my $ans=uc <STDIN>;
254		chomp $ans;
255		return if $ans ne 'Y';
256	}
257
258	# uses [[file:../bin/build/download]]
259	push @downloads,"$url,$pkg,$md5,$opts";
260}
261
262sub downloadone{
263	##  correct rescue server for done load
264	my($url,$pkg,$md5,$opts)=split(/,/,$_[0]);# warning just $pkg without pkg/$pkg
265	my $cmd="../bin/build/download $url pkg/$pkg $opts";
266	print "$cmd\n";
267	system $cmd;
268	if($?){
269		print "Download failed from $url of $pkg\n";
270		my $url="http://pkgs.freefem.org/$pkg";
271		my $cmd="../bin/build/download $url pkg/$pkg $opts";
272		print "Try other site: $url\n";
273		system $cmd;
274		if($?){
275			print "Download 2 times failed from $url of $pkg\n";
276			my $url="http://104.46.50.187/pkg/$pkg";
277			my $cmd="../bin/build/download $url pkg/$pkg $opts";
278			print "Try (2 times)  other site: $url\n";
279			system $cmd;
280			if ($?){
281				$errors.="ERROR: $cmd FAILED\n"
282			}
283		}
284
285	}
286	# check if resulting package contents are valid
287	my $md5check=md5_hex(`cat pkg/$pkg`);
288	if( ( $md5 ne "none") && ($md5check ne $md5)){
289		print "Download failed (MD5 check) from $url of $pkg\n";
290		my $url="http://pkgs.freefem.org/$pkg";
291		my $cmd="../bin/build/download $url pkg/$pkg $opts";
292		print "Try other site: $url\n";
293		system $cmd;
294		if($?){
295			$errors.="ERROR 2: $cmd FAILED\n"
296		}
297		else { $md5check=md5_hex(`cat pkg/$pkg`);}
298		if(  ($md5check ne $md5))
299		{
300		  $errors.="ERROR2: INVALID MD5 for $pkg  $md5check\n"}
301	    }
302}
303