summaryrefslogtreecommitdiff
path: root/tools/gmmproc.in
blob: 9b4f55495843d11a086701bded6443af6853ca8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#! @PERL_PATH@
#
# @configure_input@
#
######################################################################
# gmmproc (version 4)
######################################################################
#
# *** WARNING: Only modify gmmproc.in. gmmproc is built. ***
#
# Copyright 2001, Karl Einar Nelson, Murray Cumming
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or 
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
# GNU General Public License for more details. 
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
#
# 'classes':
# WrapParser: steps through .hg and .ccg files, outputting appropriate m4 code with Outputter.
# Outputter: Used by WrapParser to ouput wrapper code. Ouputs *.g1 temp file and uses m4 to generate *.g2 from it. Then outputs .h and .cc files.
# Function: Contains information about C and C++ functions and signals.
#
######################################################################

########################## 'main()' ##################################

$main::procdir;
$main::m4path;

BEGIN {
  # get prefix info from configure
  my $prefix = "@prefix@";
  my $exec_prefix = "@exec_prefix@";
  my $libdir = "@libdir@";

  # This line must match the install directory in m4/Makefile.am
  $main::procdir = "$libdir/glibmm-2.4/proc";
  $main::m4path = "@M4@";

  # This line must match install dir from pm/Makefile.am
  push @INC,"$main::procdir/pm";
}

use strict;
use warnings;

use Output;
use WrapParser;

# initialize globals 
@main::macrodirs = ();
$main::srcdir = ".";
$main::defsdir = ".";
$main::source = "";
$main::debug = 0;
$main::unwrapped = 1;
$main::mergecdocs = 0; # e.g. gtk_docs.xml, contain C comments to be added to our generated C++ code.

{ # checking the environment for a set variable can trigger a warning
  no warnings;
  $main::debug = 1 if ($ENV{'GMMPROC_DEBUG'} eq 1);
}

# prototypes
sub parse_command_line_args();


#main()
parse_command_line_args();

my $objOutputter = &Output::new($main::m4path, \@main::macrodirs);
my $objWrapParser = &WrapParser::new($objOutputter);

$$objWrapParser{srcdir} = $main::srcdir;
$$objWrapParser{defsdir} = $main::defsdir;
$$objWrapParser{source} = $main::source;
$$objOutputter{source} = $main::source;
$$objOutputter{destdir} = $ARGV[1];


if($main::mergecdocs eq 1)
{
  $$objWrapParser{mergecdocs} = 1;
}

# Suck the whole file into one big string, breaking it into tokens:
$objWrapParser->read_file($main::srcdir, $main::source);

# Parse output 
$objWrapParser->parse_and_build_output();

# Write out *.g1 temporary file:
$objOutputter->output_temp_g1($$objWrapParser{module}); # e.g. "gtk"

# Execute m4 to get *.g2 file:
{
  my $exitcode = $objOutputter->make_g2_from_g1();
  if ($exitcode != 0)
  {
    if (!$main::debug)
    {
      $objOutputter->remove_temp_files();
    }
    print STDERR "m4 failed with exit code $exitcode.  Aborting...\n";
    exit ($exitcode);
  }
}

# Section out the resulting output
$objOutputter->write_sections_to_files();

# Remove temp files.
if (!$main::debug)
{
  $objOutputter->remove_temp_files();
}

#Warn about any unwrapped function/signals:
if ($main::unwrapped)
{ 
  my @unwrapped = GtkDefs::get_unwrapped();
  if (@unwrapped)
  {
    no warnings;

    my @methods =
      grep {$$_{entity_type} eq "method" & $$_{c_name}!~/^_/ } @unwrapped;
    my @signals =
      grep {$$_{entity_type} eq "signal"} @unwrapped;
    my @properties =
      grep {$$_{entity_type} eq "property"} @unwrapped;

    if (@methods)
    { 
      print "Unwrapped functions:\n";
      map { print "  $$_{c_name}\n"} @methods;
    }
    if (@properties)
    { 
      print "Unwrapped properties:\n";
      map { print "  $$_{class}::$$_{name}\n"} @properties;
    }
    if (@signals)
    { 
      print "Unwrapped signals:\n";
      map { print "  $$_{class}::$$_{name}\n"} @signals;
    }
  }
}

# end of program
exit();


####################################################################


sub print_usage()
{
  print
'Usage: gmmproc [options] name srcdir destdir
  -h 
  --help      This usage message.

  --doc       Produces a header file for documentation.  (FIXME)

  --debug     Leave intermediate output arround for analysis.
              Alternatively, set GMMPROC_DEBUG=1 in the environment.

  --unwrapped Warn about possible unwrapped functions.
 
  --defs dir  Change the directory to seach for defs.

  -I dir      Specify the directory with m4 files.


Note: This will read srcdir/name.{hg,ccg} file and generates destdir/name.cc
';
  exit (1);
}

# void parse_command_line_args()
sub parse_command_line_args()
{
  print_usage() if ($#ARGV == -1);
  
  while ($#ARGV != -1)
  {
    $_ = shift @ARGV;

    if (/^-/)
    {
      print_usage() if ( /^--help/);
      print_usage() if ( /^-h/);
      if (/^-I/)
      {
        push @main::macrodirs, shift @ARGV;
      }
      elsif (/^--mergecdocs/)
      {
        $main::mergecdocs = 1
      }
      elsif (/^--unwrapped/)
      {
        $main::unwrapped = 1;
      }
      elsif (/^--defs/)
      {
        $main::defsdir = shift @ARGV;
      }
      elsif (/^--debug/)
      {
        $main::debug = 1;
      }
      else
      {
        print "unknown parameter $_\n";
      }
      next;
    }

    last;
  }

  # we already have one argument

  if ($#ARGV != 1)
  {
    print STDERR "Invalid number of arguments (", $#ARGV+2, ")\n";
    print_usage();
  }

  $main::srcdir = $ARGV[0];
  $main::source = $_;

  push @main::macrodirs,"$main::procdir/m4";
}