xref: /aoo42x/main/odk/configure.pl (revision a373f03e)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22#
23# configure.pl - a perl script to set a minimal environment for the SDK.
24#
25# Copyright 2000, 2010 Oracle and/or its affiliates.
26#
27
28use IO::File;
29use File::Basename;
30
31$main::hostname= $ARGV[0];
32$main::sdkpath= $ARGV[1];
33$main::OO_SDK_NAME= $ARGV[2];
34
35$main::OO_MAJORVERSION=$main::OO_SDK_NAME;
36$main::OO_MINORVERSION=$main::OO_SDK_NAME;
37$main::OO_MAJORVERSION =~ s#[^\d]+(\d).(\d).+#$1#go;
38$main::OO_MINORVERSION =~ s#[^\d]+(\d).(\d).+#$2#go;
39
40$main::OO_SDK_CONFIG_HOME= "$ENV{HOME}/$main::OO_SDK_NAME";
41
42$main::operatingSystem = `$main::sdkpath/config.guess | cut -d"-" -f3,4`;
43chomp ($main::operatingSystem);
44
45$main::OO_SDK_HOME = $main::sdkpath;
46$main::OO_SDK_HOME_SUGGESTION = $main::sdkpath;
47
48$main::OFFICE_HOME = "";
49
50#$main::OFFICE_BASE_HOME = substr($main::sdkpath, 0, rindex($main::sdkpath, "/sdk"));
51
52$main::OO_SDK_MAKE_HOME = "";
53$main::makeName = "make";
54if ( $main::operatingSystem =~ m/solaris/ ||
55	 $main::operatingSystem =~ m/freebsd/ )
56{
57	$main::makeName = "gmake";
58}
59$main::OO_SDK_MAKE_HOME_SUGGESTION = searchprog($main::makeName);
60$main::makeVersion = "3.79.1";
61$main::correctVersion = 0;
62
63$main::OO_SDK_ZIP_HOME = "";
64$main::OO_SDK_ZIP_HOME_SUGGESTION = searchprog("zip");
65$main::zipVersion = "2.3";
66
67$main::OO_SDK_CAT_HOME = "";
68$main::OO_SDK_CAT_HOME_SUGGESTION = searchprog("cat");
69# TODO cat version
70# $main::catVersion = "";
71
72$main::OO_SDK_SED_HOME = "";
73$main::OO_SDK_SED_HOME_SUGGESTION = searchprog("sed");
74# TODO sed version
75# $main::sedVersion = "";
76
77$main::OO_SDK_CPP_HOME = "";
78$main::cppName = "gcc";
79$main::cppVersion = "4.0.1";
80if ( $main::operatingSystem =~ m/solaris/ )
81{
82	$main::cppName = "CC";
83	$main::cppVersion = "5.2";
84}
85if ( $main::operatingSystem =~ m/darwin/ )
86{
87	$main::cppName = "clang";
88	$main::cppVersion = "4.2";
89}
90$main::OO_SDK_CC_55_OR_HIGHER = "";
91if ( $main::operatingSystem =~ m/darwin/ )
92{
93	$clangpath = `xcrun -f clang++`;
94	$main::OO_SDK_CPP_HOME_SUGGESTION = substr($clangpath, 0, rindex($clangpath, "/"));
95} else {
96	$main::OO_SDK_CPP_HOME_SUGGESTION = searchprog($main::cppName);
97}
98
99$main::OO_SDK_JAVA_HOME = "";
100$main::OO_SDK_JAVA_BIN_DIR = "bin";
101if ( $main::operatingSystem =~ m/darwin/ )
102{
103	$main::OO_SDK_JAVA_BIN_DIR="Commands";
104}
105$main::OO_SDK_JAVA_HOME_SUGGESTION = searchprog("javac");
106$main::javaVersion = "1.5.0_01";
107
108$main::OO_SDK_BOOST_HOME_SUGGESTION = "";
109$main::boostVersion = "1.48.0";
110$main::skipBoostDir = 0;
111
112$main::SDK_AUTO_DEPLOYMENT = "";
113$main::SDK_AUTO_DEPLOYMENT_SUGGESTION = "YES";
114
115$main::OO_SDK_OUTPUT_DIR_SUGGESTION = "$ENV{HOME}";
116$main::OO_SDK_OUTPUT_DIR = "";
117$main::skipOutputDir = 0;
118
119$main::return = 0;
120
121if ( $main::operatingSystem =~ m/darwin/ )
122{
123# used for a SDK as part of the office installation
124#    $main::OFFICE_HOME = `cd $main::sdkpath/../../.. && pwd`;
125#    chomp($main::OFFICE_HOME);
126#    print " Used Office = $main::OFFICE_HOME\n";
127	print " Used SDK = $main::OO_SDK_HOME\n\n";
128
129	$main::OFFICE_HOME_SUGGESTION = searchMacOffice();
130	while ( (! -d "$main::OFFICE_HOME" ) ||
131		((-d "$main::OFFICE_HOME") && (! -d "$main::OFFICE_HOME/Contents/MacOS")) )
132	{
133	print " Enter the Office installation directory [$main::OFFICE_HOME_SUGGESTION]: ";
134	$main::OFFICE_HOME = readStdIn();
135	chop($main::OFFICE_HOME);
136	if ( $main::OFFICE_HOME eq "" )
137	{
138		$main::OFFICE_HOME = $main::OFFICE_HOME_SUGGESTION;
139	}
140
141	if ( ! -d "$main::OFFICE_HOME" )
142	{
143		$main::OFFICE_HOME = "";
144		print " Error: An office installation is required, please specify the path to a valid installation.\n";
145	}
146
147#	$main::OFFICE_BASE_HOME = "$main::OFFICE_HOME/Contents";
148	}
149} else
150{
151	$main::OFFICE_HOME_SUGGESTION = searchoffice();
152
153	if ( $main::OFFICE_HOME_SUGGESTION eq "" ) {
154	# prepare Office path
155	$main::OFFICE_HOME_SUGGESTION = searchprog("soffice");
156	}
157
158	if ( ! $main::OFFICE_HOME_SUGGESTION eq "" )
159	{
160	my $tmpOffice = readlink "$main::OFFICE_HOME_SUGGESTION/soffice";
161
162	if ( $tmpOffice eq "" )
163	{
164		$tmpOffice = "$main::OFFICE_HOME_SUGGESTION/soffice";
165	}
166
167	my $offset = rindex($tmpOffice, "/program/soffice");
168	if ( $offset != -1 )
169	{
170		$main::OFFICE_HOME_SUGGESTION = substr($tmpOffice, 0, $offset);
171	} else
172	{
173		$offset = rindex($tmpOffice, "/soffice");
174		if ( $offset != -1 )
175		{
176		$main::OFFICE_HOME_SUGGESTION = substr($tmpOffice, 0, $offset);
177		} else
178		{
179		$main::OFFICE_HOME_SUGGESTION = "";
180		}
181	}
182	}
183
184	while ( (! -d "$main::OFFICE_HOME" ) ||
185		((-d "$main::OFFICE_HOME") && (! -d "$main::OFFICE_HOME/program")) )
186	{
187	print " Enter the Office installation directory [$main::OFFICE_HOME_SUGGESTION]: ";
188	$main::OFFICE_HOME = readStdIn();
189	chop($main::OFFICE_HOME);
190	if ( $main::OFFICE_HOME eq "" )
191	{
192		$main::OFFICE_HOME = $main::OFFICE_HOME_SUGGESTION;
193	}
194
195	if ( ! -d "$main::OFFICE_HOME" )
196	{
197		$main::OFFICE_HOME = "";
198		print " Error: An office installation is required, please specify the path to a valid installation.\n";
199	} else
200	{
201		# special work for a network installation, no program directory but a link to the soffice binary
202		if ( (! -d "$main::OFFICE_HOME/program") && (-e "$main::OFFICE_HOME/soffice") )
203		{
204		my $soserver = `ls -l $OFFICE_HOME_SUGGESTION/soffice | sed -n 's/.* -> //p'`;
205		$soserver= substr($soserver, 0, rindex($soserver, "program") - 1);
206
207		if ( ! -d $soserver )
208		{
209			$main::OFFICE_HOME = "";
210			print " Error: An office installation is required, please specify the path to a valid installation.\n";
211		} else
212		{
213			$main::OFFICE_HOME = $soserver;
214		}
215		}
216	}
217	}
218}
219
220
221# prepare GNU make path
222while ( (!$main::correctVersion) &&
223		((! -d "$main::OO_SDK_MAKE_HOME" ) ||
224		 ((-d "$main::OO_SDK_MAKE_HOME") && (! -e "$main::OO_SDK_MAKE_HOME/$main::makeName"))) )
225{
226	print " Enter GNU make ($main::makeVersion or higher) tools directory [$main::OO_SDK_MAKE_HOME_SUGGESTION]: ";
227	$main::OO_SDK_MAKE_HOME = readStdIn();
228	chop($main::OO_SDK_MAKE_HOME);
229	if ( $main::OO_SDK_MAKE_HOME eq "" )
230	{
231		$main::OO_SDK_MAKE_HOME = $main::OO_SDK_MAKE_HOME_SUGGESTION;
232	}
233	if ( (! -d "$main::OO_SDK_MAKE_HOME") ||
234		 ((-d "$main::OO_SDK_MAKE_HOME") && (! -e "$main::OO_SDK_MAKE_HOME/$main::makeName")) )
235	{
236		$main::OO_SDK_MAKE_HOME = "";
237		print " Error: GNU make is required, please specify a GNU make tools directory.\n";
238	} else
239	{
240		#check version
241		my $testVersion = `$OO_SDK_MAKE_HOME/$main::makeName --version`;
242		if ( $testVersion eq "")
243		{
244			print " Set the environment variable OO_SDK_MAKE_HOME to your GNU build tools directory.\n";
245			print " GNU make version $main::makeVersion can be obtained at ftp://ftp.gnu.org/gnu/make/\n";
246		} else
247		{
248			if ($testVersion =~ m#((\d+\.)+\d+)# )
249			{
250				$testVersion = $1;
251			}
252			$main::correctVersion = testVersion($main::makeVersion, $testVersion, "$main::OO_SDK_MAKE_HOME/$main::makeName", 1);
253			if ( !$main::correctVersion )
254			{
255				print " The '$main::makeName' command found at '$main::OO_SDK_MAKE_HOME' has a wrong version\n";
256				$main::OO_SDK_MAKE_HOME = "";
257			}
258		}
259	}
260}
261
262# prepare zip path
263$main::correctVersion = 0;
264while ( (!$main::correctVersion) &&
265		((! -d "$main::OO_SDK_ZIP_HOME" ) ||
266		 ((-d "$main::OO_SDK_ZIP_HOME") && (! -e "$main::OO_SDK_ZIP_HOME/zip"))) )
267{
268	print " Enter zip ($main::zipVersion or higher) tool directory [$main::OO_SDK_ZIP_HOME_SUGGESTION]: ";
269	$main::OO_SDK_ZIP_HOME = readStdIn();
270	chop($main::OO_SDK_ZIP_HOME);
271	if ( $main::OO_SDK_ZIP_HOME eq "" )
272	{
273		$main::OO_SDK_ZIP_HOME = $main::OO_SDK_ZIP_HOME_SUGGESTION;
274	}
275	if ( (! -d "$main::OO_SDK_ZIP_HOME") ||
276		 ((-d "$main::OO_SDK_ZIP_HOME") && (! -e "$main::OO_SDK_ZIP_HOME/zip")) )
277	{
278		$main::OO_SDK_ZIP_HOME = "";
279		print " Error: zip tool is required, please specify a zip tool directory.\n";
280	} else
281	{
282		#check version
283		my $testVersion = `$OO_SDK_ZIP_HOME/zip -h 2>&1 | grep -E Zip | head -n 1`;
284		$testVersion =~ s#Zip ([\d.]+) .*#$1#go;
285		if ( $testVersion eq "")
286		{
287			print " Set the environment variable OO_SDK_ZIP_HOME to your zip tool directory.\n";
288			print " zip version $main::zipVersion can be obtained at ftp://www.info-zip.org/\n";
289		} else
290		{
291			if ($testVersion =~ m#((\d+\.)+\d+)# )
292			{
293				$testVersion = $1;
294			}
295			$main::correctVersion = testVersion($main::zipVersion, $testVersion, "$main::OO_SDK_MAKE_HOME/zip", 1);
296			if ( !$main::correctVersion )
297			{
298				print " The 'zip' command found at '$main::OO_SDK_ZIP_HOME' has a wrong version\n";
299				$main::OO_SDK_ZIP_HOME = "";
300			}
301		}
302	}
303}
304
305# prepare cat path
306$main::correctVersion = 0;
307while ( (!$main::correctVersion) &&
308		((! -d "$main::OO_SDK_CAT_HOME" ) ||
309		((-d "$main::OO_SDK_CAT_HOME") && (! -e "$main::OO_SDK_CAT_HOME/cat"))) )
310{
311	print " Enter cat tool directory [$main::OO_SDK_CAT_HOME_SUGGESTION]: ";
312	$main::OO_SDK_CAT_HOME = readStdIn();
313	chop($main::OO_SDK_CAT_HOME);
314	if ( $main::OO_SDK_CAT_HOME eq "" )
315	{
316		$main::OO_SDK_CAT_HOME = $main::OO_SDK_CAT_HOME_SUGGESTION;
317	}
318	if ( (! -d "$main::OO_SDK_CAT_HOME") ||
319		((-d "$main::OO_SDK_CAT_HOME") && (! -e "$main::OO_SDK_CAT_HOME/cat")) )
320	{
321		$main::OO_SDK_CAT_HOME = "";
322		print " Error: cat tool is required, please specify a cat tool directory.\n";
323	}
324	# else ...
325	# TODO check version
326	# NOTE: only Linux cat understands --version
327}
328
329# prepare sed path
330$main::correctVersion = 0;
331while ( (!$main::correctVersion) &&
332		((! -d "$main::OO_SDK_SED_HOME" ) ||
333		((-d "$main::OO_SDK_SED_HOME") && (! -e "$main::OO_SDK_SED_HOME/sed"))) )
334{
335	print " Enter sed tool directory [$main::OO_SDK_SED_HOME_SUGGESTION]: ";
336	$main::OO_SDK_SED_HOME = readStdIn();
337	chop($main::OO_SDK_SED_HOME);
338	if ( $main::OO_SDK_SED_HOME eq "" )
339	{
340		$main::OO_SDK_SED_HOME = $main::OO_SDK_SED_HOME_SUGGESTION;
341	}
342	if ( (! -d "$main::OO_SDK_SED_HOME") ||
343		((-d "$main::OO_SDK_SED_HOME") && (! -e "$main::OO_SDK_SED_HOME/sed")) )
344	{
345		$main::OO_SDK_SED_HOME = "";
346		print " Error: sed tool is required, please specify a sed tool directory.\n";
347	}
348	# else ...
349	# TODO check version
350	# NOTE: only Linux sed understands --version
351}
352
353# prepare C++ compiler path
354$main::correctVersion = 0;
355while ( (!$main::correctVersion) &&
356		((! -d "$main::OO_SDK_CPP_HOME" ) ||
357		 ((-d "$main::OO_SDK_CPP_HOME") && (! -e "$main::OO_SDK_CPP_HOME/$main::cpp"))) )
358{
359	print " C++ compilers where for example a language binding exist:\n";
360	print "  - Solaris, Sun WorkShop 6 update 1 C++ 5.2 2000/09/11 or higher\n";
361	print "  - Linux, GNU C++ compiler, gcc version 4.0.1 or higher\n";
362	print "  - MacOS 64bit, Apple LLVM version 4.2 (clang-425.0.28) or higher\n";
363	print "    on MacOS auto detected using xcrun -f clang'\n";
364
365	if ( $main::operatingSystem =~ m/darwin/ )
366	{
367		# xcrun is used to find the correct clang compiler, just print the result as information
368		$main::OO_SDK_CPP_HOME = $main::OO_SDK_CPP_HOME_SUGGESTION;
369		print " Used clang compiler: $main::OO_SDK_CPP_HOME\n";
370	} else
371	{
372		print " Enter the directory of the C++ compiler, the directory\n";
373		print " where the compiler is located (optional) [$main::OO_SDK_CPP_HOME_SUGGESTION]: ";
374
375		$main::OO_SDK_CPP_HOME = readStdIn();
376		chop($main::OO_SDK_CPP_HOME);
377		if ( $main::OO_SDK_CPP_HOME eq "" )
378		{
379			$main::OO_SDK_CPP_HOME = $main::OO_SDK_CPP_HOME_SUGGESTION;
380		}
381	}
382
383	if ( (!$main::operatingSystem =~ m/darwin/) && (! $main::OO_SDK_CPP_HOME eq "") )
384	{
385		if ( (! -d "$main::OO_SDK_CPP_HOME") ||
386			 ((-d "$main::OO_SDK_CPP_HOME") && (! -e "$main::OO_SDK_CPP_HOME/$main::cppName")) )
387		{
388			print " Error: Could not find directory '$main::OO_SDK_CPP_HOME'.\n";
389			if ( skipChoice("C++ compiler") == 1 )
390			{
391				$main::correctVersion = 1;
392			}
393			$main::OO_SDK_CPP_HOME = "";
394		} else
395		{
396			#check version
397			if ( $main::cppName eq "gcc" )
398			{
399				my $testVersion = `$OO_SDK_CPP_HOME/$main::cppName -dumpversion`;
400				if ( $testVersion eq "")
401				{
402					print " The '$main::cppName' command found at $main::OO_SDK_CPP_HOME/$main::cppName is not a ";
403					print " GNU compiler.\nSet the environment variable OO_SDK_CPP_HOME to your GNU build tools ";
404					print " directory.\nA GNU compiler version $main::cppVersion can be obtained at ";
405					print " ftp://ftp.gnu.org/gnu/gcc/\n";
406				} else
407				{
408					$main::correctVersion = testVersion($main::cppVersion, $testVersion, "$main::OO_SDK_CPP_HOME/$main::cppName", 1);
409					if ( !$main::correctVersion )
410					{
411						print " The '$main::cppName' command found at '$main::OO_SDK_CPP_HOME' has a wrong version\n";
412						if ( skipChoice("C++ compiler") == 1 )
413						{
414							$main::correctVersion = 1;
415						}
416
417						$main::OO_SDK_CPP_HOME = "";
418					}
419				}
420			} else
421			{
422				# for Solaris we have to check the version too
423				open(FILE, "$OO_SDK_CPP_HOME/$main::cppName -V 2>&1 |");
424				my @lines = <FILE>;
425				my $testVersion = $lines[0];
426				if ( $testVersion eq "")
427				{
428					print " The '$main::cppName' command found at $main::OO_SDK_CPP_HOME/$main::cppName is not a ";
429					print " Solaris C++ compiler.\nSet the environment variable OO_SDK_CPP_HOME to your Solaris C++ compiler directory.\n";
430				} else
431				{
432					if ($testVersion =~ m#((\d+\.)+\d+)# )
433					{
434						$testVersion = $1;
435					}
436					$main::correctVersion = testVersion($main::cppVersion, $testVersion, "$main::OO_SDK_CPP_HOME/$main::cppName", 1);
437					if ( !$main::correctVersion )
438					{
439						print " The '$main::cppName' command found at '$main::OO_SDK_CPP_HOME' has a wrong version\n";
440						if ( skipChoice("C++ compiler") == 1 )
441						{
442							$main::correctVersion = 1;
443						}
444
445						$main::OO_SDK_CPP_HOME = "";
446					} else {
447						$main::correctVersion = testVersion("5.5", $testVersion, "$main::OO_SDK_CPP_HOME/$main::cppName", 2);
448						if ( $main::correctVersion ) {
449							$main::OO_SDK_CC_55_OR_HIGHER = $testVersion;
450						}
451					}
452				}
453			}
454		}
455	} else
456	{
457		# the C++ compiler is optional
458		$main::correctVersion = 1;
459	}
460}
461
462
463# prepare Java path
464$main::correctVersion = 0;
465
466# prepare Java suggestion (cut bin or Commands directory to be in the root of the Java SDK)
467$main::offset = rindex($main::OO_SDK_JAVA_HOME_SUGGESTION, "/$main::OO_SDK_JAVA_BIN_DIR");
468if ( $main::offset != -1 )
469{
470	$main::OO_SDK_JAVA_HOME_SUGGESTION = substr($main::OO_SDK_JAVA_HOME_SUGGESTION, 0, $main::offset);
471}
472
473while ( (!$main::correctVersion) &&
474		((! -d "$main::OO_SDK_JAVA_HOME" ) ||
475		 ((-d "$main::OO_SDK_JAVA_HOME") && (! -e "$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/javac"))) )
476{
477	print " Enter Java SDK (1.5, recommendation is 1.6 or higher) installation directory (optional) [$main::OO_SDK_JAVA_HOME_SUGGESTION]: ";
478	$main::OO_SDK_JAVA_HOME = readStdIn();
479	chop($main::OO_SDK_JAVA_HOME);
480	if ( $main::OO_SDK_JAVA_HOME eq "" )
481	{
482		$main::OO_SDK_JAVA_HOME = $main::OO_SDK_JAVA_HOME_SUGGESTION;
483	}
484	if ( ! $main::OO_SDK_JAVA_HOME eq "" )
485	{
486		if ( (! -d "$main::OO_SDK_JAVA_HOME") ||
487			 ((-d "$main::OO_SDK_JAVA_HOME") && (! -e "$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/javac")) )
488		{
489			print " Error: Could not find directory '$main::OO_SDK_JAVA_HOME' or '$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/javac'.\n";
490			if ( skipChoice("JAVA SDK") == 1 )
491			{
492				$main::correctVersion = 1;
493			}
494			$main::OO_SDK_JAVA_HOME = "";
495		} else
496		{
497			#check version
498			my $testVersion = `$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/java -version 2>&1 | grep -E "java version" | head -n 1 | sed -e 's#.*version "##' | sed -e 's#".*##'`;
499			$testVersion =~ s#([^\n]+)\n#$1#go;
500
501			$main::correctVersion = testVersion($main::javaVersion, $testVersion, "$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/java", 1);
502			if ( !$main::correctVersion )
503			{
504				if ( skipChoice("JAVA SDK") == 1 )
505				{
506					$main::correctVersion = 1;
507				}
508				$main::OO_SDK_JAVA_HOME = "";
509			}
510		}
511	}else
512	{
513		# the Java SDK is optional
514		$main::correctVersion = 1;
515	}
516}
517
518# prepare boost directory (optional)
519while ( (!$main::skipBoostDir) &&
520		((! -d "$main::OO_SDK_BOOST_HOME" ) ||
521		((-d "$main::OO_SDK_BOOST_HOME") && (! -e "$main::OO_SDK_BOOST_HOME/boost/tr1/unordered_map.hpp"))) )
522{
523
524	print " Enter boost directory [$main::OO_SDK_BOOST_HOME_SUGGESTION]: ";
525	$main::OO_SDK_BOOST_HOME = readStdIn();
526	chop($main::OO_SDK_BOOST_HOME);
527	if ( $main::OO_SDK_BOOST_HOME eq "" )
528	{
529		$main::OO_SDK_BOOST_HOME = $main::OO_SDK_BOOST_HOME_SUGGESTION;
530	}
531	if ( (! -d "$main::OO_SDK_BOOST_HOME") ||
532		((-d "$main::OO_SDK_BOOST_HOME") && (! -e "$main::OO_SDK_BOOST_HOME/boost/tr1/unordered_map.hpp")) )
533	{
534		print " Error: boost couldn't be find or verified, please specify a boost directory.\n";
535		if ( skipChoice("optional output directory") == 1 )
536		{
537			$main::skipBoostDir = 1;
538		}
539		$main::OO_SDK_BOOST_HOME = "";
540	} else
541	{
542		# the boost directory is optional
543		$main::skipBoostDir = 1;
544	}
545}
546
547# prepare output directory (optional)
548while ( (!$main::skipOutputDir) &&
549		(! -d "$main::OO_SDK_OUTPUT_DIR") )
550{
551	print " Default output directory is in your HOME directory.\n";
552	print " Enter an existent directory if you prefer a different output directory (optional) [$main::OO_SDK_OUTPUT_DIR_SUGGESTION]: ";
553
554	$main::OO_SDK_OUTPUT_DIR = readStdIn();
555
556	chop($main::OO_SDK_OUTPUT_DIR);
557	if ( $main::OO_SDK_OUTPUT_DIR eq "" )
558	{
559		$main::OO_SDK_OUTPUT_DIR = $main::OO_SDK_OUTPUT_DIR_SUGGESTION;
560	}
561	if ( ! $main::OO_SDK_OUTPUT_DIR eq "" )
562	{
563		if ( ! -d "$main::OO_SDK_OUTPUT_DIR" )
564		{
565			print " Error: Could not find directory '$main::OO_SDK_OUTPUT_DIR'.\n";
566			if ( skipChoice("optional output directory") == 1 )
567			{
568				$main::skipOutputDir = 1;
569			}
570			$main::OO_SDK_OUTPUT_DIR = "";
571		}
572	} else
573	{
574		# the output directory is optional
575		$main::skipOutputDir = 1;
576	}
577}
578
579# prepare auto deployment
580while ( $main::SDK_AUTO_DEPLOYMENT eq "" ||
581	((! $main::SDK_AUTO_DEPLOYMENT eq "YES") &&
582	 (! $main::SDK_AUTO_DEPLOYMENT eq "NO")) )
583{
584	print " Automatic deployment of UNO components (YES/NO) [$main::SDK_AUTO_DEPLOYMENT_SUGGESTION]: ";
585	$main::SDK_AUTO_DEPLOYMENT = uc <STDIN>;
586	chop($main::SDK_AUTO_DEPLOYMENT);
587	if ( $main::SDK_AUTO_DEPLOYMENT eq "" )
588	{
589	$main::SDK_AUTO_DEPLOYMENT = "YES";
590	}
591}
592
593prepareScriptFile("setsdkenv_unix.sh.in", "setsdkenv_unix.sh");
594chmod 0644, "$main::OO_SDK_CONFIG_HOME/$main::hostname/setsdkenv_unix.sh";
595
596print "\n";
597print " ************************************************************************\n";
598print " * ... your SDK environment has been prepared.\n";
599print " * For each time you want to use this configured SDK environment, you\n";
600print " * have to run the \"setsdkenv_unix\" script file!\n";
601print " * Alternatively can you source one of the scripts\n";
602print " *   \"$main::OO_SDK_CONFIG_HOME/$main::hostname/setsdkenv_unix.sh\"\n";
603print " * to get an environment without starting a new shell.\n";
604print " ************************************************************************\n\n";
605
606exit $return;
607
608sub skipChoice
609{
610	my $msg = shift;
611	my $skip = "";
612	while ( !( $skip eq "yes" || $skip eq "no") )
613	{
614		print " Do you want to skip the choice of the '$msg' (YES/NO): [YES] ";
615		$skip = lc <STDIN>;
616		chop($skip);
617		if ( $skip eq "" ) { $skip = "yes"; } # default
618		if ( $skip eq "yes" )
619		{
620			return 1;
621		}
622	}
623	return 0;
624}
625
626sub resolveLink
627{
628	my $base= shift;
629	my $link= shift;
630
631	my $resolvedpath = "$base/$link";
632	my $linktarget = readlink "$resolvedpath";
633	my $resolvedlink = "";
634
635	while ( $linktarget ne "") {
636
637	if ( $linktarget =~ m/^\/.*/ )
638	{
639		$resolvedpath = "$linktarget";
640	} else {
641		$resolvedpath = `cd $base/$linktarget; pwd`;
642		chop $resolvedpath;
643	}
644	$base = dirname("$resolvedpath");
645
646	$linktarget = readlink "$resolvedpath";
647	}
648
649	$resolvedlink = `cd $resolvedpath; pwd`;
650	chop $resolvedlink;
651	return $resolvedlink;
652}
653
654sub searchprog
655{
656	my $_search= shift;
657	my $tmpPath = `echo "\$PATH"`;
658	my @pathList = split(":" , $tmpPath);
659	my $progDir = "";
660
661	if ( $_search eq "javac" )
662	{
663		if ( $main::operatingSystem =~ m/darwin/ ) {
664			$progDir = resolveLink("/System/Library/Frameworks/JavaVM.Framework/Versions", "CurrentJDK");
665
666			if ( -e "$progDir/$main::OO_SDK_JAVA_BIN_DIR/javac" )
667			{
668				return "$progDir/$main::OO_SDK_JAVA_BIN_DIR";
669			}
670		}
671
672		if ( $main::operatingSystem =~ m/solaris/ ) {
673			$progDir = resolveLink("/usr/jdk", "latest");
674			if ( -e "$progDir/$main::OO_SDK_JAVA_BIN_DIR/javac" )
675			{
676				return "$progDir/$main::OO_SDK_JAVA_BIN_DIR";
677			}
678		}
679	}
680
681	if ( $_search eq "gmake" && $main::operatingSystem =~ m/solaris/ ) {
682		if ( -e "/usr/sfw/bin/gmake" )
683		{
684			return "/usr/sfw/bin";
685		}
686	}
687
688	foreach $i (@pathList)
689	{
690		chomp ($i);
691
692		if ( -e "$i/$_search" )
693		{
694
695			if ( index($i, "/") == 0 )
696			{
697				# # absolute path; leave unchanged
698				$progDir = $i;
699			} else
700			{
701				$progDir = `cd "$i"; pwd`;
702			}
703			return $progDir
704		}
705	}
706	return $progDir
707}
708
709sub searchMacOffice
710{
711	if (-d "/Applications/OpenOffice.app" ) {
712		return "/Applications/OpenOffice.app"
713	}
714	return "";
715}
716
717sub searchoffice
718{
719	my $offset = rindex($main::sdkpath, "/openoffice");
720	my $tmpOffice = substr($main::sdkpath, 0, $offset);
721	my $officepath = "$tmpOffice/openoffice$main::OO_MAJORVERSION";
722
723#	if ( $main::OO_MINORVERSION > 0) {
724#		$officepath = "$officepath$main::OO_MINORVERSION";
725#	}
726
727	# search corresponding office for this SDK
728	if (-d $officepath && -e "$officepath/program/soffice") {
729		return $officepath;
730	}
731	return "";
732}
733
734
735
736sub testVersion
737{
738	my $tmpMustBeVersion = shift;
739	my $tmpTestVersion = shift;
740	my $toolName = shift;
741	# 1=check + message 2=check only
742	my $checkOnly = shift;
743	my @mustBeVersion = split(/\.|_|-/,$tmpMustBeVersion);
744	my @testVersion = split(/\.|_|-/,$tmpTestVersion);
745	my $length = $#mustBeVersion;
746
747	if ($#testVersion < $#mustBeVersion) {
748		$length = $#testVersion;
749	}
750
751	for ($i=0; $i <= $length; $i++ )
752	{
753		if ( @testVersion[$i] > @mustBeVersion[$i] )
754		{
755			return 1; # 1 indicates a correct version
756		}
757
758		if ( @testVersion[$i] < @mustBeVersion[$i] )
759		{
760			if ( $#checkOnly == 1 ) {
761				print " The command '$toolName' has the version $tmpTestVersion.\n";
762				print " The SDK requires at least the version $tmpMustBeVersion.\n";
763			}
764			return 0;
765		}
766	}
767
768	return 1; # 1 indicates a correct version
769}
770
771sub readStdIn
772{
773	my $tmpstdin = <STDIN>;
774	if ( index($tmpstdin, "\$") != -1)
775	{
776		return `echo $tmpstdin`;
777	}
778
779	return $tmpstdin;
780}
781
782sub prepareScriptFile()
783{
784	my $inputFile = shift;
785	my $outputFile = shift;
786
787	if ( ! -d "$main::OO_SDK_CONFIG_HOME/$main::hostname" )
788	{
789		system("mkdir -p $main::OO_SDK_CONFIG_HOME/$main::hostname");
790	}
791
792	open ( FILEIN, "$main::sdkpath/$inputFile" ) || die "\nERROR: could not open '$main::sdkpath/$inputFile' for reading";
793	open ( FILEOUT, ">$main::OO_SDK_CONFIG_HOME/$main::hostname/$outputFile" ) || die "\nERROR: could not open '$main::OO_SDK_CONFIG_HOME/$main::hostname/$outputFile' for writing";
794
795	while ( <FILEIN> )
796	{
797		$_ =~ s#\@OO_SDK_NAME\@#$main::OO_SDK_NAME#go;
798		$_ =~ s#\@OO_SDK_HOME\@#$main::OO_SDK_HOME#go;
799		$_ =~ s#\@OFFICE_HOME\@#$main::OFFICE_HOME#go;
800		$_ =~ s#\@OO_SDK_MAKE_HOME\@#$main::OO_SDK_MAKE_HOME#go;
801		$_ =~ s#\@OO_SDK_ZIP_HOME\@#$main::OO_SDK_ZIP_HOME#go;
802		$_ =~ s#\@OO_SDK_CAT_HOME\@#$main::OO_SDK_CAT_HOME#go;
803		$_ =~ s#\@OO_SDK_SED_HOME\@#$main::OO_SDK_SED_HOME#go;
804		$_ =~ s#\@OO_SDK_CPP_HOME\@#$main::OO_SDK_CPP_HOME#go;
805		$_ =~ s#\@OO_SDK_CC_55_OR_HIGHER\@#$main::OO_SDK_CC_55_OR_HIGHER#go;
806		$_ =~ s#\@OO_SDK_JAVA_HOME\@#$main::OO_SDK_JAVA_HOME#go;
807		$_ =~ s#\@OO_SDK_BOOST_HOME\@#$main::OO_SDK_BOOST_HOME#go;
808		$_ =~ s#\@SDK_AUTO_DEPLOYMENT\@#$main::SDK_AUTO_DEPLOYMENT#go;
809		$_ =~ s#\@OO_SDK_OUTPUT_DIR\@#$main::OO_SDK_OUTPUT_DIR#go;
810
811		print FILEOUT $_;
812	}
813
814	close FILEIN;
815	close FILEOUT;
816}
817