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