1cdf0e10cSrcweireval 'exec perl -wS $0 ${1+\"$@\"}'
2cdf0e10cSrcweir    if 0;
3cdf0e10cSrcweir
4*7e90fac2SAndrew Rist#**************************************************************
5*7e90fac2SAndrew Rist#
6*7e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
7*7e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
8*7e90fac2SAndrew Rist#  distributed with this work for additional information
9*7e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
10*7e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
11*7e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
12*7e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
13*7e90fac2SAndrew Rist#
14*7e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
15*7e90fac2SAndrew Rist#
16*7e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
17*7e90fac2SAndrew Rist#  software distributed under the License is distributed on an
18*7e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*7e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
20*7e90fac2SAndrew Rist#  specific language governing permissions and limitations
21*7e90fac2SAndrew Rist#  under the License.
22*7e90fac2SAndrew Rist#
23*7e90fac2SAndrew Rist#**************************************************************
24*7e90fac2SAndrew Rist
25*7e90fac2SAndrew Rist
26cdf0e10cSrcweir
27cdf0e10cSrcweir# This is a pre check, which checks if some extra software exists
28cdf0e10cSrcweir
29cdf0e10cSrcweirBEGIN
30cdf0e10cSrcweir{
31cdf0e10cSrcweir    #       Adding the path of this script file to the include path in the hope
32cdf0e10cSrcweir    #       that all used modules can be found in it.
33cdf0e10cSrcweir    $0 =~ /^(.*)[\/\\]/;
34cdf0e10cSrcweir    push @INC, $1;
35cdf0e10cSrcweir}
36cdf0e10cSrcweir
37cdf0e10cSrcweiruse strict;
38cdf0e10cSrcweiruse English;                  # $OSNAME, ...
39cdf0e10cSrcweiruse Getopt::Long;
40cdf0e10cSrcweiruse Cwd;
41cdf0e10cSrcweiruse Cwd 'chdir';
42cdf0e10cSrcweirmy $cwd = getcwd();
43cdf0e10cSrcweir
44cdf0e10cSrcweirour $help;                    # Help option flag
45cdf0e10cSrcweirour $version;                 # Version option flag
46cdf0e10cSrcweir
47cdf0e10cSrcweir# flush STDOUT
48cdf0e10cSrcweir# my $old_handle = select (STDOUT); # "select" STDOUT and save # previously selected handle
49cdf0e10cSrcweir# $| = 1; # perform flush after each write to STDOUT
50cdf0e10cSrcweir# select ($old_handle); # restore previously selected handle
51cdf0e10cSrcweir
52cdf0e10cSrcweir$OUTPUT_AUTOFLUSH=1; # works only if use English is used.
53cdf0e10cSrcweir
54cdf0e10cSrcweirour $sGlobalIniFile;
55cdf0e10cSrcweirour $verbose = 0;
56cdf0e10cSrcweirour $ghostscript;
57cdf0e10cSrcweirour $imagemagick;
58cdf0e10cSrcweirour $java6;
59cdf0e10cSrcweirour $printerdriver;
60cdf0e10cSrcweir
61cdf0e10cSrcweirour $version_info = 'compare.pl';
62cdf0e10cSrcweir
63cdf0e10cSrcweirGetOptions(
64cdf0e10cSrcweir           "ghostscript"   => \$ghostscript,
65cdf0e10cSrcweir           "imagemagick"   => \$imagemagick,
66cdf0e10cSrcweir           "java6"         => \$java6,
67cdf0e10cSrcweir           "printerdriver" => \$printerdriver,
68cdf0e10cSrcweir           "verbose"       => \$verbose,
69cdf0e10cSrcweir
70cdf0e10cSrcweir           "help"          => \$help,
71cdf0e10cSrcweir           "version"       => \$version
72cdf0e10cSrcweir           );
73cdf0e10cSrcweir
74cdf0e10cSrcweirif ($help)
75cdf0e10cSrcweir{
76cdf0e10cSrcweir    print_usage(*STDOUT);
77cdf0e10cSrcweir    exit(0);
78cdf0e10cSrcweir}
79cdf0e10cSrcweir# Check for version option
80cdf0e10cSrcweirif ($version)
81cdf0e10cSrcweir{
82cdf0e10cSrcweir    print STDERR "$version_info\n";
83cdf0e10cSrcweir    exit(0);
84cdf0e10cSrcweir}
85cdf0e10cSrcweir
86cdf0e10cSrcweir# prepare the GlobalIniFile
87cdf0e10cSrcweir
88cdf0e10cSrcweirsub prepare()
89cdf0e10cSrcweir{
90cdf0e10cSrcweir    my $sEnv = "$ENV{PRJ}";
91cdf0e10cSrcweir    if (! $sEnv)
92cdf0e10cSrcweir    {
93cdf0e10cSrcweir        print "Warning: Seems you are not in a makefile.mk environment.\n";
94cdf0e10cSrcweir        $sEnv = "..";
95cdf0e10cSrcweir    }
96cdf0e10cSrcweir    my $sPath = getcwd();
97cdf0e10cSrcweir    $sPath .= "/" . $sEnv;
98cdf0e10cSrcweir    chdir ($sPath);
99cdf0e10cSrcweir    cwd();
100cdf0e10cSrcweir    $sPath = getcwd();
101cdf0e10cSrcweir    my $sInpath = $ENV{INPATH};
102cdf0e10cSrcweir    $sPath .= "/" . $sInpath . "/misc";
103cdf0e10cSrcweir    $sGlobalIniFile = "$sPath/pathes.ini";
104cdf0e10cSrcweir    print "Global Path ini file is: $sGlobalIniFile\n" if ($verbose);
105cdf0e10cSrcweir}
106cdf0e10cSrcweir
107cdf0e10cSrcweirsub unixpath($)
108cdf0e10cSrcweir{
109cdf0e10cSrcweir    my $path = shift;
110cdf0e10cSrcweir    $path =~ s/\\/\//g; # make out of '\' a '/'
111cdf0e10cSrcweir    return $path;
112cdf0e10cSrcweir}
113cdf0e10cSrcweir
114cdf0e10cSrcweir# search for file in a given path list.
115cdf0e10cSrcweir# the path list should be separated as the path variable in the corresponding OS
116cdf0e10cSrcweirsub searchForFileInPath($$)
117cdf0e10cSrcweir{
118cdf0e10cSrcweir    my $sFile = shift;
119cdf0e10cSrcweir    my $sPathList = shift;
120cdf0e10cSrcweir
121cdf0e10cSrcweir    my $sep = ':';
122cdf0e10cSrcweir    if ($OSNAME eq "MSWin32")
123cdf0e10cSrcweir    {
124cdf0e10cSrcweir        $sep = ';';
125cdf0e10cSrcweir    }
126cdf0e10cSrcweir    my @path = split($sep, $sPathList);
127cdf0e10cSrcweir
128cdf0e10cSrcweir    my $sPath;
129cdf0e10cSrcweir    my $startdir;
130cdf0e10cSrcweir    my $bFound = 0;
131cdf0e10cSrcweir    my $olddir = getcwd();
132cdf0e10cSrcweir
133cdf0e10cSrcweir    my $sWindowsHomeDir = unixpath(lc($ENV{WINDIR}));
134cdf0e10cSrcweir
135cdf0e10cSrcweir    foreach $startdir (@path)
136cdf0e10cSrcweir    {
137cdf0e10cSrcweir        my $nCount = 0;
138cdf0e10cSrcweir        #
139cdf0e10cSrcweir        # IMPORTANT: leave out windir path.
140cdf0e10cSrcweir        #
141cdf0e10cSrcweir        if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
142cdf0e10cSrcweir        {
143cdf0e10cSrcweir            my $sPath = unixpath(lc(convertCygwinPath($startdir)));
144cdf0e10cSrcweir            if ($sPath =~ /^$sWindowsHomeDir/ )
145cdf0e10cSrcweir            {
146cdf0e10cSrcweir                print "path: $startdir is windows path leave out.\n" if ($verbose);
147cdf0e10cSrcweir                next;
148cdf0e10cSrcweir            }
149cdf0e10cSrcweir        }
150cdf0e10cSrcweir
151cdf0e10cSrcweir        local *DIR;
152cdf0e10cSrcweir        if (opendir (DIR, $startdir))           # open directory
153cdf0e10cSrcweir        {
154cdf0e10cSrcweir            print "path: $startdir" if ($verbose);
155cdf0e10cSrcweir            chdir ($startdir);
156cdf0e10cSrcweir            cwd();
157cdf0e10cSrcweir            my $myfile;
158cdf0e10cSrcweir            while ($myfile = readdir(DIR))      # get filename
159cdf0e10cSrcweir            {
160cdf0e10cSrcweir                if (-f $myfile )                # is it a file?
161cdf0e10cSrcweir                {
162cdf0e10cSrcweir                    $nCount ++;
163cdf0e10cSrcweir                    if ($myfile eq $sFile)      # is it the real file?
164cdf0e10cSrcweir                    {
165cdf0e10cSrcweir                        $sPath = $startdir;
166cdf0e10cSrcweir                        $bFound = 1;
167cdf0e10cSrcweir                        last;
168cdf0e10cSrcweir                    }
169cdf0e10cSrcweir                }
170cdf0e10cSrcweir            }
171cdf0e10cSrcweir            closedir(DIR);
172cdf0e10cSrcweir            print " ($nCount)\n" if ($verbose);
173cdf0e10cSrcweir        }
174cdf0e10cSrcweir        if ($bFound == 1)
175cdf0e10cSrcweir        {
176cdf0e10cSrcweir            last;
177cdf0e10cSrcweir        }
178cdf0e10cSrcweir    }
179cdf0e10cSrcweir    chdir ($olddir);
180cdf0e10cSrcweir    cwd();
181cdf0e10cSrcweir
182cdf0e10cSrcweir    return $sPath;
183cdf0e10cSrcweir}
184cdf0e10cSrcweir
185cdf0e10cSrcweir
186cdf0e10cSrcweirprepare();
187cdf0e10cSrcweir# don't remove the inifile, only build clean should do this.
188cdf0e10cSrcweir# if ( -e "$sGlobalIniFile")
189cdf0e10cSrcweir# {
190cdf0e10cSrcweir#     unlink($sGlobalIniFile);
191cdf0e10cSrcweir# }
192cdf0e10cSrcweir
193cdf0e10cSrcweir
194cdf0e10cSrcweir# small helper, which replaces the return code
195cdf0e10cSrcweirsub errorAdaption($)
196cdf0e10cSrcweir{
197cdf0e10cSrcweir    my $error = shift;
198cdf0e10cSrcweir    if ($error != 0)
199cdf0e10cSrcweir    {
200cdf0e10cSrcweir        $error = $error / 256;
201cdf0e10cSrcweir    }
202cdf0e10cSrcweir    if ($error > 127)
203cdf0e10cSrcweir    {
204cdf0e10cSrcweir        $error = $error - 256;
205cdf0e10cSrcweir    }
206cdf0e10cSrcweir    return $error;
207cdf0e10cSrcweir}
208cdf0e10cSrcweir
209cdf0e10cSrcweir# for every error we increment this variable by 1
210cdf0e10cSrcweirour $nGlobalErrors = 0;
211cdf0e10cSrcweir
212cdf0e10cSrcweirsub handleError($$)
213cdf0e10cSrcweir{
214cdf0e10cSrcweir    my $error = shift;
215cdf0e10cSrcweir    my $sText = shift;
216cdf0e10cSrcweir    if ($error != 0)
217cdf0e10cSrcweir    {
218cdf0e10cSrcweir        print "ERROR: search for $sText has failed with Errornumber: $error\n";
219cdf0e10cSrcweir        $nGlobalErrors ++;
220cdf0e10cSrcweir    }
221cdf0e10cSrcweir}
222cdf0e10cSrcweir
223cdf0e10cSrcweirsub convertCygwinPath($)
224cdf0e10cSrcweir{
225cdf0e10cSrcweir    my $sPath = shift;
226cdf0e10cSrcweir
227cdf0e10cSrcweir    if ($OSNAME eq "cygwin")
228cdf0e10cSrcweir    {
229cdf0e10cSrcweir        # print "Cygwin Path Patch.\n" if ($verbose);
230cdf0e10cSrcweir        if ($sPath =~ /\/cygdrive\/(.)/)
231cdf0e10cSrcweir        {
232cdf0e10cSrcweir            my $Letter = $1;
233cdf0e10cSrcweir            $sPath =~ s/\/cygdrive\/${Letter}/${Letter}\:/;
234cdf0e10cSrcweir            # print "Cygwin Path Patch: '$sPath'\n" if ($verbose);
235cdf0e10cSrcweir        }
236cdf0e10cSrcweir    }
237cdf0e10cSrcweir    return $sPath;
238cdf0e10cSrcweir}
239cdf0e10cSrcweir
240cdf0e10cSrcweir# append key=value to GlobalIniFile
241cdf0e10cSrcweirsub insertPath($$)
242cdf0e10cSrcweir{
243cdf0e10cSrcweir    my $sKey = shift;
244cdf0e10cSrcweir    my $sValue = shift;
245cdf0e10cSrcweir
246cdf0e10cSrcweir    $sValue = convertCygwinPath($sValue);
247cdf0e10cSrcweir    my $sIniFile = convertCygwinPath($sGlobalIniFile);
248cdf0e10cSrcweir    local *INIFILE;
249cdf0e10cSrcweir    if (open(INIFILE, ">>" . $sIniFile ))
250cdf0e10cSrcweir    {
251cdf0e10cSrcweir        print INIFILE "$sKey=$sValue\n";
252cdf0e10cSrcweir    }
253cdf0e10cSrcweir    close(INIFILE);
254cdf0e10cSrcweir}
255cdf0e10cSrcweir
256cdf0e10cSrcweirsub getFastPath($)
257cdf0e10cSrcweir{
258cdf0e10cSrcweir    my $sKey = shift;
259cdf0e10cSrcweir    my $sValue;
260cdf0e10cSrcweir    local *INIFILE;
261cdf0e10cSrcweir    my $sIniFile = convertCygwinPath($sGlobalIniFile);
262cdf0e10cSrcweir    if (open(INIFILE, $sIniFile))
263cdf0e10cSrcweir    {
264cdf0e10cSrcweir        my $line;
265cdf0e10cSrcweir        while ($line = <INIFILE>)
266cdf0e10cSrcweir        {
267cdf0e10cSrcweir            chomp($line);
268cdf0e10cSrcweir            if ( $line =~ /^$sKey=(.*)$/ )
269cdf0e10cSrcweir            {
270cdf0e10cSrcweir                $sValue = $1;
271cdf0e10cSrcweir                # print INIFILE "$sKey=$sValue\n";
272cdf0e10cSrcweir            }
273cdf0e10cSrcweir        }
274cdf0e10cSrcweir        close(INIFILE);
275cdf0e10cSrcweir    }
276cdf0e10cSrcweir    return $sValue;
277cdf0e10cSrcweir}
278cdf0e10cSrcweir
279cdf0e10cSrcweirsub checkForGhostscript()
280cdf0e10cSrcweir{
281cdf0e10cSrcweir    print "Search for Ghostscript\n" if ($verbose);
282cdf0e10cSrcweir    if ($OSNAME eq "linux" ||
283cdf0e10cSrcweir        $OSNAME eq "solaris")
284cdf0e10cSrcweir    {
285cdf0e10cSrcweir        # search for ghostscript
286cdf0e10cSrcweir        local *GHOSTSCRIPT;
287cdf0e10cSrcweir        if (open(GHOSTSCRIPT, "which gs 2>&1 |"))
288cdf0e10cSrcweir        {
289cdf0e10cSrcweir            my $line;
290cdf0e10cSrcweir            while ($line = <GHOSTSCRIPT>)
291cdf0e10cSrcweir            {
292cdf0e10cSrcweir                chomp($line);
293cdf0e10cSrcweir                print "- $line\n" if ($verbose);
294cdf0e10cSrcweir            }
295cdf0e10cSrcweir            close(GHOSTSCRIPT);
296cdf0e10cSrcweir        }
297cdf0e10cSrcweir        my $error = errorAdaption($?);
298cdf0e10cSrcweir        handleError($error, "Ghostscript");
299cdf0e10cSrcweir    }
300cdf0e10cSrcweir    elsif ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
301cdf0e10cSrcweir    {
302cdf0e10cSrcweir        my $sGSExe = "gswin32c.exe";
303cdf0e10cSrcweir        # my $sGSPath = "C:/gs/gs8.64/bin";
304cdf0e10cSrcweir        my $sGSPath = getFastPath("gs.path");
305cdf0e10cSrcweir        if (! $sGSPath)
306cdf0e10cSrcweir        {
307cdf0e10cSrcweir            $sGSPath = searchForFileInPath($sGSExe, $ENV{PATH});
308cdf0e10cSrcweir
309cdf0e10cSrcweir            if ( ! -e "$sGSPath/$sGSExe")
310cdf0e10cSrcweir            {
311cdf0e10cSrcweir                $nGlobalErrors ++;
312cdf0e10cSrcweir                print "ERROR: search for $sGSPath/$sGSExe failed.\n";
313cdf0e10cSrcweir                print "Please install ghostscript from www.adobe.com to and make it available in \$PATH variable \n";
314cdf0e10cSrcweir            }
315cdf0e10cSrcweir            else
316cdf0e10cSrcweir            {
317cdf0e10cSrcweir                insertPath("gs.path", $sGSPath);
318cdf0e10cSrcweir                insertPath("gs.exe", $sGSExe);
319cdf0e10cSrcweir            }
320cdf0e10cSrcweir        }
321cdf0e10cSrcweir        if ( -e "$sGSPath/$sGSExe" )
322cdf0e10cSrcweir        {
323cdf0e10cSrcweir            print "Found Ghostscript: '$sGSPath'\n" if ($verbose);
324cdf0e10cSrcweir        }
325cdf0e10cSrcweir    }
326cdf0e10cSrcweir    else
327cdf0e10cSrcweir    {
328cdf0e10cSrcweir        print "ERROR: Check for Ghostscript failed, due to unsupported '$OSNAME' environment.\n";
329cdf0e10cSrcweir        $nGlobalErrors ++;
330cdf0e10cSrcweir    }
331cdf0e10cSrcweir}
332cdf0e10cSrcweir
333cdf0e10cSrcweir
334cdf0e10cSrcweirsub checkForPSDriver()
335cdf0e10cSrcweir{
336cdf0e10cSrcweir    # we don't need to check for unix here, due to the fact, unix is per default be able to print in postscript
337cdf0e10cSrcweir    if ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
338cdf0e10cSrcweir    {
339cdf0e10cSrcweir        print "Check for postscript driver.\n" if ($verbose);
340cdf0e10cSrcweir        my $sWindowsRoot = $ENV{windir};
341cdf0e10cSrcweir        if (! $sWindowsRoot)
342cdf0e10cSrcweir        {
343cdf0e10cSrcweir            $sWindowsRoot = $ENV{WINDIR};
344cdf0e10cSrcweir        }
345cdf0e10cSrcweir        my $sCrossOfficeDriver = "${sWindowsRoot}/system32/crossoffice.ppd";
346cdf0e10cSrcweir        if ( ! -e "$sCrossOfficeDriver")
347cdf0e10cSrcweir        {
348cdf0e10cSrcweir            print "ERROR: Don't found Postscript driver $sCrossOfficeDriver file\n";
349cdf0e10cSrcweir            $nGlobalErrors ++;
350cdf0e10cSrcweir            print "Take a look on: http://so-gfxcmp.germany.sun.com/docs/further/convwatch/convwatch.html.\n";
351cdf0e10cSrcweir        }
352cdf0e10cSrcweir    }
353cdf0e10cSrcweir}
354cdf0e10cSrcweir
355cdf0e10cSrcweirsub checkForImageMagick()
356cdf0e10cSrcweir{
357cdf0e10cSrcweir    print "Search for Imagemagick\n" if ($verbose);
358cdf0e10cSrcweir    if ($OSNAME eq "linux" ||
359cdf0e10cSrcweir        $OSNAME eq "solaris")
360cdf0e10cSrcweir    {
361cdf0e10cSrcweir        # search for imagemagick
362cdf0e10cSrcweir        local *IMAGEMAGICK;
363cdf0e10cSrcweir        if (open(IMAGEMAGICK, "which convert 2>&1 |"))
364cdf0e10cSrcweir        {
365cdf0e10cSrcweir            my $line;
366cdf0e10cSrcweir            while ($line = <IMAGEMAGICK>)
367cdf0e10cSrcweir            {
368cdf0e10cSrcweir                chomp($line);
369cdf0e10cSrcweir                print "- $line\n" if ($verbose);
370cdf0e10cSrcweir            }
371cdf0e10cSrcweir            close(IMAGEMAGICK);
372cdf0e10cSrcweir        }
373cdf0e10cSrcweir        my $error = errorAdaption($?);
374cdf0e10cSrcweir        handleError($error, "Imagemagick");
375cdf0e10cSrcweir    }
376cdf0e10cSrcweir    elsif ($OSNAME eq "MSWin32" || $OSNAME eq "cygwin")
377cdf0e10cSrcweir    {
378cdf0e10cSrcweir        my $sImageMagickExe = "convert.exe";
379cdf0e10cSrcweir        # my $sImageMagickPath = "C:/gs/gs8.64/bin";
380cdf0e10cSrcweir        my $sImageMagickPath = getFastPath("imagemagick.path");
381cdf0e10cSrcweir        if (! $sImageMagickPath)
382cdf0e10cSrcweir        {
383cdf0e10cSrcweir            $sImageMagickPath = searchForFileInPath($sImageMagickExe, $ENV{PATH});
384cdf0e10cSrcweir            if ($sImageMagickPath)
385cdf0e10cSrcweir            {
386cdf0e10cSrcweir                if ( ! -e "$sImageMagickPath/$sImageMagickExe")
387cdf0e10cSrcweir                {
388cdf0e10cSrcweir                    $nGlobalErrors ++;
389cdf0e10cSrcweir                    print "ERROR: search for $sImageMagickPath/$sImageMagickExe failed.\n";
390cdf0e10cSrcweir                    print "Please install ImageMagick from www.imagemagick.org to and make it available in \$PATH variable \n";
391cdf0e10cSrcweir                }
392cdf0e10cSrcweir                else
393cdf0e10cSrcweir                {
394cdf0e10cSrcweir                    insertPath("imagemagick.path", $sImageMagickPath);
395cdf0e10cSrcweir                    # insertPath("gs.exe", $sImageMagickExe);
396cdf0e10cSrcweir                }
397cdf0e10cSrcweir            }
398cdf0e10cSrcweir            else
399cdf0e10cSrcweir            {
400cdf0e10cSrcweir                # next try, search image magick in $PROGRAMFILES
401cdf0e10cSrcweir                my $sPrograms = unixpath($ENV{PROGRAMFILES});
402cdf0e10cSrcweir
403cdf0e10cSrcweir                if (! $sPrograms)
404cdf0e10cSrcweir                {
405cdf0e10cSrcweir                    print "There exist no \$PROGRAMFILES path, wrong Windows version?\n";
406cdf0e10cSrcweir                    $nGlobalErrors++;
407cdf0e10cSrcweir                }
408cdf0e10cSrcweir                else
409cdf0e10cSrcweir                {
410cdf0e10cSrcweir                    local *DIR;
411cdf0e10cSrcweir                    if (opendir (DIR, $sPrograms))           # open program directory
412cdf0e10cSrcweir                    {
413cdf0e10cSrcweir                        my $myfile;
414cdf0e10cSrcweir                        while ($myfile = readdir(DIR))       # get a filename
415cdf0e10cSrcweir                        {
416cdf0e10cSrcweir                            if ($myfile =~ /ImageMagick/)
417cdf0e10cSrcweir                            {
418cdf0e10cSrcweir                                $sImageMagickPath = $sPrograms . "/" . $myfile;
419cdf0e10cSrcweir                                last;
420cdf0e10cSrcweir                            }
421cdf0e10cSrcweir                        }
422cdf0e10cSrcweir                        closedir(DIR);
423cdf0e10cSrcweir                    }
424cdf0e10cSrcweir                    if (! -e $sImageMagickPath)
425cdf0e10cSrcweir                    {
426cdf0e10cSrcweir                        print "ImageMagick not found.\n";
427cdf0e10cSrcweir                        $nGlobalErrors ++;
428cdf0e10cSrcweir                    }
429cdf0e10cSrcweir                    else
430cdf0e10cSrcweir                    {
431cdf0e10cSrcweir                        insertPath("imagemagick.path", $sImageMagickPath);
432cdf0e10cSrcweir                    }
433cdf0e10cSrcweir                }
434cdf0e10cSrcweir            }
435cdf0e10cSrcweir
436cdf0e10cSrcweir        }
437cdf0e10cSrcweir        if ( -e "$sImageMagickPath/$sImageMagickExe" )
438cdf0e10cSrcweir        {
439cdf0e10cSrcweir            print "Found ImageMagick: '$sImageMagickPath'\n" if ($verbose);
440cdf0e10cSrcweir        }
441cdf0e10cSrcweir    }
442cdf0e10cSrcweir    else
443cdf0e10cSrcweir    {
444cdf0e10cSrcweir        print "ERROR: not supported environment\n";
445cdf0e10cSrcweir    }
446cdf0e10cSrcweir}
447cdf0e10cSrcweir
448cdf0e10cSrcweirsub checkForJava6()
449cdf0e10cSrcweir{
450cdf0e10cSrcweir    print "Search for Java6\n" if ($verbose);
451cdf0e10cSrcweir    my $javaexe = "java";
452cdf0e10cSrcweir    if ( $ENV{JAVA6} )
453cdf0e10cSrcweir    {
454cdf0e10cSrcweir        $javaexe = $ENV{JAVA6};
455cdf0e10cSrcweir    }
456cdf0e10cSrcweir
457cdf0e10cSrcweir    if ($OSNAME eq "linux" || $OSNAME eq "cygwin")
458cdf0e10cSrcweir    {
459cdf0e10cSrcweir        # search for imagemagick
460cdf0e10cSrcweir        local *JAVA;
461cdf0e10cSrcweir        if (open(JAVA, "$javaexe -version 2>&1 |"))
462cdf0e10cSrcweir        {
463cdf0e10cSrcweir            my $line;
464cdf0e10cSrcweir            while ($line = <JAVA>)
465cdf0e10cSrcweir            {
466cdf0e10cSrcweir                chomp($line);
467cdf0e10cSrcweir                print "- $line\n" if ($verbose);
468cdf0e10cSrcweir                if ( $line =~ /java version "(.*)"/ )
469cdf0e10cSrcweir                {
470cdf0e10cSrcweir                    my $javaversion = $1;
471cdf0e10cSrcweir                    my @version = split('\.', $javaversion);
472cdf0e10cSrcweir                    print "Found Java version: $version[1]  the complete version: $javaversion\n" if ($verbose);
473cdf0e10cSrcweir                    if ( $version[1] < 6)
474cdf0e10cSrcweir                    {
475cdf0e10cSrcweir                        print "Wrong Java version, at least Java version 6 is need but found $javaversion.\n";
476cdf0e10cSrcweir                        $nGlobalErrors++;
477cdf0e10cSrcweir                        print "It is possible to overwrite the java exe with environment variable JAVA6='path'.\n";
478cdf0e10cSrcweir                    }
479cdf0e10cSrcweir                    else
480cdf0e10cSrcweir                    {
481cdf0e10cSrcweir                        insertPath("java.exe", $javaexe);
482cdf0e10cSrcweir                    }
483cdf0e10cSrcweir                    last;
484cdf0e10cSrcweir                }
485cdf0e10cSrcweir            }
486cdf0e10cSrcweir            close(JAVA);
487cdf0e10cSrcweir        }
488cdf0e10cSrcweir        my $error = errorAdaption($?);
489cdf0e10cSrcweir        handleError($error, "Java");
490cdf0e10cSrcweir    }
491cdf0e10cSrcweir    elsif ($OSNAME eq "MSWin32")
492cdf0e10cSrcweir    {
493cdf0e10cSrcweir         my $javaexe = "java";
494cdf0e10cSrcweir         if ( $ENV{JAVA6} )
495cdf0e10cSrcweir         {
496cdf0e10cSrcweir             $javaexe = $ENV{JAVA6};
497cdf0e10cSrcweir         }
498cdf0e10cSrcweir
499cdf0e10cSrcweir         if (! -e $javaexe)
500cdf0e10cSrcweir         {
501cdf0e10cSrcweir             print "Java not found.\n";
502cdf0e10cSrcweir             $nGlobalErrors ++;
503cdf0e10cSrcweir         }
504cdf0e10cSrcweir         else
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir             print "Found Java: '$javaexe'\n" if ($verbose);
507cdf0e10cSrcweir             insertPath("java.exe", $javaexe);
508cdf0e10cSrcweir         }
509cdf0e10cSrcweir    }
510cdf0e10cSrcweir    else
511cdf0e10cSrcweir    {
512cdf0e10cSrcweir        print "ERROR: Java not found.\n";
513cdf0e10cSrcweir    }
514cdf0e10cSrcweir}
515cdf0e10cSrcweir
516cdf0e10cSrcweir# different checks
517cdf0e10cSrcweirprint "Environment '$OSNAME'\n" if ($verbose);
518cdf0e10cSrcweir
519cdf0e10cSrcweirif ($printerdriver)
520cdf0e10cSrcweir{
521cdf0e10cSrcweir    checkForPSDriver();
522cdf0e10cSrcweir}
523cdf0e10cSrcweirif ($ghostscript)
524cdf0e10cSrcweir{
525cdf0e10cSrcweir    checkForGhostscript();
526cdf0e10cSrcweir}
527cdf0e10cSrcweirif ($imagemagick)
528cdf0e10cSrcweir{
529cdf0e10cSrcweir    checkForImageMagick();
530cdf0e10cSrcweir}
531cdf0e10cSrcweirif ($java6)
532cdf0e10cSrcweir{
533cdf0e10cSrcweir    checkForJava6();
534cdf0e10cSrcweir}
535cdf0e10cSrcweir
536cdf0e10cSrcweir# return with found errors
537cdf0e10cSrcweirexit($nGlobalErrors);
538cdf0e10cSrcweir
539cdf0e10cSrcweir# ------------------------------------------------------------------------------
540cdf0e10cSrcweirsub print_usage(*)
541cdf0e10cSrcweir{
542cdf0e10cSrcweir    local *HANDLE = $_[0];
543cdf0e10cSrcweir    my $tool_name = basename($0);
544cdf0e10cSrcweir
545cdf0e10cSrcweir    print(HANDLE <<END_OF_USAGE);
546cdf0e10cSrcweir
547cdf0e10cSrcweirUsage: $tool_name [OPTIONS]
548cdf0e10cSrcweir
549cdf0e10cSrcweir    -ghostscript             Try to find ghostscript in your environment
550cdf0e10cSrcweir    -imagemagick             Try to find imagemagick
551cdf0e10cSrcweir    -java6                   Checks for java 1.6.x
552cdf0e10cSrcweir    -printerdriver           Try to find printer driver, windows only
553cdf0e10cSrcweir    -verbose                 be verbose
554cdf0e10cSrcweir
555cdf0e10cSrcweir    -h, --help               Print this help, then exit
556cdf0e10cSrcweir    -v, --version            Print version number, then exit
557cdf0e10cSrcweir
558cdf0e10cSrcweirEND_OF_USAGE
559cdf0e10cSrcweir;
560cdf0e10cSrcweir}
561