forked from ViewTouch/viewtouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·337 lines (301 loc) · 10.3 KB
/
configure
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/usr/bin/perl -w
# --------------------------------------------------------------------
# Module: configure
# Description: simple script to sort of mimic autoconf.
# Author: Bruce Alon King
# Created: Thu Apr 4 11:12:13 2002
# --------------------------------------------------------------------
# ####################################################################
# INITIALIZATION AND GLOBAL VARIABLES
# ####################################################################
use strict;
use vars qw/$hostname $license_server/;
BEGIN {
# $hostname = `hostname`;
# $hostname =~ /^\s+|\s+$/gs;
# if ( $hostname =~ /mainbox|debian/ ) {
# $license_server = "localhost";
# } elsif ( $hostname =~ /arachne|asgard/ ) {
# $license_server = "localhost";
# } elsif ( $hostname =~ /wincor|linux/ ) {
# $license_server = "mainbox.viewtouch.com";
# } else {
# $license_server = "";
# }
# $license_server = "vtweb";
$license_server = "viewtouch.com";
};
use Getopt::Std;
# configuration options (file and/or command line)
my $gcc = "";
my @configfiles = qw|/etc/vtmake_config HOME/.vtmake_config|;
readConfigFiles( \@configfiles );
my $cmdoptions = "g:hl:";
my %opts;
getopts( $cmdoptions, \%opts );
showHelp() if ( $opts{'h'} );
$gcc = $opts{'g'} if ( $opts{'g'} );
$license_server = $opts{'l'} if ( $opts{'l'} );
my $gpp = "g++";
my $platform = ( `uname` ); chomp( $platform );
my $configurein = "configure.in";
my $makefilein = "Makefile.in";
my $makefileout = "Makefile";
my $makelinestart = "# System Settings Start";
my $makelineend = "# System Settings End";
my $mode = "";
my $gccversion = "";
if ( $gcc ) {
$gccversion = "gcc$gcc";
$gpp = "g++$gcc";
} else {
$gccversion = `gcc -v 2>&1`;
if ( $gccversion =~ /gcc version ([\d\.]+)/s ) {
$gccversion = $1;
}
$gccversion = "gcc$gccversion";
}
$gccversion =~ s/\.//g;
# ####################################################################
# MAIN LOOP
# ####################################################################
my $config = readConfig( $configurein, $platform );
my $incdirs = getIncDirs( $$config{'incdirs'} );
my $options = getOptions( \@ARGV, $$config{'defaults'}, $$config{'options'} );
my $settings = buildSettings( $$config{'mode'}, $incdirs, $options );
my $makefile = readFile( $makefilein );
insertConfig( \$makefile, $settings );
changeTarget( \$makefile, $mode );
printFile( $makefileout, $makefile );
system( "make dep >dep.log 2>&1" );
system( "make clean >/dev/null 2>&1" );
# ####################################################################
# SUBROUTINES
# ####################################################################
# --------------------------------------------------------------------
# showHelp:
# --------------------------------------------------------------------
sub showHelp {
print STDERR "Usage: ./configure\n";
print STDERR "OPTIONS:\n";
print STDERR " -g <version> Which GCC version to use.\n";
print STDERR "<debug|release>\n";
print STDERR " debug Build a release version of the binary\n";
print STDERR " release Build a release version of the binary\n";
print STDERR "<nocredit|mcve|cheq>\n";
print STDERR " nocredit Do not add credit card support\n";
print STDERR " mcve Add credit card support with MCVE\n";
print STDERR " cheq Add credit card support with CreditCheq\n";
print STDERR "\n";
exit( 1 );
}
#-----------------------------------------------------------------------
# readConfigFiles:
#-----------------------------------------------------------------------
sub readConfigFiles {
my ( $files ) = @_;
foreach ( @$files ) {
my $file = $_;
$file =~ s/HOME/$ENV{'HOME'}/;
if ( -f $file ) {
readConfigFile( $file );
}
}
}
#-----------------------------------------------------------------------
# readConfigFile:
#-----------------------------------------------------------------------
sub readConfigFile {
my ( $file ) = @_;
if ( open( FILE, $file ) ) {
while ( <FILE> ) {
my $line = $_;
if ( $line =~ /^([^:]+):\s+(.*)$/ ) {
my ( $key, $value ) = ( $1, $2 );
setConfig( $key, $value );
}
}
close( FILE );
} else {
print "Could not read config file $file: $!\n";
}
}
#-----------------------------------------------------------------------
# setConfig:
#-----------------------------------------------------------------------
sub setConfig {
my ( $key, $value ) = @_;
if ( $key eq "gccversion" ) {
$gcc = $value;
} elsif ( $key eq "licenseserver" ) {
$license_server = $value;
} else {
print "Unknown Key '$key', value '$value'\n";
}
}
# --------------------------------------------------------------------
# readConfig:
# --------------------------------------------------------------------
sub readConfig {
my ( $file, $platform ) = @_;
my %config;
my %options;
my $contents = readFileArray( $file );
while ( @$contents ) {
my $line = shift( @$contents );
chomp( $line );
if ( $line =~ /^\#\#\#\s+$platform\s+Mode\s+\#\#\#/ ) {
$config{'mode'} = readBlock( $contents, "Mode" );
} elsif ( $line =~ /^\#\#\#\s+($platform\s+)?Defaults\s+\#\#\#/ ) {
$config{'defaults'} = readBlock( $contents, "Defaults" );
} elsif ( $line =~ /^\#\#\#\s+($platform\s+)?IncDirs\s+\#\#\#/ ) {
$config{'incdirs'} = readBlock( $contents, "IncDirs" );
} elsif ( $line =~ /^\#\#\#\s+($platform\s+)?Option\s+(\S+)\s+\#\#\#/ ) {
my $option = $2;
$options{lc($option)} = readBlock( $contents, $option );
}
}
$config{'options'} = \%options;
return( \%config );
}
# --------------------------------------------------------------------
# readBlock:
# --------------------------------------------------------------------
sub readBlock {
my ( $lines, $blockname ) = @_;
my @lines;
my $done = 0;
while ( @$lines && !$done ) {
my $line = shift( @$lines );
chomp( $line );
if ( $line =~ /^\#\#\#\s+$blockname\s+End\s+\#\#\#/ ) {
$done = 1;
} else {
push( @lines, $line );
}
}
return( \@lines );
}
# --------------------------------------------------------------------
# getIncDirs:
# --------------------------------------------------------------------
sub getIncDirs {
my ( $incdirs ) = @_;
my $incs = "INCDIRS = ";
foreach ( @$incdirs ) {
my $dir = $_;
if ( $dir =~ s/^(gcc[\d\.]+)\s+// ) {
my $gcc = $1;
if ( $gcc eq $gccversion && -d $dir ) {
$incs .= "-I$dir ";
} else {
print STDERR "Skipping Include Dir: '$dir'\n";
}
} elsif ( -d $dir ) {
$incs .= "-I$dir ";
} else {
print STDERR "Skipping Include Dir: '$dir'\n";
}
}
return( $incs );
}
# --------------------------------------------------------------------
# getOptions:
# --------------------------------------------------------------------
sub getOptions {
my ( $args, $defaults, $options ) = @_;
my $settings = "";
foreach ( @$defaults ) {
my $line = lc($_);
my @opts = split( /\s+/, $line );
my $option = "";
foreach ( @opts ) {
my $opt = lc($_);
if ( grep( $opt eq lc($_), @$args ) ) {
$option = $opt;
}
}
if ( $option eq "" ) {
$option = shift( @opts );
}
my @nonopts = grep( $option ne $_, @opts );
foreach ( @nonopts ) {
delete( $$options{$_} );
}
}
foreach ( sort keys %$options ) {
my $opts = $$options{$_};
foreach ( @$opts ) {
$settings .= "$_\n";
}
}
return( $settings );
}
# --------------------------------------------------------------------
# buildSettings:
# --------------------------------------------------------------------
sub buildSettings {
my ( $mode, $incdirs, $options ) = @_;
my $settings = "";
foreach ( @$mode ) {
$settings .= "$_\n";
}
$settings .= $incdirs . "\n";
$settings .= $options;
$settings =~ s/LICENSESERVERDEBUG/$license_server/gs;
return( $settings );
}
# --------------------------------------------------------------------
# insertConfig:
# --------------------------------------------------------------------
sub insertConfig {
my ( $makefile, $config ) = @_;
$$makefile =~ s/($makelinestart\s+).*?($makelineend)/$1$config$2/s;
$$makefile =~ s/GPP/$gpp/sg;
}
# --------------------------------------------------------------------
# changeTarget: replaces the "make all" dependency to make either
# debug or release, depending on what has been selected for
# configure.
# --------------------------------------------------------------------
sub changeTarget {
my ( $makefile, $target ) = @_;
$target = lc( $target );
$$makefile =~ s/all:\s+(debug|release)/all: $target/gs;
}
# --------------------------------------------------------------------
# readFile: just reads the file in and returns the contents as a
# reference to an array.
# --------------------------------------------------------------------
sub readFile {
my ( $name ) = @_;
my $contents = readFileArray( $name );
return( join( "", @$contents ) );
}
# --------------------------------------------------------------------
# readFileArray: just reads the file in and returns the contents as a
# reference to an array.
# --------------------------------------------------------------------
sub readFileArray {
my ( $name ) = @_;
my @contents;
if ( open( FILE, $name ) ) {
@contents = <FILE>;
close( FILE );
} else {
die "Could not read $name: $!\n";
}
return( \@contents );
}
# --------------------------------------------------------------------
# printFile:
# --------------------------------------------------------------------
sub printFile {
my ( $file, $contents ) = @_;
if ( open( FILE, ">$file" ) ) {
print FILE $contents;
close( FILE );
} else {
die "Could not write $file: $!\n";
}
}