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