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