1@rem = '--*-Perl-*--
2@echo off
3if "%OS%" == "Windows_NT" goto WinNT
4perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
5goto endofperl
6:WinNT
7perl -x -S %0 %*
8if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
9if %errorlevel% == 9009 echo You do not have Perl in your PATH.
10if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
11goto endofperl
12@rem ';
13#!perl -w
14#line 15
15#  -------------------------------------------------------------------------
16#                               GRISBI for Windows
17#  -------------------------------------------------------------------------
18# $Id: autogen.bat,v 1.13 2009/05/08 17:41:01 pbiava Exp $
19#  -------------------------------------------------------------------------
20#
21#  Copyleft 2004 (c) Fran�ois Terrot
22#           2005 (c) Fran�ois Terrot
23#           2006 (c) Fran�ois Terrot
24#
25#  This program is free software; you can redistribute it and/or
26#  modify it under the terms of the GNU General Public License as
27#  published by the Free Software Foundation; either version 2 of the
28#  License, or (at your option) any later version.
29#
30#  This program is distributed in the hope that it will be useful, but
31#  WITHOUT ANY WARRANTY; without even the implied warranty of
32#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
33#  General Public License for more details.
34#
35#  You should have received a copy of the GNU General Public License
36#  along with this program; if not, write to the Free Software
37#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
38#  USA
39#  -------------------------------------------------------------------------
40#  History:
41#
42#  $Log: autogen.bat,v $
43#  Revision 1.13  2009/05/08 17:41:01  pbiava
44#  minor fixes in windows project's generation
45#
46#  Revision 1.12  2006/12/10 17:20:39  teilginn
47#  last modifications to make grisbi win32 compliant with gtk 2.8
48#
49#  Revision 1.11  2006/04/15 19:11:58  teilginn
50#  add libz in link (-lz)
51#
52#  Revision 1.10  2006/04/15 16:04:00  teilginn
53#  merge modification done for 0.5.8
54#
55#  Revision 1.1.2.10  2006/04/15 15:12:32  teilginn
56#  updates for GTK 2.6
57#
58#  Revision 1.1.2.9  2006/01/31 21:05:12  teilginn
59#  Remove Perl warnings
60#
61#  Revision 1.1.2.8  2006/01/31 20:48:36  teilginn
62#  last updates
63#
64#  Revision 1.1.2.7  2005/06/05 09:49:11  teilginn
65#  Better languages (po) variables list management
66#
67#  Revision 1.1.2.6  2005/05/22 16:07:02  teilginn
68#  Support 'The Gimp' and also 'Gaim' GTK binary package
69#
70#  Revision 1.1.2.5  2005/04/17 16:53:17  teilginn
71#  New DevCpp version support + clean the script from unusefull stuff
72#
73#  Revision 1.1.2.4  2004/10/13 19:46:44  teilginn
74#  update to also manage installer
75#
76#  Revision 1.1.2.3  2004/09/02 19:46:39  teilginn
77#  get version number from configure.in if not in the directory name
78#
79#  Revision 1.1.2.2  2004/08/26 20:19:06  teilginn
80#  add support for current gtk-2.2.4-3
81#
82#  Revision 1.1.2.1  2004/08/15 14:24:54  teilginn
83#  autogen script and templates for Windows
84#
85#
86# --------------------------------------------------------------------------
87# Todo:
88#
89# - To implemente cache system for using same value on different projects
90# - To try to autodetect used tools location
91# - To clean command line args
92# - To add auto documentation for the -h/--help args
93# - To add a clean command
94# - To add the build directory management
95# - To manage and explain all error cases
96#
97# **************************************************************************
98# local $CvsId = '$RevisionName';
99# ==========================================================================
100# PACKAGES
101# ==========================================================================
102use strict;
103# **************************************************************************
104# @INC
105# **************************************************************************
106# These few lines are here to manage the fact the script may have to use
107# not present modules without having to modify the current installation:
108# - put your pure perl module in the 'lib' directory
109# - put the 'cpan' module required by the script in 'site/lib'
110# - put the dll files required by modules in the 'site/arch/5x' directory
111#       where <x> depend form the Perl version ( Perl 5.x)
112#       Note: it should a good idea to provide Perl 5.6 and 5.8 dlls
113#
114# The way you are able to distribution your script for perl 5.6 and 5.8
115# without having to ask the user to update his installation.
116# If you want to restricted you script to Perl 5.8 modify the require line
117
118our $LOCALLIBDIR;
119our $LOCALSITEDIR;
120our $LOCALARCHDIR;
121BEGIN
122{
123    require 5.006;
124    use File::Basename; my $INSTDIR = dirname $0; $INSTDIR =~ s/\\/\//g;
125    $LOCALLIBDIR  = $INSTDIR."/lib";
126    $LOCALSITEDIR = $INSTDIR."/site/lib";
127    $LOCALARCHDIR = $INSTDIR."/site/arch/5" . int (($]-5) *1000);
128}
129
130use lib($LOCALLIBDIR);
131use lib($LOCALSITEDIR);
132use lib($LOCALARCHDIR);
133
134( "$^O" =~ m/MSWin32/ ) or die "This script is only designed for MS Win32 operating System\n";
135
136# **************************************************************************
137
138use Cwd qw(chdir realpath getcwd);
139use File::Basename;
140use File::Copy;
141use File::Path;
142use File::Spec qw(File::Spec->abs2rel file_name_is_absolute);
143use Pod::Usage;
144use Getopt::Long;
145use Win32::TieRegistry(Delimiter=>"/");
146use TieIniFile;
147
148# ==========================================================================
149# GLOBALS
150# ==========================================================================
151our $g_debug  = 0;
152my $config_ini = "autogen.ini";   # configuration file (config.ini)
153my %cache_in;                     # configuration parameters from cache
154my %config;                       # configuration parameters from config.ini
155my %opt;                          # configuration parameters from arg line
156my %src_plugins;
157my @targets = ();
158my $g_outdir = realpath(getcwd());
159
160my $builddir   ;
161my $gtkdevdir ;
162my $gccbasedir ;
163my $grisbidir  ;
164my $startdir   ;
165
166my %GTKBIN_RECOMMENDED = ( 'maj'=> 2 , 'min' => 8 , 'rel' => 7 );
167my %GTKDEV_RECOMMENDED = ( 'maj'=> 2 , 'min' => 8 , 'rel' => 7 );
168
169#
170# ==========================================================================
171# FUNCTIONS
172# ==========================================================================
173# --------------------------------------------------------------------------
174# Utils                                                             PART_2_1
175# --------------------------------------------------------------------------
176# \brief List the source files from the given directory
177#   Get the source ( ".c", ) files from the given directory, exclude
178#   "variable*.c" files and remove the directory name.
179#   The result is a Makefile compatible file list
180#
181# \param  $dir path (relative or absolute) of the directory to search in
182# \return $    the source file list, each file is <space> separed
183# --------------------------------------------------------------------------
184sub _get_c_file_list
185{
186    my ($dir) = @_;
187    my $srcs  = "";
188    opendir DIR,$dir or die "autogen.pl *** WARNING * unable get sources list : $@\n";
189    rewinddir DIR;
190    LS_DIR: while (defined (my $f = readdir DIR ))
191    {
192        next LS_DIR if ( $f =~ m/^variables.*\.c/ ) ;
193        $srcs .= " $f" if ( $f =~ m/\.c$/ ); }
194    close DIR;
195    return $srcs;
196}
197sub _get_files
198{
199    my ($dir) = @_;
200    my %files;
201    my @variables;
202    my @sources;
203    my @headers;
204    opendir DIR,$dir or die "autogen.pl *** WARNING * unable get sources list : $@\n";
205    rewinddir DIR;
206    LS_DIR: while (defined (my $f = readdir DIR ))
207    {
208        ( $f =~ m/^variables.*\.c/ ) && do {
209            push @variables,($f);
210
211            next LS_DIR;
212        };
213        ( $f =~ m/\.c$/ ) && do {
214            push @sources,($f);
215            next LS_DIR;
216        };
217        ( $f =~ m/\.h$/ ) && do {
218            push @headers,($f);
219            next LS_DIR;
220        };
221    }
222    close DIR;
223    $files{'variables'}{'ref'} = \@variables;
224    $files{'variables'}{'num'} = $#variables;
225    $files{'sources'}{'ref'}   = \@sources;
226    $files{'sources'}{'num'}   = $#sources;
227    $files{'headers'}{'ref'}   = \@headers;
228    $files{'headers'}{'num'}   = $#headers;
229    $files{'headers'}{'ref'}   = \@headers;
230    $files{'headers'}{'num'}   = $#headers;
231    $files{'num'}   = $#variables + $#sources + $#headers;
232    return %files;
233}
234# \brief List the po files from the given directory
235#   Get the source ( ".po", ) files from the given directory, and
236#   remove the directory name.
237#   The result is a Makefile compatible file list
238#
239# \param  $dir path (relative or absolute) of the directory to search in
240# \return @    the source file list,
241# --------------------------------------------------------------------------
242sub _get_po_file_list
243{
244    my ($dir) = @_;
245    my @pos  ;
246    opendir DIR,$dir or die "autogen.pl *** WARNING * unable get po sources list : $@\n";
247    rewinddir DIR;
248    LS_DIR: while (defined (my $f = readdir DIR ))
249    {
250        next LS_DIR if ( $f =~ m/^\./ ) ;
251        push @pos,($f) if ( $f =~ s/\.po$// );
252    }
253    close DIR;
254    return @pos;
255}
256sub _get_plugins_list
257{
258    my ($dir) = @_;
259    my %plugins;
260    opendir DIR,$dir or die "autogen.pl *** WARNING *** unable to get plugins list from $dir: $@\n";
261    rewinddir DIR;
262    LS_DIR: foreach my $entry (readdir DIR)
263    {
264        next LS_DIR if ($entry =~ m/^..?$/ );
265        # only directory is used ...
266        next LS_DIR unless (-d "$dir/$entry" );
267        # skip . and ..
268        next LS_DIR if ($entry =~ m/^CVS$/ );
269        opendir SUBD, "$dir/$entry" or do {
270            warn "autogen.pl:get_plugins_list() *** WARNING *** unable to enter $dir/$entry : $@ *\n";
271            next LS_DIR;
272        };
273        rewinddir SUBD;
274
275        # my $plheaders = "";
276        my $plsources = "";
277
278        LS_SUBD: foreach my $subfile (readdir SUBD)
279        {
280            # only listing file are used, skip all directories
281            next LS_SUBD if (-d "$dir/$entry/$subfile");
282            $plsources .= " $entry/$subfile" if ( $subfile =~m/.c$/ );
283            #   push @plheaders,("$subfile") if ( $subfile =~m/.h$/ );
284        }
285        closedir SUBD;
286
287        $plugins{$entry}{'sources'}{'ref'} = $plsources;
288        # $plugins{$entry}{'sources'}{'num'} = $#plsources;print $#plsources;
289        # $plugins{$entry}{'headers'}{'ref'} = \@plheaders;
290        # $plugins{$entry}{'headers'}{'num'} = $#plheaders;
291        # $plugins{$entry}{'num'} = $#plheaders + $#plsources;
292    }
293    closedir DIR;
294    return %plugins;
295}
296# --------------------------------------------------------------------------
297#/**
298# * create directy if not exists in the current selected by _cd directory
299# *
300# * \param $dir directory to create
301# *
302# */
303sub _mkdir # {{{
304{
305    my ($dir) = @_;
306    $dir = "${g_outdir}/${dir}" unless (File::Spec->file_name_is_absolute($dir));
307    print "_mkdir $dir\n" if ($g_debug);
308    unless (-d "$dir")
309    {
310        print "Creating ".File::Spec->abs2rel($dir)."\n";
311        eval { mkpath($dir) } or die "*** ERROR * Couldn't create dir : $@\n";
312    }
313} # }}}
314#/*!
315# * virtually change directory, the new directory is the base of all commands
316# *     the directory will be created if not exists
317# *     $g_outdir = realpath $g_outdir/$dir if $dir is a relative path
318# *     $g_outdir = $dir if $dir is a absolute path
319# *
320# * \param $dir new directory destination ,
321# *
322# */
323sub _cd # {{{
324{
325    my ($dir,$quiet) = @_;
326
327    $dir = "${g_outdir}/${dir}" unless (File::Spec->file_name_is_absolute(${dir}));
328    print "_cd $dir\n" if ($g_debug);
329    _mkdir ($dir);
330
331    $dir = realpath($dir);
332    print "_cd $dir\n" if ($g_debug);
333    if ( $g_outdir ne $dir)
334    {
335        die "*** ERROR * Couldn't change directory to ${dir}\n" unless (-d "$dir");
336        print "Entering ".File::Spec->abs2rel($dir)."\n" unless (defined($quiet));
337        $g_outdir = $dir;
338    }
339    return $g_outdir;
340} #  }}}
341#/**
342# * copy file if it not exists or is out of date (not implemented yet) in the destination directory
343# *
344# * \param $path directory the file is to be copied from
345# * \param $file location to copy form $path to $g_outdir
346# * \param $ref_ignore reference to a list of regexp defining the file to ignore
347# *
348# */
349sub _cp # {{{
350{
351    my $cp_oldpwd = $g_outdir;
352    my ($path,$file,$ref_ignore) = @_;
353    eval "\$path = \"$path\";";
354    eval "\$ref_ignore = $ref_ignore" if (defined ($ref_ignore));
355    $path =~ s/\/\//\//g;
356    print "_cp ${path}, ${file}\n" if($g_debug);
357    # if file is a directory - we copy all the contains
358    die "**** CONFIGURATION ERROR * $path/$file does not exist\n" unless ( -d "$path");
359    if (defined ($ref_ignore))
360    {
361        print "is $file matching with $ref_ignore ?\n" if ($g_debug);
362        IGNORE: foreach (@$ref_ignore)
363        {
364            if ($file =~ m/$_/ )
365            {
366                print "Ignoring $file\n";
367                return;
368            }
369        }
370        print "NO\n" if ($g_debug);
371    }
372    if ( -d "$path/$file")
373    {
374        print "$path/$file is a directory\n" if ($g_debug);
375        _cd ($file);
376        opendir DIR, "${path}/${file}";
377        rewinddir DIR;
378        LS: foreach (readdir DIR)
379        {
380            next LS if ( /\.{1,2}$/ ) ; # Skip . and ..
381            _cp ("$path/$file","$_",$ref_ignore);
382        }
383#        closedir DIR;
384        _cd('..','TRUE');
385    }
386    elsif ( $file =~ m/^\/.*\/$/ ) # regexp
387    {
388        opendir DIR, "${path}";
389        rewinddir DIR;
390        LSREGEXP: foreach (readdir DIR)
391        {
392            next LSREGEXP if ( /\.{1,2}$/ ) ; # Skip . and ..
393            _cp ("$path","$_",$ref_ignore) if ( eval ("'$_' =~ m$file") ) ;
394        }
395        closedir DIR;
396    }
397    else
398    {
399        if ( (!-f "${g_outdir}/${file}") || ( (stat("${g_outdir}/${file}"))[9] <  (stat("${path}/${file}"))[9] ))
400        {
401            _mkdir ( dirname "${g_outdir}/${file}");
402            print "Copying $file\n";
403            copy ("${path}/${file}","${g_outdir}/${file}");
404        }
405        else
406        {
407            print "$file is uptodate\n";
408        }
409    }
410    _cd ($cp_oldpwd,'quiet');
411
412} # }}}
413# \brief : compare the last modification time of two files
414#   it does $ledt cmp $right
415# \param $left
416# \param $right
417# \return -1 if $left is older than $right
418# \return  0 if $left has the same modification time as $right
419# \return  1 if $ledt is more recent than $right
420# --------------------------------------------------------------------------
421sub _last_modified # {{{
422{
423    my ($left,$right) = @_;
424    my @left_stat = stat($left);
425    my @right_stat = stat($right);
426    return 1 if ($left_stat[9] > $right_stat[9]);
427    return -1 if ($left_stat[9] < $right_stat[9]);
428    return 0;
429} # }}}
430# --------------------------------------------------------------------------
431# \brief returns the location of a file from a directory list
432# \param  $prog complete name (with extension) of the file to search for
433# \param  $dirs list of directory in a semi columns separed string
434#  \caveas : the function use %PATH% if the $dirs param is omitted or 'false'.
435# \return $ the directory name in the Unix way without last dir separator
436#           undef is returned is no occurence of the file was found.
437# --------------------------------------------------------------------------
438sub _which # {{{
439{
440    my ($prog,$dirs) = @_;
441    $dirs = $ENV{'PATH'} unless ($dirs);
442    foreach my $dir (split /;/,$dirs)
443    {
444        (-f "$dir\\$prog") && do { (my $udir = $dir) =~ s/\\/\//g; return $udir; };
445    }
446    return undef;
447} # }}}
448sub _dirname # {{{
449{
450    my ($path,$sep) = @_;
451    $sep = '/' unless ($sep);
452    $sep =~ s/^/\\/;
453    $path =~ s/[\w\d_\.\s-]+$sep?$// if ($path);
454    return $path;
455}
456# }}}
457
458# ==========================================================================
459sub _uninstallstring # {{{
460{
461    my ($uninstallprogkey,$uninstallinfokey) = @_;
462    $uninstallinfokey = "UninstallString" unless ($uninstallinfokey);
463    my $uninstallstring = $Registry->{"HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Uninstall/$uninstallprogkey/$uninstallinfokey"};
464    $uninstallstring =~ s/\"//g   if ($uninstallstring);
465    $uninstallstring =~ s/\\/\//g if ($uninstallstring);
466    return $uninstallstring;
467} # }}}
468sub _ReadHklmSoftware($$) # {{{
469{
470    my ($progkey,$infokey) = @_;
471    my $string = $Registry->{"HKEY_LOCAL_MACHINE/Software/$progkey/$infokey"};
472    $string =~ s/\"//g   if ($string);
473    $string =~ s/\\/\//g if ($string);
474    return $string;
475} # }}}
476# !
477# @brief extract some installation information from pkgconfig files
478sub _pkgconfig # {{{
479{
480    my ($pkgfile) = @_;
481    my $pkg_name;
482    my $pkg_version;
483    open PKG,$pkgfile or return undef;
484    while (<PKG>)
485    {
486        ( m/^Name:\s*(.*)\s*$/) && do {
487            $pkg_name = $1;
488            next;
489        };
490        ( m/^Version:\s(.*)\s*$/ ) && do {
491            $pkg_version = $1;
492            next;
493        };
494    }
495    close PKG;
496    return ($pkg_name,$pkg_version);
497} # }}}
498
499# --------------------------------------------------------------------------
500# Template management                                               PART_2_3
501# --------------------------------------------------------------------------
502# \brief callbacks function use for configuring created files
503#   There are use to replace the  @NAME@ variables
504#   The call returns the modified version of the string taken as input
505#   _cb_default is called when no callback is defined
506# \param  $ the line without the last '\n' to modify
507# \return $ the modified line
508# --------------------------------------------------------------------------
509
510sub _cb_default #{{{
511{
512    return shift;
513} #}}}
514sub _cb_config_ini #{{{
515{
516    my $l = shift;
517    READ_INI: {
518        last READ_INI if ($l =~ s/ GCCBASEDIR/ $config{'directories'}{'mingw'}/);
519        last READ_INI if ($l =~ s/ PERLBASEDIR/ $config{'directories'}{'perl'}/);
520        last READ_INI if ($l =~ s/ NSISBINDIR/ $config{'directories'}{'nsis'}/);
521        last READ_INI if ($l =~ s/ GETTEXT/ $config{'directories'}{'gettext'}/);
522        last READ_INI if ($l =~ s/ GTKBINDIR/ $config{'directories'}{'gtkbin'}/);
523        last READ_INI if ($l =~ s/ GTKDEVDIR/ $config{'directories'}{'gtkdev'}/);
524        last READ_INI if ($l =~ s/ BUILDDIR/ $config{'directories'}{'prefix'}/);
525        last READ_INI if ($l =~ s/ WINGRISBIDIR/ $config{'directories'}{'grisbi'}/);
526        last READ_INI if ($l =~ s/ CORE/ $config{'grisbi'}{'core'}/);
527        last READ_INI if ($l =~ s/ BUILD/ $config{'grisbi'}{'build'}/);
528        last READ_INI if ($l =~ s/ PATCH/ $config{'grisbi'}{'patch'}/);
529        last READ_INI if ($l =~ s/ GTKDEVVERS/ $config{'grisbi'}{'gtkdev'}/);
530        last READ_INI if ($l =~ s/ GTKBINVERS/ $config{'grisbi'}{'gtkbin'}/);
531        last READ_INI if ($l =~ s/ REQUIRE/ $config{'grisbi'}{'build'}/);
532    }
533
534    $l =~ s/\s+$//;
535    return $l;
536} #}}}
537sub _cb_config_h # {{{
538{
539     (my $l = shift ) =~ s/\@VERSION\@/$config{'grisbi'}{'core'} for Windows (GTK $config{'grisbi'}{'gtkdev'})/ ;
540    return $l;
541} # }}}
542sub _explode_po # {{{
543{
544    my ($ori,$m) = @_;
545    my @pos = _get_po_file_list("../po");
546    my $r = "";
547    if (@pos)
548    {
549        foreach my $po (@pos)
550        {
551            my $PO = uc $po;
552            ( $r .= $ori . "\n" ) =~ s/$m/$PO/g;
553        }
554    }
555    return $r;
556} # }}}
557sub _cb_config_nsh #{{{
558{
559    my $l = shift;
560    READ_NSH: {
561        last READ_NSH if ($l =~ s/\@CORE\@/$config{'grisbi'}{'core'}/);
562        last READ_NSH if ($l =~ s/\@BUILD\@/$config{'grisbi'}{'build'}/);
563        last READ_NSH if ($l =~ s/\@PATCH\@/$config{'grisbi'}{'patch'}/);
564        last READ_NSH if ($l =~ s/\@GTKVERS\@/$config{'grisbi'}{'gtkdev'}/);
565        last READ_NSH if ($l =~ s/\@GTKBINDIR\@/$config{'directories'}{'gtkbin'}/);
566        last READ_NSH if ($l =~ s/\@REQUIRE\@/$config{'grisbi'}{'require'}/);
567        foreach my $mask ("APP","ATK","GLIB","GTK")
568        {
569            ( $l =~ m/\@${mask}LOCALES\@/ ) && do {
570                $l = _explode_po($l,"\@${mask}LOCALES\@");
571                last READ_NSH;
572            };
573        }
574
575    }
576    $l =~ s/\s+$//;
577    return $l;
578} #}}}
579sub _cb_grisbi_private_h # {{{
580{
581    my $l = shift;
582    my ($major,$minor,$release ) = split /\./,$config{'grisbi'}{'core'};
583    $release =~ s/(\d).*$/$1/;
584    PRIVATE_H:
585    {
586        $l =~ s/\@MAJOR\@/$major/;
587        $l =~ s/\@MINOR\@/$minor/;
588        $l =~ s/\@RELEASE\@/$release/;
589        $l =~ s/\@PATCH\@/$config{'grisbi'}{'patch'}/;
590        last PRIVATE_H if ($l =~ s/\@CORE\@/$config{'grisbi'}{'core'}/);
591    }
592    $l =~ s/\s+$//;
593    return $l;
594} # }}}
595sub _cb_makefile # {{{
596{
597    my $l = shift;
598
599    READ_MAKE: {
600        last READ_MAKE if ($l =~ s/\@GCCBASEDIR\@/$config{'directories'}{'mingw'}/);
601        last READ_MAKE if ($l =~ s/\@GTKBASEDIR\@/$config{'directories'}{'gtkbin'}/);
602        last READ_MAKE if ($l =~ s/\@GTKDEVDIR\@/$config{'directories'}{'gtkdev'}/);
603        last READ_MAKE if ($l =~ s/\@PERLBASEDIR\@/$config{'directories'}{'perl'}/);
604        last READ_MAKE if ($l =~ s/\@BUILDDIR\@/$config{'directories'}{'prefix'}/);
605        last READ_MAKE if ($l =~ s/\@NSISBINDIR\@/$config{'directories'}{'nsis'}/);
606        last READ_MAKE if ($l =~ s/\@GETTEXTDIR\@/$config{'directories'}{'gettext'}/);
607        last READ_MAKE if ($l =~ s/\@INSTSRCDIR\@/$config{'directories'}{'installer'}/);
608        last READ_MAKE if ($l =~ s/\@CFLAGS\@/$config{'environment'}{'cflags'}/);
609        last READ_MAKE if ($l =~ s/\@LDFLAGS\@/$config{'environment'}{'ldflags'}/);
610        ( $l =~ /\@SRCS\@/ ) && do {
611            my $srcs = _get_c_file_list("../src");
612            $l =~ s/\@SRCS\@/$srcs/;
613            last READ_MAKE;
614        };
615        ( $l =~ /\@INCS\@/ ) && do {
616            my $incs;
617            my $ref = $config{'includes'}{'item'};
618            foreach my $item (@$ref)
619            {
620                $incs .= " \\\n". $item;
621            }
622            $l =~ s/\@INCS\@/$incs/;
623            last READ_MAKE;
624        };
625        ( $l =~ /^VPATH.*\@PLUGINS\@/ ) && do {
626            my $vpath = "";
627            foreach my $p (keys %src_plugins)
628            {
629                $vpath .= " ../src/plugins/$p";
630            }
631            $l =~ s/\@PLUGINS\@/$vpath/;
632            last READ_MAKE;
633        };
634        ( $l =~ /^PLUGINS.*\@PLUGINS\@/ ) && do {
635            my $src_c = "";
636            foreach my $p (keys %src_plugins)
637            {
638                $src_c .= "$src_plugins{$p}{'sources'}{'ref'}" ;
639            }
640            $l =~ s/\@PLUGINS\@/$src_c/;
641            last READ_MAKE;
642        };
643        ( $l =~/^plugins:.*\@PLUGINS\@/ ) && do {
644            my $dep = "";
645            foreach my $p (keys %src_plugins)
646            {
647                $dep .= "\$(PLUGINSDIR)/$p.dll ";
648            }
649            $l =~ s/\@PLUGINS\@/$dep/;
650            last READ_MAKE;
651        };
652        ( $l =~ /\@LIBS\@/ ) && do {
653            my $libs;
654            my $ref = $config{'libraries'}{'item'};
655            foreach my $item (@$ref)
656            {
657                $libs .= " \\\n". $item;
658            }
659            $l =~ s/\@LIBS\@/$libs/;
660            last READ_MAKE;
661        };
662
663        ( $l =~ /\@WIN32\@/ ) && do {
664            my $win32 = _get_c_file_list("../win32");
665            $l =~ s/\@WIN32\@/$win32/;
666            last READ_MAKE;
667        };
668        ( $l =~ /\@LANGS\@/ ) && do {
669            my @pos = _get_po_file_list("../po");
670            if (@pos)
671            {
672                $l = "#! Build all supported languages files : " . join (',',@pos) ."\n";
673                $l   .= "lang  : " . join(' ',@pos) . "\n";
674
675                foreach my $po (@pos)
676                {
677
678                    $l .= "#! Build only the $po related files\n";
679                    $l .= "$po : \$(BUILDDIR)/lib/locale/$po/LC_MESSAGES/grisbi.mo\n";
680                }
681            }
682            else
683            {
684                $l = "lang:\n";
685                $l .= "\t\@echo \"No language files available\"\n\n";
686            }
687            last READ_MAKE;
688        };
689        ($l =~ /\@WINGRISBIDIR\@/ ) && do {
690            $l =~ s/\@WINGRISBIDIR\@/$config{'directories'}{'grisbi'}/;
691            $l =~ s:/:\\\\:g;
692        };
693        ($l =~ /\@NSISBINDIR\@/ ) && do {
694            $l =~ s/\@NSISBINDIR\@/$config{'directories'}{'nsis'}/ if (defined($config{'directories'}{'nsis'})) ;
695        };
696        ($l =~ /\@INSTSRCDIR\@/ ) && do {
697            $l =~ s/\@INSTSRCDIR\@/$config{'directories'}{'installer'}/ if (defined($config{'directories'}{'installer'})) ;
698        };
699
700    }
701
702    $l =~ s/\s+$//;
703    return $l;
704} # }}}
705#
706
707# --------------------------------------------------------------------------
708# grisbi.dev template callback {{{
709# --------------------------------------------------------------------------
710sub _dev_cpp_format_unit_section
711{
712    my ($unit,$file,$dir,$folder,$compile) = @_;
713
714    my $section = "[Unit$unit]\n";
715    $section .= "FileName=$dir\\$file\n";
716    $section .= "CompileCpp=0\n";
717    $section .= "Folder=$folder\n";
718    $section .= "Compile=$compile\n";
719    $section .= "Link=$compile\n";
720    $section .= "Priority=1000\n";
721    $section .= "OverrideBuildCmd=0\n";
722    $section .= "BuildCmd=\n";
723    $section .= "\n";
724    return $section;
725}
726
727my %project_files;
728
729sub _cb_grisbi_dev
730{
731    my $l = shift;
732
733    unless (%project_files)
734    {
735       %project_files = _get_files("../src");
736    }
737
738    READ_DEV:
739    {
740        last READ_DEV if ($l =~ s/\@#UNITS\@/$project_files{'num'}/);
741        ( $l =~ /\@UNITS\@/ ) && do {
742            $l = "";
743            my $i = 1;
744            foreach my $file (@{$project_files{'sources'}{'ref'}})
745            {
746                $l .= _dev_cpp_format_unit_section($i++,$file,'.\src','Sources',1);
747            }
748            foreach my $file (@{$project_files{'headers'}{'ref'}})
749            {
750                $l .= _dev_cpp_format_unit_section($i++,$file,'.\src','Headers',0);
751            }
752            foreach my $file (@{$project_files{'variables'}{'ref'}})
753            {
754                $l .= _dev_cpp_format_unit_section($i++,$file,'.\src','Sources',0);
755            }
756            foreach my $file (@{$project_files{'win32'}{'ref'}})
757            {
758                $l .= _dev_cpp_format_unit_section($i++,$file,'.\win32','Win32',0);
759            }
760            last READ_DEV;
761        };
762        ( $l =~ /\@CFLAGS\@/ ) && do {
763            my $cflags = $config{'environment'}{'cflags'};
764            foreach my $copt (@{$config{'includes'}{'item'}})
765            {
766                $cflags .= " ".$copt;
767            }
768            $cflags =~s/\//\\/g;
769
770            $l =~s/\@CFLAGS\@/$cflags/;
771            last READ_DEV;
772        };
773        ( $l =~ /\@LDFLAGS\@/ ) && do {
774            my $ldflags = $config{'environment'}{'ldflags'};
775            foreach my $ldopt (@{$config{'libraries'}{'item'}})
776            {
777                $ldflags .= " ".$ldopt;
778            }
779            $ldflags =~s/\s+/ _\@\@_/g ;
780            $ldflags =~s/\//\\/g;
781
782            $l =~s/\@LDFLAGS\@/$ldflags/;
783            last READ_DEV;
784        };
785    }
786
787    $l =~ s/\s+$//;
788    return $l;
789}
790# }}}
791# --------------------------------------------------------------------------
792# \brief the _configure function takes the template configuration data from
793#   the _DATA_ area of the script and create the corresponding file
794#
795# <file\s+name="" [src=""][ callback=""]>[\n.*\n]</file>
796#
797# \param $target
798# \param $callback
799#
800# \return $ 0 if the target file template as not been found
801# --------------------------------------------------------------------------
802sub _templates_configure # {{{
803{
804    my ($target,$callback) = @_;
805    my $found = 0;
806    my $src   = '__FILE__';
807    $callback = '_cb_default' unless (defined($callback));
808
809    #
810    READ_DATA: while (<DATA>)
811    {
812        last READ_DATA if (/^__END__/);
813
814        ( /^\<file\s+name="$target"/ ) && do {
815            $found    = 1;
816            $src      = $1 if ( /src="([\w\d\._-]*)"/ );
817            $callback = $1 if ( /callback="([\w\d\._-]*)"/ );
818
819            print "Generating $target \n" unless ($target eq $config_ini);
820            open FD,">$target" or do { warn "*** autogen.pl ERROR * Unable to create $target from $src : $@\n"; return;};
821
822            if ( $src ne '__FILE__')
823            {
824                open SRC,"$src" or do { warn "*** autogen.pl ERROR * Unable to load template $src : $@\n";return;};
825                LOAD_TEMPLATE: while (defined (my $line = <SRC>))
826                {
827                    chomp $line;
828                    $line = eval "$callback ".'$line';
829                    print FD $line."\n";
830                }
831                close SRC;
832            }
833            else
834            {
835                next READ_DATA;
836            }
837        };
838
839        ( /\<\/file\>/ ) && do {
840            if ($found)
841            {
842                close FD;
843                last READ_DATA;
844            }
845        };
846
847        next READ_DATA if (!$found);
848
849        chomp;
850        $_ = eval "$callback ".'$_';
851        print FD $_."\n";
852    }
853
854    return ($found);
855
856} # }}}
857# --------------------------------------------------------------------------
858#   Extract from _DATA_ part the file of templates available
859#   Exclude the autogen.ini line from the result
860#
861# \return @ list of template description lines
862# --------------------------------------------------------------------------
863sub _templates_get_targets_list() # {{{
864{
865    my @templates = ();
866    my $data = 0;
867    open FD,$0 or die "autogen.pl *** ERROR * Unable to read $0 : $@\n";
868    SEEK2DATA: while (defined($_ = <FD>)) { next SEEK2DATA unless ( /^__DATA__/) ; last SEEK2DATA; }
869
870    READ_DATA: while (defined ($_ = <FD>))
871    {
872        last READ_DATA if ( /^__END__/ );
873        #push @templates,($1) if ( /^\<file\s+name="([\w\d\._-]*)"/ );
874        if ( /^\<file\s+name="([\w\d\.\\\/_-]*)"/ )
875        {
876            next READ_DATA if ($1 eq "$config_ini");
877            push @templates,($1) ;
878        }
879    }
880    close FD;
881    return @templates;
882
883} # }}}
884
885sub _templates_clean # {{{
886{
887    return 0;
888} # }}}
889# ------------------------------------------------------------------------
890#   Extract from _RUNTIME_ part the file of targets available
891#
892# \return @ list of targets description lines
893# --------------------------------------------------------------------------
894sub _runtime_get_targets_list() # {{{
895{
896    my @templates = ();
897    my $data = 0;
898    open FD,$0 or die "autogen.pl *** ERROR * Unable to read $0 : $@\n";
899    SEEK2DATA: while (defined($_ = <FD>)) { next SEEK2DATA unless ( /^__DATA__/) ; last SEEK2DATA; }
900
901    READ_DATA: while (defined ($_ = <FD>))
902    {
903        last READ_DATA if ( /^__END__/ );
904        #push @templates,($1) if ( /^\<file\s+name="([\w\d\._-]*)"/ );
905        if ( /^\<file\s+name="([\w\d\._-]*)"/ )
906        {
907            next READ_DATA if ($1 eq "$config_ini");
908            push @templates,($1) ;
909        }
910    }
911    close FD;
912    return @templates;
913
914} # }}}
915sub _runtime_configure # {{{
916{
917    my ($targets) = @_;
918    $targets = join ':', qw/build plugins libraries pixmaps help dtd/ unless $targets;
919my $gtkcompliant   = 0;
920my $runtime_prefix = 0;
921my $target_found   = 0;
922my $with_target_dest=0;
923my $dest_dir       = "";
924    open FD,$0 or die "autogen.pl *** ERROR Unable to read $0 : $@\n";
925    SEEK2RUNTIME: while(<FD>) { next SEEK2RUNTIME unless ( /^#__RUNTIME__#/); last SEEK2RUNTIME;};
926    READ_RUNTIME: while(<FD>)
927    {
928        last READ_RUNTIME if ( /^__END__$/);
929        ( /^\<gtk\s+version=[\"\']?([\d\.\w-]*)[\"\']?/ ) && do {
930            my $gtkversion = $1;
931            if (($gtkversion =~ m/all/i )||($gtkversion eq $config{'grisbi'}{'gtkdev'}))
932            {
933                $gtkcompliant = 1;
934            }
935        };
936        ( /\<\/gtk\>/ ) && do { $gtkcompliant = 0; };
937       next READ_RUNTIME unless($gtkcompliant);
938
939       ( /^\s*\<prefix\>/ )   && do { $runtime_prefix = 1 ; };
940       ( /^\s*\<\/prefix\>/ ) && do { $runtime_prefix = 0 ; };
941
942       next READ_RUNTIME unless($runtime_prefix);
943
944       ( /^\s*\<target\s+name=([\/\w\d\.-]*)\s+(?:dest=([\/\"\'\$\{\}\w\d\s\.-]*))?/ ) && do {
945           my $target_name = $1;
946           $with_target_dest = (defined($2));
947           ($dest_dir = $2) =~ s/\s*$// if (defined($2));
948           $target_found = 1 if (grep { /$target_name/ } $targets);
949           if ($target_found)
950           {
951               eval "_cd(\"${builddir}/${dest_dir}\");" if ($with_target_dest);
952           }
953       };
954       (( $target_found ) && ( /^\s*<copy\s+(.*)\s*>(.*)<\/copy>/ )) && do
955       {
956           my $dest = $dest_dir;
957           my $filter = $2;
958           my %F ;
959           foreach my $kv (split /\s/,$1)
960           {
961               my ($k,$v) = split /=/,$kv;
962               $F{$k} = $v if defined($v);
963           }
964
965           $dest = $F{'dest'} if (defined($F{'dest'}));
966           eval "_cd(\"${builddir}/${dest}\")" if (defined($F{'dest'}));
967           if (defined($F{'ignore'}))
968           {
969                eval '_cp("$F{from}",$filter,$F{ignore});';
970            }
971            else
972            {
973                eval '_cp("$F{from}",$filter);';
974            }
975            _cd("..") if ((defined($F{'dest'}))&&($F{'dest'}));
976
977       };
978       ( /\<\/target\>/ ) && do {
979           if ($target_found)
980           {
981               _cd("..",'TRUE') if (($with_target_dest)&&($dest_dir));
982           }
983           $target_found     = 0;
984           $with_target_dest = 0;
985           $dest_dir         = undef;
986       };
987
988       next READ_RUNTIME unless($target_found);
989    }
990    close FD;
991    exit;
992} # }}}
993# }}}
994
995# --------------------------------------------------------------------------
996# Configuration functions
997# --------------------------------------------------------------------------
998sub _configuration_autodetect # {{{
999{
1000    # Mingw : in the path
1001    $config{'directories'}{'mingw'} =  _dirname _which 'gcc.exe'  unless ($config{'directories'}{'mingw'});
1002    die "*** ERROR *** autogen is not able to detect the location of gcc.exe\n\n \
1003        Please add the MinGw installation directory in your PATH\n" unless ($config{'directories'}{'mingw'});
1004
1005    # gettext
1006
1007    $config{'directories'}{'gettext'} = $config{'directories'}{'mingw'}."gettext/bin" if (-f $config{'directories'}{'mingw'}."gettext/bin/msgfmt.exe");
1008    $config{'directories'}{'gettext'} = _dirname _which 'msgfmt.exe'  unless ($config{'directories'}{'gettext'});
1009    die "*** ERROR autogen is not able to find msgfmt.exe\n\n \
1010        Please reinstall GNU Win32 gettext  or add msgfmt.exe installation directory in your PATH" unless ($config{'directories'}{'gettext'});
1011
1012    # Perl : in the path
1013    $config{'directories'}{'perl'}  =  _dirname _which 'perl.exe' unless ($config{'directories'}{'perl'});
1014
1015    # NSIS from PATH, then from registry
1016    $config{'directories'}{'nsis'} = _which 'makensis.exe' unless ($config{'directories'}{'nsis'});
1017    $config{'directories'}{'nsis'} = _dirname _uninstallstring "NSIS" unless ($config{'directories'}{'nsis'});
1018
1019    #
1020    # GTK runtime (GTK 2.4.14 official pack as to be installed)
1021    #
1022    # Old GTK 2.2.* version are no more supported ...
1023    #my $old_gtk_bin = _dirname _uninstallstring "GTK+ Runtime Environment_is1";
1024    #my $old_gtk_bver= _uninstallstring "GTK+ Runtime Environment_is1","DisplayVersion";
1025    #my $old_gtk_dev =  _dirname _uninstallstring "GTK+ Development Environment_is1";
1026    my $old_gtk_dver= _uninstallstring "GTK+ Development Environment_is1","DisplayVersion";
1027
1028
1029    #
1030    # GTK 2.4.14 or higher is required but not 2.6
1031    #
1032    $config{'directories'}{'gtkbin'} = _dirname _uninstallstring "WinGTK-2_is1" unless ($config{'directories'}{'gtkbin'});
1033    $config{'directories'}{'gtkbin'} = _dirname _uninstallstring "GTK 2.0" unless ($config{'directories'}{'gtkbin'});
1034
1035    die "*** ERROR *** autogen is not able to find any GTK2  binary packages on yout host\n\n \
1036        Please install GTK " . $GTKBIN_RECOMMENDED{'maj'}.".".$GTKBIN_RECOMMENDED{'min'}.".".$GTKBIN_RECOMMENDED{'rel'}.
1037        " or ".$GTKBIN_RECOMMENDED{'maj'}.".".$GTKBIN_RECOMMENDED{'min'} ." higher version from http://www.gtk.org/win32/\n" unless $config{'directories'}{'gtkbin'};
1038
1039
1040    my $gtkbinvers;
1041    $gtkbinvers =  _uninstallstring "WinGTK-2_is1","DisplayName"; # gtk from gimp
1042    $gtkbinvers =  _ReadHklmSoftware ("GTK/2.0","Version") unless ($gtkbinvers); # gtk from gaim
1043
1044    $gtkbinvers =~ s/^.*((\d)\.(\d+).(\d+)).*$/$1/;
1045
1046    die "*** ERROR *** Gtk+ version $gtkbinvers is not supported for building Grisbi\n\n \
1047        Please use GTK+ version 2.8.x (x>=7) (from http://www.gtk.org/win32) [$2!=2]\n" if ($2 != 2);
1048
1049        #warn "*** ERROR *** Gtk+ version $gtkbinvers is not yet supported for building Grisbi\n\n \
1050        #Please use GTK+ version 2.6.x (x>=8) (from http://www.gtk.org/win32) [$3>6]\n" if ($3 > 6);
1051
1052    die "*** ERROR *** Gtk+ version $gtkbinvers is no more supported for building Grisbi\n\n \
1053        Please use GTK+ version 2.6.x (x>=8) (from http://www.gtk.org/win32) [$3<4]\n" if ($3 < 6);
1054
1055    die "*** ERROR *** Gtk+ version $gtkbinvers is no more supported for building Grisbi\n\n \
1056        Please use GTK+ version 2.6.x (x>=9) (from http://www.gtk.org/win32) [[$3==4]&&[$4<14]}\n" if (($3 == 4)&&($4 < 14));
1057
1058    #
1059    my ($pkgn,$gtkdevvers) = _pkgconfig($config{'directories'}{'mingw'}."/lib/pkgconfig/gtk+-2.0.pc");
1060    die "*** ERROR *** Unable to detect GTK+ development version\n\n \
1061        Please reinstall GTK+ 2.4.x (x>=14) DevPack\n" if (not defined($pkgn) or not defined($gtkdevvers));
1062
1063    die "*** ERROR *** Unable to determine GTK+ development version\n\n \
1064        Please reinstall GTK+ 2.6.x (x>=8) DevPack\n" unless ($gtkdevvers =~ m/((\d)\.(\d+)\.(\d+))/ );
1065
1066    die "*** ERROR *** Gtk+ dev version $gtkdevvers  is not supported for building Grisbi\n\n \
1067        Please reinstall GTK+ 2.6.x (x>=8) DevPack\n" if ($2 != 2);
1068
1069    warn "*** ERROR *** Gtk+ dev version $gtkdevvers is not yet supported for building Grisbi\n\n \
1070        Please prefer GTK+ ".$GTKBIN_RECOMMENDED{'maj'}.".".$GTKBIN_RECOMMENDED{'min'}.".x (x>=8) DevPack\n" if ($3 > $GTKBIN_RECOMMENDED{'min'} );
1071
1072    die "*** ERROR *** Gtk+ dev version $gtkdevvers is no more supported for building Grisbi\n\n \
1073        Please reinstall GTK+ 2.6.x (x>=8) DevPack\n" if ($3 < 6);
1074
1075    die "*** ERROR *** Gtk+ dev version $gtkdevvers is no more supported for building Grisbi\n\n \
1076        Please reinstall GTK+ 2.6.x (x>=8) DevPack\n" if (($3 == 4)&&($4 < 14));
1077
1078    $config{'directories'}{'gtkdev'} = $config{'directories'}{'mingw'};
1079
1080    #
1081    # Other usefull location
1082    #
1083    $config{'directories'}{'prefix'} = "../build" unless ($config{'directories'}{'prefix'});
1084    $config{'directories'}{'grisbi'} = dirname(getcwd()) unless ($config{'directories'}{'grisbi'});
1085
1086    # Extract version number from pwd
1087    (my $core = basename dirname getcwd() ) =~ s/^grisbi-//;
1088    # if version can not be found from directory name grisbi-unstable ....
1089    my ($major,$minor,$release ) = (undef,undef,undef);
1090    ($major,$minor,$release ) = split /\./,$core if ($core);
1091    if (not (defined($major) and defined($minor) and defined($release)))
1092    {
1093        my $l;
1094        open CONFIGURE_IN,"../configure.in" or die "Unable to open configure.in to get version number";
1095        while ($l = <CONFIGURE_IN>) { last if ($l =~ m/AM_INIT_AUTOMAKE/);}
1096        close CONFIGURE_IN;
1097        chomp $l;
1098        $l =~ s/.*(\d\.\d\.\d).*/$1/ if (defined($l));
1099        $core = $l."-$core";
1100    }
1101    $config{'grisbi'}{'core'} = $core unless ($config{'grisbi'}{'core'});
1102
1103    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
1104    $year %= 100; # localtime year is 00..99 from year 1900..1999 and 1xx for year 20xx
1105    $mon++;       # localtime month is 0..11
1106    $year =~ s/^(\d)$/0$1/;
1107    $mon  =~ s/^(\d)$/0$1/;
1108    $mday =~ s/^(\d)$/0$1/;
1109
1110    $config{'grisbi'}{'build'} = "$year$mon$mday" unless ($config{'grisbi'}{'build'});
1111    $config{'grisbi'}{'patch'} = "$year$mon$mday" unless ($config{'grisbi'}{'patch'});
1112
1113    $config{'grisbi'}{'gtkdev'} = "$gtkdevvers" unless ($config{'grisbi'}{'gtkdev'});
1114    $config{'grisbi'}{'gtkbin'} = "$gtkbinvers" unless ($config{'grisbi'}{'gtkbin'});
1115} # }}}
1116sub _configuration_check # {{{
1117{
1118    unless ($config{'directories'}{'gtkbin'})
1119    {
1120        print "*** ERROR *** Unable to detect gtk runtime files location\n";
1121        print "   Please edit autogen.ini to set the 'gtkbin' of the 'directories section' with the correct value\n";
1122        die "\n";
1123    }
1124    unless ($config{'directories'}{'gtkdev'})
1125    {
1126        print "*** ERROR *** Unable to detect gtk development files location\n";
1127        print "   Please edit autogen.ini to set the 'gtkdev' of the 'directories section' with the correct value\n";
1128        die "\n";
1129    }
1130    die "Unable to determine prefix directory name, please edit $config_ini\n"   unless ( $config{'directories'}{'prefix'} );
1131    die "gtk runtime directory is empty, please edit $config_ini\n" unless ( $config{'directories'}{'gtkbin'} );
1132    die "mingw directory  is empty, please edit $config_ini\n" unless ( $config{'directories'}{'mingw'} );
1133    #die "no target defined, please use configure.pl or make \n" unless ($targets);
1134
1135} # }}}
1136
1137# ==========================================================================
1138# __MAIN___                                              {{{ PART_3
1139# ==========================================================================
1140
1141# Load config.ini if any
1142tie %config, 'TieIniFile', READ => $config_ini if (-f $config_ini);
1143
1144my $opt_help      = undef;
1145my $opt_usage     = undef;
1146my $opt_force     = undef;
1147my $opt_prefix    = $config{'directories'}{'prefix'};
1148my $opt_npatch    = undef;
1149my $opt_runtime   = undef;
1150my $opt_templates = undef;
1151my $opt_clean     = undef;
1152
1153# Commmand lines arguments management {{{
1154GetOptions(
1155    "h|?"         => \$opt_usage,
1156    "help|aide"   => \$opt_help,
1157    "force|f"     => \$opt_force,
1158    "prefix=s"    => \$opt_prefix,
1159    "new-patch"   => \$opt_npatch,
1160    "runtime"     => \$opt_runtime,
1161    "templates"   => \$opt_templates,
1162) or pod2usage(2);
1163
1164# Check arguments value
1165pod2usage(verbose=>1,exit_status=>0) if $opt_usage;
1166pod2usage(verbose=>2,exit_status=>0) if $opt_help;
1167pod2usage(verbose=>1,exit_status=>1) if ($opt_runtime and $opt_templates );
1168
1169#default action is template creation
1170$opt_templates = 'default' if (!$opt_runtime and !$opt_templates );
1171
1172# reconfigure configuration depending arg lines
1173$config{'grisbi'}{'patch'} = undef if ($opt_npatch);
1174
1175#
1176# }}}
1177
1178_configuration_autodetect;
1179
1180#  * First in a clean directory : create ini and ask to complete it
1181if ((! -f $config_ini)||($opt_npatch))
1182{
1183    _templates_configure($config_ini,'_cb_config_ini') or die "autogen.pl *** ERROR * Unable to create $config_ini: $@\n";
1184    print "Your $config_ini file has been created, please check it and restart the autogen.bat command\n";
1185    exit;
1186}
1187
1188_configuration_check;
1189
1190#
1191# Build runtime environnement in the prefix directory only if $opt_runtime
1192#
1193if ($opt_runtime)
1194{
1195    $builddir   = $config{'directories'}{'prefix'};
1196    $gtkdevdir  = $config{'directories'}{'gtkdev'};
1197    $gccbasedir = $config{'directories'}{'mingw'};
1198    $grisbidir  = $config{'directories'}{'grisbi'};
1199    $startdir   = $g_outdir;
1200    _runtime_configure join ':',@ARGV
1201}
1202
1203#
1204# Configure the files from the template
1205#
1206if ($opt_templates)
1207{
1208    TEMPLATES_ARGV: foreach (@ARGV)
1209    {
1210        ( /^clean$/ ) && do { $opt_clean = 1; next TEMPLATES_ARGV; };
1211        push @targets,($_) ;
1212    }
1213    @targets = _templates_get_targets_list() if ($#targets < 0);
1214
1215    foreach my $target ( @targets )
1216    {
1217        if (($opt_force)&&($opt_clean)&&(-f $target))
1218        {
1219            _templates_clean($target) or warn "*** autogen.bat WARNING * Unable to remove $target ***\n";
1220        }
1221        elsif (($opt_force)||(!-f $target)|| (_last_modified($config_ini,$target) == 1))
1222        {
1223            %src_plugins = _get_plugins_list("../src/plugins");
1224            _templates_configure($target) or warn "*** autogen.bat ERROR * Unable to found a template for $target***\n";
1225        }
1226    }
1227}
1228
12290;
1230
1231# }}}
1232
1233# ==========================================================================
1234# _TEMPLATES_
1235# ==========================================================================
1236__DATA__
1237<file name="autogen.ini" callback="_cb_config_ini" >  {{{
1238[grisbi]
1239core      = CORE
1240build     = BUILD
1241patch     = PATCH
1242require   = BUILD
1243gtkdev    = GTKDEVVERS
1244gtkbin    = GTKBINVERS
1245
1246[environment]
1247compiler  = gcc ; only gcc is supported yet
1248cflags    = -Wall \$(INCS) -D _WIN32 -mms-bitfields -g -D _WIN32_IE=0x0410
1249ldflags   = -L\"\$(GCCBASEDIR)/lib\" -L\"\$(GTKDEVDIR)/lib/\" -mwindows
1250
1251[includes]
1252item[0] = -I\"../win32\" -I\"../src\"
1253item[1] = -I\"\$(GCCBASEDIR)/include\"
1254item[2] = -I\"\$(GTKDEVDIR)/include\"
1255item[3] = -I\"\$(GTKDEVDIR)/lib/glib-2.0/include\" -I\"\$(GTKDEVDIR)/include/glib-2.0\"
1256item[4] = -I\"\$(GTKDEVDIR)/lib/gtk-2.0/include\" -I\"\$(GTKDEVDIR)/include/gtk-2.0\"
1257item[5] = -I\"\$(GTKDEVDIR)/include/atk-1.0\" -I\"\$(GTKDEVDIR)/include/pango-1.0\" -I\"\$(GTKDEVDIR)/include/cairo\"
1258item[6] = -I\"\$(GTKDEVDIR)/include/libiconv-1.9.1\"
1259item[7] = -I\"\$(GTKDEVDIR)/include/libxml2-2.4.12\"
1260
1261[libraries]
1262item[0] = -latk-1.0 -lpango-1.0 -lpangowin32-1.0 -lpangoft2-1.0
1263item[1] = -lglib-2.0 -lgobject-2.0  -lgmodule-2.0  -lgthread-2.0
1264item[2] = -lgtk-win32-2.0 -lgdk-win32-2.0 -lgdk_pixbuf-2.0
1265item[3] = -lintl -liconv -lz -lcrypto
1266item[4] = \$(GTKDEVDIR)/lib/libxml2.lib
1267item[5] = \$(GTKDEVDIR)/lib/libofx.lib
1268
1269[directories]
1270gtkdev    = GTKDEVDIR
1271gtkbin    = GTKBINDIR
1272perl      = PERLBASEDIR
1273mingw     = GCCBASEDIR
1274nsis      = NSISBINDIR
1275gettext   = GETTEXT
1276prefix    = BUILDDIR
1277grisbi    = WINGRISBIDIR
1278installer =
1279</file> # }}}
1280<file name="Grisbi_private.rc"> {{{
1281// THIS FILE WILL BE OVERWRITTEN BY DEV-C++!
1282// DO NOT EDIT!
1283
1284
1285A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "Grisbi.ico"
1286</file> }}}
1287<file name="Grisbi_private.h" callback="_cb_grisbi_private_h"> {{{
1288// THIS FILE WILL BE OVERWRITTEN BY DEV-C++!
1289// DO NOT EDIT!
1290
1291#ifndef GRISBI_PRIVATE_H
1292#define GRISBI_PRIVATE_H
1293
1294// VERSION DEFINITIONS
1295#define VER_STRING	"@MAJOR@.@MINOR@.@RELEASE@.@PATCH@"
1296#define VER_MAJOR	@MAJOR@
1297#define VER_MINOR	@MINOR@
1298#define VER_RELEASE	@RELEASE@
1299#define VER_BUILD	@PATCH@
1300#define COMPANY_NAME	"grisbi.org"
1301#define FILE_VERSION	""
1302#define FILE_DESCRIPTION	"Personal accounting software using GTK under GPL Licence (ported on Windows using the Dev-C++ IDE)"
1303#define INTERNAL_NAME	        "Grisbi"
1304#define LEGAL_COPYRIGHT	        "2004 grisbi.org"
1305#define LEGAL_TRADEMARKS	"grisbi.org"
1306#define ORIGINAL_FILENAME	"grisbi.exe"
1307#define PRODUCT_NAME	        "Grisbi"
1308#define PRODUCT_VERSION	        "@CORE@"
1309
1310#endif //GRISBI_PRIVATE_H
1311</file> }}}
1312<file name="config.h"   src="config-win32.in" callback="_cb_config_h"></file>
1313<file name="Makefile"   src="Makefile-win32.am" callback="_cb_makefile"></file>
1314<file name="../Grisbi.dev" src="grisbi.dev.in" callback="_cb_grisbi_dev"></file>
1315<file name="config.nsh" src="config-nsh.in" callback="_cb_config_nsh"></file>
1316__END__
1317# }}}
1318# ==========================================================================
1319#__RUNTIME__# {{{
1320<gtk version="all">
1321<prefix>
1322    <target name=build dest= ></target>
1323    <target name=plugins dest=plugins ></target>
1324    <target name=libraries  dest= >
1325        <copy from=${gtkdevdir}/bin >osp151.dll</copy>
1326        <copy from=${gtkdevdir}/bin >libofx.dll</copy>
1327        <copy from=${gtkdevdir}/bin >libintl-2.dll</copy>
1328        <copy from=${gtkdevdir}/bin >libiconv-2.dll</copy>
1329        <copy from=${gtkdevdir}/bin >libxml2.dll</copy>
1330        <copy from=${gtkdevdir}/gettext/bin >libintl3.dll</copy>
1331        <copy from=${gtkdevdir}/gettext/bin >libiconv2.dll</copy>
1332    </target>
1333    <target name=dtd  dest=dtd>
1334        <copy from=${gtkdevdir}/bin/dtd ignore=['.git','Makefile','topic']>.</copy>
1335    </target>
1336    <target name=help  dest=help>
1337        <copy from=${grisbidir}/help ignore=['.git','Makefile','topic']>.</copy>
1338    </target>
1339    <target name=pixmaps  dest=pixmaps>
1340        <copy from=${grisbidir}/pixmaps ignore=['.git','Makefile','topic']>.</copy>
1341    </target>
1342</prefix>
1343</gtk>
1344__END__
1345# }}}
1346# ==========================================================================
1347# INLINE DOCUMENTATION                                 {{{ PART_5
1348# ==========================================================================
1349=head1 NAME
1350
1351autogen.bat - Perl script to configure Grisbi for Windows build environment
1352
1353=head1 SYNOPSIS
1354
1355autogen.bat [-f] [clean]
1356
1357autogen.bat [-h|--help]
1358
1359autogen.bat [-f]
1360
1361autogen.bat [-runtime [[obj] [help] [pixmaps] [dlls] [lib] [it] [fr]]]
1362
1363=head1 OPTIONS
1364
1365=over 8
1366
1367=item B<-h>
1368
1369Print a brief help message with command line syntax summary and exit.
1370
1371=item B<--help>
1372
1373Print this complete help message and exit
1374
1375=back
1376
1377=head1 DESCRIPTION
1378
1379    B<This program> is used to configure the build environment of Grisbi for
1380    Windows. It creates all needs files and configures them .
1381
1382=head2 autogen.ini
1383    All common information about the builded version and tools configuration
1384    are stored in the autogen.ini file created by the first run of the script.
1385
1386=head2 created files
1387
1388=back
1389=cut
1390
1391#}}}
1392# ==========================================================================
1393# vim:sts=4:ft=perl:
1394
1395__END__
1396:endofperl
1397
1398