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