Branch libreoffice-5-0-4
[LibreOffice.git] / odk / config / configure.pl
blobc0f3188a4274aa2be08df26dd3f19d251b9e86aa
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 # configure.pl - a perl script to set a minimal environment for the SDK.
20 # Copyright 2000, 2010 Oracle and/or its affiliates.
23 use IO::File;
24 use File::Basename;
26 $main::hostname= $ARGV[0];
27 $main::sdkpath= $ARGV[1];
28 $main::OO_SDK_NAME= $ARGV[2];
30 $main::OO_MAJORVERSION=$main::OO_SDK_NAME;
31 $main::OO_MINORVERSION=$main::OO_SDK_NAME;
32 $main::OO_MAJORVERSION =~ s#[^\d]+(\d).(\d).+#$1#go;
33 $main::OO_MINORVERSION =~ s#[^\d]+(\d).(\d).+#$2#go;
35 $main::OO_SDK_CONFIG_HOME= "$ENV{HOME}/$main::OO_SDK_NAME";
37 $main::operatingSystem = `/bin/sh $main::sdkpath/config.guess | cut -d"-" -f3,4`;
38 chomp ($main::operatingSystem);
40 $main::OO_SDK_HOME = $main::sdkpath;
41 #$main::OO_SDK_HOME = "";
42 $main::OO_SDK_HOME_SUGGESTION = $main::sdkpath;
44 $main::OFFICE_HOME = "";
46 $main::OO_SDK_MAKE_HOME = "";
47 $main::makeName = "make";
48 if ( $main::operatingSystem =~ m/solaris/ ||
49 $main::operatingSystem =~ m/freebsd/ )
51 $main::makeName = "gmake";
53 $main::OO_SDK_MAKE_HOME_SUGGESTION = searchprog($main::makeName);
54 $main::makeVersion = "3.79.1";
55 $main::correctVersion = 0;
57 $main::OO_SDK_ZIP_HOME = "";
58 $main::OO_SDK_ZIP_HOME_SUGGESTION = searchprog("zip");
59 $main::zipVersion = "2.3";
61 $main::OO_SDK_CAT_HOME = "";
62 $main::OO_SDK_CAT_HOME_SUGGESTION = searchprog("cat");
63 # TODO cat version
64 # $main::catVersion = "";
66 $main::OO_SDK_SED_HOME = "";
67 $main::OO_SDK_SED_HOME_SUGGESTION = searchprog("sed");
68 # TODO sed version
69 # $main::sedVersion = "";
71 $main::OO_SDK_CPP_HOME = "";
72 $main::cppName = "gcc";
73 $main::cppVersion = "4.0.1";
74 $main::OO_SDK_CPP_HOME_SUGGESTION = searchprog($main::cppName);
76 $main::OO_SDK_JAVA_HOME = "";
77 $main::OO_SDK_JAVA_BIN_DIR = "bin";
78 if ( $main::operatingSystem =~ m/darwin/ )
80 $main::OO_SDK_JAVA_BIN_DIR="Commands";
82 $main::OO_SDK_JAVA_HOME_SUGGESTION = searchprog("javac");
83 $main::javaVersion = "1.5.0_01";
85 $main::SDK_AUTO_DEPLOYMENT = "";
86 $main::SDK_AUTO_DEPLOYMENT_SUGGESTION = "YES";
88 $main::OO_SDK_OUTPUT_DIR_SUGGESTION = "$ENV{HOME}";
89 $main::OO_SDK_OUTPUT_DIR = "";
90 $main::skipOutputDir = 0;
92 $main::return = 0;
94 if ( $main::operatingSystem =~ m/darwin/ )
96 print " Used SDK = $main::OO_SDK_HOME\n\n";
98 $main::OFFICE_HOME_SUGGESTION = searchMacOffice();
99 while ( (! -d "$main::OFFICE_HOME" ) ||
100 ((-d "$main::OFFICE_HOME") && (! -d "$main::OFFICE_HOME/Contents/MacOS")) )
102 print " Enter the Office installation directory [$main::OFFICE_HOME_SUGGESTION]: ";
103 $main::OFFICE_HOME = readStdIn();
104 chop($main::OFFICE_HOME);
105 if ( $main::OFFICE_HOME eq "" )
107 $main::OFFICE_HOME = $main::OFFICE_HOME_SUGGESTION;
110 if ( ! -d "$main::OFFICE_HOME" )
112 $main::OFFICE_HOME = "";
113 print " Error: An office installation is required, please specify the path to a valid installation.\n";
117 } else
119 $main::OFFICE_HOME_SUGGESTION = searchoffice();
121 if ( $main::OFFICE_HOME_SUGGESTION eq "" ) {
122 # prepare Office path
123 $main::OFFICE_HOME_SUGGESTION = searchprog("soffice");
126 if ( ! $main::OFFICE_HOME_SUGGESTION eq "" )
128 my $tmpOffice = readlink "$main::OFFICE_HOME_SUGGESTION/soffice";
130 if ( $tmpOffice eq "" )
132 $tmpOffice = "$main::OFFICE_HOME_SUGGESTION/soffice";
135 my $offset = rindex($tmpOffice, "/program/soffice");
136 if ( $offset != -1 )
138 $main::OFFICE_HOME_SUGGESTION = substr($tmpOffice, 0, $offset);
139 } else
141 $offset = rindex($tmpOffice, "/soffice");
142 if ( $offset != -1 )
144 $main::OFFICE_HOME_SUGGESTION = substr($tmpOffice, 0, $offset);
145 } else
147 $main::OFFICE_HOME_SUGGESTION = "";
152 while ( (! -d "$main::OFFICE_HOME" ) ||
153 ((-d "$main::OFFICE_HOME") && (! -d "$main::OFFICE_HOME/program")) )
155 print " Enter the Office installation directory [$main::OFFICE_HOME_SUGGESTION]: ";
156 $main::OFFICE_HOME = readStdIn();
157 chop($main::OFFICE_HOME);
158 if ( $main::OFFICE_HOME eq "" )
160 $main::OFFICE_HOME = $main::OFFICE_HOME_SUGGESTION;
163 if ( ! -d "$main::OFFICE_HOME" )
165 $main::OFFICE_HOME = "";
166 print " Error: An office installation is required, please specify the path to a valid installation.\n";
167 } else
169 # special work for a network installation, no prgram directory but a link to the soffice binary
170 if ( (! -d "$main::OFFICE_HOME/program") && (-e "$main::OFFICE_HOME/soffice") )
172 my $soserver = `ls -l $OFFICE_HOME_SUGGESTION/soffice | sed -n 's/.* -> //p'`;
173 $soserver= substr($soserver, 0, rindex($soserver, "program") - 1);
175 if ( ! -d $soserver )
177 $main::OFFICE_HOME = "";
178 print " Error: An office installation is required, please specify the path to a valid installation.\n";
179 } else
181 $main::OFFICE_HOME = $soserver;
188 # prepare GNU make path
189 while ( (!$main::correctVersion) &&
190 ((! -d "$main::OO_SDK_MAKE_HOME" ) ||
191 ((-d "$main::OO_SDK_MAKE_HOME") && (! -e "$main::OO_SDK_MAKE_HOME/$main::makeName"))) )
193 print " Enter GNU make ($main::makeVersion or higher) tools directory [$main::OO_SDK_MAKE_HOME_SUGGESTION]: ";
194 $main::OO_SDK_MAKE_HOME = readStdIn();
195 chop($main::OO_SDK_MAKE_HOME);
196 if ( $main::OO_SDK_MAKE_HOME eq "" )
198 $main::OO_SDK_MAKE_HOME = $main::OO_SDK_MAKE_HOME_SUGGESTION;
200 if ( (! -d "$main::OO_SDK_MAKE_HOME") ||
201 ((-d "$main::OO_SDK_MAKE_HOME") && (! -e "$main::OO_SDK_MAKE_HOME/$main::makeName")) )
203 $main::OO_SDK_MAKE_HOME = "";
204 print " Error: GNU make is required, please specify a GNU make tools directory.\n";
205 } else
207 #check version
208 my $testVersion = `$OO_SDK_MAKE_HOME/$main::makeName --version`;
209 if ( $testVersion eq "")
211 print " Set the environment variable OO_SDK_MAKE_HOME to your GNU build tools directory.\n";
212 print " GNU make version $main::makeVersion can be obtained at ftp://ftp.gnu.org/gnu/make/\n";
213 } else
215 if ($testVersion =~ m#((\d+\.)+\d+)# )
217 $testVersion = $1;
219 $main::correctVersion = testVersion($main::makeVersion, $testVersion, "$main::OO_SDK_MAKE_HOME/$main::makeName", 1);
220 if ( !$main::correctVersion )
222 print " The '$main::makeName' command found at '$main::OO_SDK_MAKE_HOME' has a wrong version\n";
223 $main::OO_SDK_MAKE_HOME = "";
229 # prepare zip path
230 $main::correctVersion = 0;
231 while ( (!$main::correctVersion) &&
232 ((! -d "$main::OO_SDK_ZIP_HOME" ) ||
233 ((-d "$main::OO_SDK_ZIP_HOME") && (! -e "$main::OO_SDK_ZIP_HOME/zip"))) )
235 print " Enter zip ($main::zipVersion or higher) tool directory [$main::OO_SDK_ZIP_HOME_SUGGESTION]: ";
236 $main::OO_SDK_ZIP_HOME = readStdIn();
237 chop($main::OO_SDK_ZIP_HOME);
238 if ( $main::OO_SDK_ZIP_HOME eq "" )
240 $main::OO_SDK_ZIP_HOME = $main::OO_SDK_ZIP_HOME_SUGGESTION;
242 if ( (! -d "$main::OO_SDK_ZIP_HOME") ||
243 ((-d "$main::OO_SDK_ZIP_HOME") && (! -e "$main::OO_SDK_ZIP_HOME/zip")) )
245 $main::OO_SDK_ZIP_HOME = "";
246 print " Error: zip tool is required, please specify a zip tool directory.\n";
247 } else
249 #check version
250 my $testVersion = `$OO_SDK_ZIP_HOME/zip -h 2>&1 | egrep Zip | head -n 1`;
251 $testVersion =~ s#Zip ([\d.]+) .*#$1#go;
252 if ( $testVersion eq "")
254 print " Set the environment variable OO_SDK_ZIP_HOME to your zip tool directory.\n";
255 print " zip version $main::zipVersion can be obtained at ftp://www.info-zip.org/\n";
256 } else
258 if ($testVersion =~ m#((\d+\.)+\d+)# )
260 $testVersion = $1;
262 $main::correctVersion = testVersion($main::zipVersion, $testVersion, "$main::OO_SDK_MAKE_HOME/zip", 1);
263 if ( !$main::correctVersion )
265 print " The 'zip' command found at '$main::OO_SDK_ZIP_HOME' has a wrong version\n";
266 $main::OO_SDK_ZIP_HOME = "";
272 # prepare cat path
273 $main::correctVersion = 0;
274 while ( (!$main::correctVersion) &&
275 ((! -d "$main::OO_SDK_CAT_HOME" ) ||
276 ((-d "$main::OO_SDK_CAT_HOME") && (! -e "$main::OO_SDK_CAT_HOME/cat"))) )
278 print " Enter cat tool directory [$main::OO_SDK_CAT_HOME_SUGGESTION]: ";
279 $main::OO_SDK_CAT_HOME = readStdIn();
280 chop($main::OO_SDK_CAT_HOME);
281 if ( $main::OO_SDK_CAT_HOME eq "" )
283 $main::OO_SDK_CAT_HOME = $main::OO_SDK_CAT_HOME_SUGGESTION;
285 if ( (! -d "$main::OO_SDK_CAT_HOME") ||
286 ((-d "$main::OO_SDK_CAT_HOME") && (! -e "$main::OO_SDK_CAT_HOME/cat")) )
288 $main::OO_SDK_CAT_HOME = "";
289 print " Error: cat tool is required, please specify a cat tool directory.\n";
291 # else ...
292 # TODO check version
293 # NOTE: only Linux cat understands --version
296 # prepare sed path
297 $main::correctVersion = 0;
298 while ( (!$main::correctVersion) &&
299 ((! -d "$main::OO_SDK_SED_HOME" ) ||
300 ((-d "$main::OO_SDK_SED_HOME") && (! -e "$main::OO_SDK_SED_HOME/sed"))) )
302 print " Enter sed tool directory [$main::OO_SDK_SED_HOME_SUGGESTION]: ";
303 $main::OO_SDK_SED_HOME = readStdIn();
304 chop($main::OO_SDK_SED_HOME);
305 if ( $main::OO_SDK_SED_HOME eq "" )
307 $main::OO_SDK_SED_HOME = $main::OO_SDK_SED_HOME_SUGGESTION;
309 if ( (! -d "$main::OO_SDK_SED_HOME") ||
310 ((-d "$main::OO_SDK_SED_HOME") && (! -e "$main::OO_SDK_SED_HOME/sed")) )
312 $main::OO_SDK_SED_HOME = "";
313 print " Error: sed tool is required, please specify a sed tool directory.\n";
315 # else ...
316 # TODO check version
317 # NOTE: only Linux sed understands --version
320 # prepare C++ compiler path
321 $main::correctVersion = 0;
322 while ( (!$main::correctVersion) &&
323 ((! -d "$main::OO_SDK_CPP_HOME" ) ||
324 ((-d "$main::OO_SDK_CPP_HOME") && (! -e "$main::OO_SDK_CPP_HOME/$main::cpp"))) )
326 print " C++ compilers where for example a language binding exist:\n";
327 print " - Solaris, Sun WorkShop 6 update 1 C++ 5.2 2000/09/11 or higher\n";
328 print " - Linux, GNU C++ compiler, gcc version 4.0.1 or higher\n";
329 print " - MacOS, GNU C++ compiler, gcc version 4.0.1 or higher\n";
330 print " Enter the directory of the C++ compiler, the directory\n";
331 print " where the compiler is located (optional) [$main::OO_SDK_CPP_HOME_SUGGESTION]: ";
333 $main::OO_SDK_CPP_HOME = readStdIn();
334 chop($main::OO_SDK_CPP_HOME);
335 if ( $main::OO_SDK_CPP_HOME eq "" )
337 $main::OO_SDK_CPP_HOME = $main::OO_SDK_CPP_HOME_SUGGESTION;
340 if ( ! $main::OO_SDK_CPP_HOME eq "" )
342 if ( (! -d "$main::OO_SDK_CPP_HOME") ||
343 ((-d "$main::OO_SDK_CPP_HOME") && (! -e "$main::OO_SDK_CPP_HOME/$main::cppName")) )
345 print " Error: Could not find directory '$main::OO_SDK_CPP_HOME'.\n";
346 if ( skipChoice("C++ compiler") == 1 )
348 $main::correctVersion = 1;
350 $main::OO_SDK_CPP_HOME = "";
351 } else
353 #check version
354 if ( $main::cppName eq "gcc" )
356 my $testVersion = `$OO_SDK_CPP_HOME/$main::cppName -dumpversion`;
357 if ( $testVersion eq "")
359 print " The '$main::cppName' command found at $main::OO_SDK_CPP_HOME/$main::cppName is not a ";
360 print " GNU compiler.\nSet the environment variable OO_SDK_CPP_HOME to your GNU build tools ";
361 print " directory.\nA GNU compiler version $main::cppVersion can be obtained at ";
362 print " ftp://ftp.gnu.org/gnu/gcc/\n";
363 } else
365 $main::correctVersion = testVersion($main::cppVersion, $testVersion, "$main::OO_SDK_CPP_HOME/$main::cppName", 1);
366 if ( !$main::correctVersion )
368 print " The '$main::cppName' command found at '$main::OO_SDK_CPP_HOME' has a wrong version\n";
369 if ( skipChoice("C++ compiler") == 1 )
371 $main::correctVersion = 1;
374 $main::OO_SDK_CPP_HOME = "";
379 } else
381 # the C++ compiler is optional
382 $main::correctVersion = 1;
387 # prepare Java path
388 $main::correctVersion = 0;
390 # prepare Java suggestion (cut bin or Commands directory to be in the root of the Java SDK)
391 $main::offset = rindex($main::OO_SDK_JAVA_HOME_SUGGESTION, "/$main::OO_SDK_JAVA_BIN_DIR");
392 if ( $main::offset != -1 )
394 $main::OO_SDK_JAVA_HOME_SUGGESTION = substr($main::OO_SDK_JAVA_HOME_SUGGESTION, 0, $main::offset);
397 while ( (!$main::correctVersion) &&
398 ((! -d "$main::OO_SDK_JAVA_HOME" ) ||
399 ((-d "$main::OO_SDK_JAVA_HOME") && (! -e "$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/javac"))) )
401 print " Enter Java SDK (1.5, recommendation is 1.6 or higher) installation directory (optional) [$main::OO_SDK_JAVA_HOME_SUGGESTION]: ";
402 $main::OO_SDK_JAVA_HOME = readStdIn();
403 chop($main::OO_SDK_JAVA_HOME);
404 if ( $main::OO_SDK_JAVA_HOME eq "" )
406 $main::OO_SDK_JAVA_HOME = $main::OO_SDK_JAVA_HOME_SUGGESTION;
408 if ( ! $main::OO_SDK_JAVA_HOME eq "" )
410 if ( (! -d "$main::OO_SDK_JAVA_HOME") ||
411 ((-d "$main::OO_SDK_JAVA_HOME") && (! -e "$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/javac")) )
413 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";
414 if ( skipChoice("JAVA SDK") == 1 )
416 $main::correctVersion = 1;
418 $main::OO_SDK_JAVA_HOME = "";
419 } else
421 #check version
422 my $testVersion = `$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/java -version 2>&1 | egrep "java version" | head -n 1 | sed -e 's#.*version "##' | sed -e 's#".*##'`;
423 $testVersion =~ s#([^\n]+)\n#$1#go;
425 $main::correctVersion = testVersion($main::javaVersion, $testVersion, "$main::OO_SDK_JAVA_HOME/$main::OO_SDK_JAVA_BIN_DIR/java", 1);
426 if ( !$main::correctVersion )
428 if ( skipChoice("JAVA SDK") == 1 )
430 $main::correctVersion = 1;
432 $main::OO_SDK_JAVA_HOME = "";
435 }else
437 # the Java SDK is optional
438 $main::correctVersion = 1;
443 # prepare output directory (optional)
444 while ( (!$main::skipOutputDir) &&
445 (! -d "$main::OO_SDK_OUTPUT_DIR") )
447 print " Default output directory is in your HOME directory.\n";
448 print " Enter an existent directory if you prefer a different output directory (optional) [$main::OO_SDK_OUTPUT_DIR_SUGGESTION]: ";
450 $main::OO_SDK_OUTPUT_DIR = readStdIn();
452 chop($main::OO_SDK_OUTPUT_DIR);
453 if ( $main::OO_SDK_OUTPUT_DIR eq "" )
455 $main::OO_SDK_OUTPUT_DIR = $main::OO_SDK_OUTPUT_DIR_SUGGESTION;
457 if ( ! $main::OO_SDK_OUTPUT_DIR eq "" )
459 if ( ! -d "$main::OO_SDK_OUTPUT_DIR" )
461 print " Error: Could not find directory '$main::OO_SDK_OUTPUT_DIR'.\n";
462 if ( skipChoice("optional output directory") == 1 )
464 $main::skipOutputDir = 1;
466 $main::OO_SDK_OUTPUT_DIR = "";
468 } else
470 # the output directory is optional
471 $main::skipOutputDir = 1;
475 # prepare auto deployment
476 while ( $main::SDK_AUTO_DEPLOYMENT eq "" ||
477 ((! $main::SDK_AUTO_DEPLOYMENT eq "YES") &&
478 (! $main::SDK_AUTO_DEPLOYMENT eq "NO")) )
480 print " Automatic deployment of UNO components (YES/NO) [$main::SDK_AUTO_DEPLOYMENT_SUGGESTION]: ";
481 $main::SDK_AUTO_DEPLOYMENT = uc <STDIN>;
482 chop($main::SDK_AUTO_DEPLOYMENT);
483 if ( $main::SDK_AUTO_DEPLOYMENT eq "" )
485 $main::SDK_AUTO_DEPLOYMENT = "YES";
489 prepareScriptFile("setsdkenv_unix.sh.in", "setsdkenv_unix.sh");
490 chmod 0644, "$main::OO_SDK_CONFIG_HOME/$main::hostname/setsdkenv_unix.sh";
492 print "\n";
493 print " ************************************************************************\n";
494 print " * ... your SDK environment has been prepared.\n";
495 print " * For each time you want to use this configured SDK environment, you\n";
496 print " * have to run the \"setsdkenv_unix\" script file!\n";
497 print " * Alternatively can you source one of the scripts\n";
498 print " * \"$main::OO_SDK_CONFIG_HOME/$main::hostname/setsdkenv_unix.sh\"\n";
499 print " * to get an environment without starting a new shell.\n";
500 print " ************************************************************************\n\n";
502 exit $return;
504 sub skipChoice
506 my $msg = shift;
507 my $skip = "";
508 while ( !( $skip eq "yes" || $skip eq "no") )
510 print " Do you want to skip the choice of the '$msg' (YES/NO): [YES] ";
511 $skip = lc <STDIN>;
512 chop($skip);
513 if ( $skip eq "" ) { $skip = "yes"; } # default
514 if ( $skip eq "yes" )
516 return 1;
519 return 0;
522 sub resolveLink
524 my $base= shift;
525 my $link= shift;
527 my $resolvedpath = "$base/$link";
528 my $linktarget = readlink "$resolvedpath";
529 my $resolvedlink = "";
531 while ( $linktarget ne "") {
533 if ( $linktarget =~ m/^\/.*/ )
535 $resolvedpath = "$linktarget";
536 } else {
537 $resolvedpath = `cd $base/$linktarget; pwd`;
538 chop $resolvedpath;
540 $base = dirname("$resolvedpath");
542 $linktarget = readlink "$resolvedpath";
545 $resolvedlink = `cd $resolvedpath; pwd`;
546 chop $resolvedlink;
547 return $resolvedlink;
550 sub searchprog
552 my $_search= shift;
553 my $tmpPath = `echo "\$PATH"`;
554 my @pathList = split(":" , $tmpPath);
555 my $progDir = "";
557 if ( $_search eq "javac" )
559 if ( $main::operatingSystem =~ m/darwin/ ) {
560 $progDir = resolveLink("/System/Library/Frameworks/JavaVM.Framework/Versions", "CurrentJDK");
562 if ( -e "$progDir/$main::OO_SDK_JAVA_BIN_DIR/javac" )
564 return "$progDir/$main::OO_SDK_JAVA_BIN_DIR";
568 if ( $main::operatingSystem =~ m/solaris/ ) {
569 $progDir = resolveLink("/usr/jdk", "latest");
570 if ( -e "$progDir/$main::OO_SDK_JAVA_BIN_DIR/javac" )
572 return "$progDir/$main::OO_SDK_JAVA_BIN_DIR";
577 if ( $_search eq "gmake" && $main::operatingSystem =~ m/solaris/ ) {
578 if ( -e "/usr/sfw/bin/gmake" )
580 return "/usr/sfw/bin";
584 foreach $i (@pathList)
586 chomp ($i);
588 if ( -e "$i/$_search" )
591 if ( index($i, "/") == 0 )
593 # # absolute path; leave unchanged
594 $progDir = $i;
595 } else
597 $progDir = `cd "$i"; pwd`;
599 return $progDir
602 return $progDir
605 sub searchMacOffice
607 if (-d "/Applications/LibreOffice.app" ) {
608 return "/Applications/LibreOffice.app"
610 if (-d "/Applications/OpenOffice.org.app" ) {
611 return "/Applications/OpenOffice.org.app"
613 if (-d "/Applications/Oracle Open Office.app" ) {
614 return "/Applications/Oracle Open Office.app";
616 if (-d "/Applications/StarOffice.app" ) {
617 return "/Applications/StarOffice.app";
619 if (-d "/Applications/StarSuite.app" ) {
620 return "/Applications/StarSuite.app";
623 return "";
626 sub searchoffice
628 my $offset = rindex($main::sdkpath, "/libreoffice");
629 my $tmpOffice = substr($main::sdkpath, 0, $offset);
630 my $officepath = "$tmpOffice/libreoffice";
632 # if ( $main::OO_MINORVERSION > 0) {
633 # $officepath = "$officepath$main::OO_MINORVERSION";
636 # search corresponding office for this SDK
637 if (-d $officepath && -e "$officepath/program/soffice") {
638 return $officepath;
640 # fallback
641 my $tmpversion = $main::OO_MAJORVERSION;
642 # if ( $main::OO_MINORVERSION > 0) {
643 # $tmpversion = "$tmpversion.$main::OO_MINORVERSION";
646 $officepath = "$tmpOffice/oracle_open_office$tmpversion";
647 if (-d $officepath && -e "$officepath/program/soffice") {
648 return $officepath;
651 # Before trying versioned directories, check if the sdk is directly under
652 # the office path.
653 $officepath = $main::sdkpath . "/..";
654 if (-d $officepath && -e "$officepath/program/soffice") {
655 return $officepath;
658 my $tmpversion = $main::OO_MAJORVERSION + 6;
659 if ( $main::OO_MINORVERSION > 0) {
660 $tmpversion = "$tmpversion.$main::OO_MINORVERSION";
663 $officepath = "$tmpOffice/staroffice$tmpversion";
664 if (-d $officepath && -e "$officepath/program/soffice") {
665 return $officepath;
667 $officepath = "$tmpOffice/StarOffice$tmpversion";
668 if (-d $officepath && -e "$officepath/program/soffice") {
669 return $officepath;
671 $officepath = "$tmpOffice/starsuite$tmpversion";
672 if (-d $officepath && -e "$officepath/program/soffice") {
673 return $officepath;
675 $officepath = "$tmpOffice/StarSuite$tmpversion";
676 if (-d $officepath && -e "$officepath/program/soffice") {
677 return $officepath;
679 $officepath = "";
681 # search other potential matching office versions
682 my $path = "/opt/";
683 my $entry = "";
684 my $version = "0";
685 for $entry (glob($path.'*')) {
686 ## if the file is a directory
687 if( -d $entry) {
689 if ($entry =~ m#(.+(o|O)ffice(\.org){0,1}(\d([\d\.]){0,2}))# ||
690 $entry =~ m#(.+(s|S)uite(.*)(\d([\d\.]){0,2}))# )
692 if ($4 > $version) {
693 $version = $4;
694 $officepath = $entry;
699 return $officepath;
704 sub testVersion
706 my $tmpMustBeVersion = shift;
707 my $tmpTestVersion = shift;
708 my $toolName = shift;
709 # 1=check + message 2=check only
710 my $checkOnly = shift;
711 my @mustBeVersion = split(/\.|_|-/,$tmpMustBeVersion);
712 my @testVersion = split(/\.|_|-/,$tmpTestVersion);
713 my $length = $#mustBeVersion;
715 if ($#testVersion < $#mustBeVersion) {
716 $length = $#testVersion;
719 for ($i=0; $i <= $length; $i++ )
721 if ( $testVersion[$i] > $mustBeVersion[$i] )
723 return 1; # 1 indicates a correct version
726 if ( $testVersion[$i] < $mustBeVersion[$i] )
728 if ( $#checkOnly == 1 ) {
729 print " The command '$toolName' has the version $tmpTestVersion.\n";
730 print " The SDK requires at least the version $tmpMustBeVersion.\n";
732 return 0;
736 return 1; # 1 indicates a correct version
739 sub readStdIn
741 my $tmpstdin = <STDIN>;
742 if ( index($tmpstdin, "\$") != -1)
744 return `echo $tmpstdin`;
747 return $tmpstdin;
750 sub prepareScriptFile()
752 my $inputFile = shift;
753 my $outputFile = shift;
755 if ( ! -d "$main::OO_SDK_CONFIG_HOME/$main::hostname" )
757 system("mkdir -p $main::OO_SDK_CONFIG_HOME/$main::hostname");
760 open ( FILEIN, "$main::sdkpath/$inputFile" ) || die "\nERROR: could not open '$main::sdkpath/$inputFile' for reading";
761 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";
763 while ( <FILEIN> )
765 $_ =~ s#\@OO_SDK_NAME\@#$main::OO_SDK_NAME#go;
766 $_ =~ s#\@OO_SDK_HOME\@#$main::OO_SDK_HOME#go;
767 $_ =~ s#\@OFFICE_HOME\@#$main::OFFICE_HOME#go;
768 $_ =~ s#\@OO_SDK_MAKE_HOME\@#$main::OO_SDK_MAKE_HOME#go;
769 $_ =~ s#\@OO_SDK_ZIP_HOME\@#$main::OO_SDK_ZIP_HOME#go;
770 $_ =~ s#\@OO_SDK_CAT_HOME\@#$main::OO_SDK_CAT_HOME#go;
771 $_ =~ s#\@OO_SDK_SED_HOME\@#$main::OO_SDK_SED_HOME#go;
772 $_ =~ s#\@OO_SDK_CPP_HOME\@#$main::OO_SDK_CPP_HOME#go;
773 $_ =~ s#\@OO_SDK_JAVA_HOME\@#$main::OO_SDK_JAVA_HOME#go;
774 $_ =~ s#\@SDK_AUTO_DEPLOYMENT\@#$main::SDK_AUTO_DEPLOYMENT#go;
775 $_ =~ s#\@OO_SDK_OUTPUT_DIR\@#$main::OO_SDK_OUTPUT_DIR#go;
777 print FILEOUT $_;
780 close FILEIN;
781 close FILEOUT;