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 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
|
#!/usr/bin/perl
use IO::Handle;
my $prefix = "/usr/local";
my $package = "eboard";
my $version = "0.9.5";
my $cxx = "g++";
my @cxxflags = ("-O2");
my @ldflags = ( );
my $configh = "config.h";
my $configmake = "config.make";
my $nls = 1;
# ------------
sub usage;
sub run_cmd;
sub cplusplus_lang;
sub install_util;
sub header_check;
sub header_def;
sub macro_check;
sub spaces;
sub version_cmp;
sub get_prog;
sub cppdef;
sub cppundef;
sub append_inc;
sub append_ld;
# ------------
sub usage {
print "configure options:\n";
print "\t--prefix=path install to given prefix instead of /usr/local\n";
print "\t--enable-debug compile with gdb debugging info\n";
print "\t--disable-nls disable translation support\n";
print "\t--extra-inc=list additional include file search paths, separated by :\n";
print "\t--extra-ld=list additional library search paths, separated by :\n";
print "\t--help show this usage help.\n\n";
exit 2;
}
sub run_cmd {
my @cmd;
my $pid, $r;
@cmd = @_;
$pid = fork;
if ($pid == 0) {
close(STDOUT);
close(STDERR);
open(STDOUT,">/dev/null");
open(STDERR,">/dev/null");
exec @cmd;
} else {
if ($pid > 0) {
$pid = waitpid($pid, 0);
$r = $? / 256;
return $r;
}
return -1;
}
}
sub cplusplus_lang {
my @compilers = ( 'g++', 'c++' );
my $x;
my $program = <<EOF;
#include <list>
#include <vector>
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
vector<int> v;
list<char> l;
v.push_back(1);
v.push_back(7);
l.push_back(0x30);
l.push_front(0x31);
vector<int>::iterator vi;
list<char>::iterator li;
for(vi=v.begin();vi!=v.end();vi++)
cout << (*vi);
for(li=l.begin();li!=l.end();li++)
cout << (*li);
cout << endl;
return 0;
}
EOF
print "testing C++ compiler... ";
if (!open(TESTCC,">test.cc")) {
print "cannot write test program.\n";
return 0;
}
print TESTCC "$program";
close TESTCC;
$cxx = 'no';
for (@compilers) {
$x = $_;
unlink('test.o','yytest');
next if (run_cmd($x, '-c', 'test.cc', '-o', 'test.o') != 0);
next if (run_cmd($x, 'test.o', '-o', 'yytest') != 0);
$y = `./yytest`;
next if ($y ne "1710\n");
$cxx = $x;
print "$cxx works\n";
last;
}
unlink('test.o','yytest','test.cc');
if ($cxx eq 'no') {
print "FAIL\n";
return 0;
}
return 1;
}
sub install_util {
print "checking sanity of install... ";
if (run_cmd("sh", "-c", "echo something > xxtest") != 0) {
print "FAIL\n";
return 0;
}
if (run_cmd("install -m 0644 xxtest ./yytest") != 0) {
print "FAIL\n";
unlink("xxtest","yytest");
return 0;
}
if (run_cmd("diff xxtest yytest") != 0) {
print "FAIL\n";
unlink("xxtest","yytest");
return 0;
}
unlink("xxtest","yytest");
print "ok\n";
return 1;
}
sub append_inc {
my $x = shift @_;
my @y;
@y = split(/:/, $x);
for (@y) {
push @cxxflags, "-I$_";
}
}
sub append_ld {
my $x = shift @_;
my @y;
@y = split(/:/, $x);
for (@y) {
push @ldflags, "-L$_";
}
}
sub header_def {
my $x = shift @_;
$x =~ s/\//_/g;
$x =~ s/\./_/g;
$x =~ tr/a-z/A-Z/;
$x = "HAVE_$x";
return $x;
}
sub spaces {
my $i, $x = "";
for($i=$_[0];$i>0;$i--) {
$x = $x.' ';
}
return $x;
}
# @_ = ( header macro confighname )
sub macro_check {
my $hdr = shift @_;
my $mac = shift @_;
my $chn = shift @_;
my $program = "#include <$hdr>\n#if !defined($mac)\n#error not there\n#endif\n";
print "checking for $mac in $hdr... ";
if (!open(TESTCC,">test.cc")) {
print "cannot write test program, FAIL\n";
return 0;
}
print TESTCC "$program";
close TESTCC;
if (run_cmd($cxx,@cxxflags,"-c","test.cc","-o","xxtest.o") != 0) {
print "no\n";
print CONFIGH "#undef $chn\n";
unlink("test.cc","xxtest.o");
return 0;
} else {
print "yes\n";
print CONFIGH "#define $chn 1\n";
unlink("test.cc","xxtest.o");
return 1;
}
}
sub cppdef {
my $macro = shift @_;
print CONFIGH "#define $macro 1\n";
}
sub cppundef {
my $macro = shift @_;
print CONFIGH "#undef $macro\n";
}
sub header_check {
my $x,$y,$fail=0;
print "header verification:\n";
for(@_) {
$x = $_;
print " $x";
$y = spaces(20 - length($x));
print "$y";
$program = "#include <$x>\nint main() { return 0; }\n";
if (!open(TESTCC,">test.cc")) {
print "cannot write test program, FAIL\n";
return 0;
}
print TESTCC "$program";
close TESTCC;
if (run_cmd($cxx,@cxxflags,"-c","test.cc","-o","xxtest.o") != 0) {
print ": no\n";
$y = header_def($x);
print CONFIGH "#undef $y\n";
++$fail;
} else {
$y = header_def($x);
print CONFIGH "#define $y 1\n";
print "\r";
$y = spaces(40);
print "$y\r";
}
unlink("test.cc","xxtest.o");
}
if ($fail == 0) {
print " all headers found.\n";
return 1;
}
return 0;
}
# ver, minver, maxver
sub version_cmp {
my $ver = shift @_;
my $minver = shift @_;
my $maxver = shift @_;
my @av, @minav, @maxav;
@av = split(/\./,$ver);
@minav = split(/\./,$minver);
@maxav = split(/\./,$maxver);
return 0 if ($av[0]<$minav[0] || $av[0]>$maxav[0]);
return 0 if ($av[0]==$minav[0] && $av[1]<$minav[1]);
return 0 if ($av[0]==$maxav[0] && $av[1]>$maxav[1]);
return 0 if ($av[0]==$minav[0] && $av[1]==$minav[1] && $av[2]<$minav[2]);
return 0 if ($av[0]==$maxav[0] && $av[1]==$maxav[1] && $av[2]>$maxav[2]);
return 1;
}
# name
sub get_prog {
my $file = shift @_;
my $path = $ENV{PATH};
my @path, $x;
@path = split(/:/,$path);
for(@path) {
$x = "$_/$file";
next unless -x $x && -f $x && -e $x;
return $x;
}
return '';
}
# -------------
STDOUT->autoflush();
print "configuring eboard $version...\n";
# parse command-line options
for (@ARGV) {
if (/--prefix=(.*)/) {
$prefix = $1;
next;
}
if ($_ eq '--enable-debug') {
@cxxflags = ("-ggdb");
next;
}
if ($_ eq '--disable-nls') {
$nls = 0;
next;
}
if (/--extra-inc=(.*)/) {
append_inc($1);
next;
}
if (/--extra-ld=(.*)/) {
append_ld($1);
next;
}
if ($_ eq '-h' || $_ eq '--help') {
usage();
exit 1;
}
print "** ignoring unknown parameter $_\n";
}
if (!open(CONFIGH,">$configh")) {
print "** cannot open $configh for writing, GIVING UP.\n";
exit 2;
}
print CONFIGH "#ifndef CONFIG_H\n#define CONFIG_H 1\n\n";
if (!open(CONFIGMAKE,">$configmake")) {
print "**cannot open $configmake for writing, GIVING UP.\n";
exit 2;
}
if (!install_util()) {
print "** install is not working properly.\n";
exit 2;
}
if (!cplusplus_lang()) {
print "** no suitable C++ compiler found.\n";
exit 2;
}
# required headers
if (!header_check("stdio.h","stdlib.h","string.h","unistd.h",
"time.h","stdarg.h","ctype.h","errno.h",
"fcntl.h","dirent.h","sys/stat.h",
"sys/types.h","sys/wait.h","signal.h",
"math.h","sys/time.h","sys/ioctl.h",
"sys/socket.h", "netdb.h", "netinet/in.h",
"arpa/inet.h", "iostream",
"deque","list","vector","stack","string")) {
print "** at least one required header is missing.\n";
exit 2;
}
#optional headers
header_check("strings.h","sys/soundcard.h","sys/audioio.h");
$t1=macro_check("netinet/in.h","IPPROTO_TCP","HAVE_IPPROTO_TCP_ON_IN_H");
$t2=macro_check("netinet/in.h","TCP_NODELAY","HAVE_TCP_NODELAY_ON_IN_H");
$t3=macro_check("netinet/in.h","SOL_TCP","HAVE_SOL_TCP_ON_IN_H");
$t4=macro_check("netinet/tcp.h","IPPROTO_TCP","HAVE_IPPROTO_TCP_ON_TCP_H");
$t5=macro_check("netinet/tcp.h","TCP_NODELAY","HAVE_TCP_NODELAY_ON_TCP_H");
$t6=macro_check("netinet/tcp.h","SOL_TCP","HAVE_SOL_TCP_ON_TCP_H");
print " net options: ";
if ($t2 != 0) {
cppdef("USE_SOCK_OPTS");
if ($t1!=0 && $t3!=0) {
cppundef("NEED_TCP_H");
cppdef("USE_SOCK_OPTS");
}
if ($t1!=0) {
cppdef("USE_IPPROTO_TCP");
print "netinet/tcp.h not required, IPPROTO_TCP present.\n";
} else {
cppdef("USE_SOL_TCP");
print "netinet/tcp.h not required, SOL_TCP present.\n";
}
} else {
if ($t5 != 0 && ($t1!=0 || $t4!=0) && ($t3!=0 || $t6!=0) ) {
cppdef("NEED_TCP_H");
cppdef("USE_SOCK_OPTS");
if ($t1!=0 || $t4!=0) {
cppdef("USE_IPPROTO_TCP");
print "netinet/tcp.h required, IPPROTO_TCP present.\n";
} else {
cppdef("USE_SOL_TCP");
print "netinet/tcp.h required, SOL_TCP present.\n";
}
} else {
cppundef("USE_SOCK_OPTS");
print "TCP macros not found, eboard will not use setsockopt\n";
}
}
# gtk 1.2.x
print "looking for gtk-config... ";
$gtkconfig = get_prog("gtk-config");
$gtkconfig = get_prog("gtk12-config") if ($gtkconfig eq '');
if ($gtkconfig eq '') {
print "NOT FOUND\n";
print "** You need GTK+ 1.2.x to compile eboard. If you're on a\n";
print "** RPM-based Linux system (Red Hat, SuSE, Conectiva, Mandrake)\n";
print "** you may need to install the -devel package of glib and gtk.\n";
print "** GTK+'s site: http://www.gtk.org\n";
exit 2;
}
print "$gtkconfig\n";
print "looking for GTK+ version... ";
$gtkversion = `$gtkconfig --version`;
chomp($gtkversion);
if (version_cmp($gtkversion,"1.2.8","1.3.0")!=0) {
print "$gtkversion, ok\n";
} else {
print "$gtkversion, WILL NOT DO (must be >= 1.2.8 and < 1.3.0)\n";
print "** The currently installed GTK+ version cannot be used to\n";
print "** compile eboard, it is recommended you get 1.2.10.\n";
print "** GTK+'s site: http://www.gtk.org\n";
exit 2;
}
print "looking for imlib-config... ";
$imlibconfig = get_prog("imlib-config");
if ($imlibconfig eq '') {
print "NOT FOUND\n";
print "** You need imlib 1.x.x to compile eboard. If you're on a\n";
print "** RPM-based Linux system (Red Hat, SuSE, Conectiva, Mandrake)\n";
print "** you may need to install the -devel package of imlib.\n";
print "** imlib's site: ftp://ftp.gnome.org/pub/GNOME/stable/sources/imlib\n";
exit 2;
}
print "$imlibconfig\n";
print "looking for imlib version... ";
$imlibversion = `$imlibconfig --version`;
chomp($imlibversion);
if (version_cmp($imlibversion, "1.9.7", "7000.0.0")!=0) {
print "$imlibversion, ok\n";
} else {
print "$imlibversion, WILL NOT DO (must be >= 1.9.7)\n";
print "** The currently installed imlib version cannot be used to\n";
print "** compile eboard, it is recommended you get 1.9.14 or later.\n";
print "** imlib's site: ftp://ftp.gnome.org/pub/GNOME/stable/sources/imlib\n";
exit 2;
}
$x = `$imlibconfig --cflags-gdk`;
chomp($x);
@x = split(/ /,$x);
for(@x) {
push @cxxflags, $_;
}
$x = `$imlibconfig --libs-gdk`;
chomp($x);
@x = split(/ /,$x);
for(@x) {
push @ldflags, $_;
}
if (!header_check("gtk/gtk.h","gdk/gdkkeysyms.h",
"gdk_imlib.h","X11/Xlib.h"))
{
print "** The compiler did not find GTK/GDK/imlib/X11 headers,\n";
print "** unable to proceed.\n";
exit 2;
}
# end
print CONFIGH "#define DATADIR \"$prefix/share/games\"\n";
print CONFIGH "#define EBOARD_PREFIX \"$prefix\"\n";
print CONFIGH "#define VERSION \"$version\"\n";
if ($nls == 0) {
print CONFIGH "#undef ENABLE_NLS\n";
} else {
print CONFIGH "#define ENABLE_NLS 1\n";
}
print CONFIGH "\n#endif\n";
close CONFIGH;
print "wrote $configh\n";
print CONFIGMAKE "CXX = $cxx\n";
print CONFIGMAKE "CXXFLAGS = @cxxflags\n";
print CONFIGMAKE "LDFLAGS = @ldflags\n";
print CONFIGMAKE "prefix = $prefix\n";
print CONFIGMAKE "bindir = $prefix/bin\n";
print CONFIGMAKE "mandir = $prefix/share/man\n";
print CONFIGMAKE "datadir = $prefix/share/games/$package\n";
print CONFIGMAKE "version = $version\n";
close CONFIGMAKE;
print "wrote $configmake\n";
print "writing Makefile... ";
if (run_cmd("sh","-c","cat $configmake elifekam > Makefile") != 0) {
print "error (?!?)\n";
exit 2;
}
print "ok\n";
print "creating eboard-config... ";
if (!open(ECIN,"<eboard-config.in")) {
print "FAILED, eboard-config.in not found.\n";
exit 2;
}
if (!open(ECOUT,">eboard-config")) {
print "FAILED, cannot create eboard-config.\n";
exit 2;
}
while($_=<ECIN>) {
chomp;
if (/^\#HERE/) {
print ECOUT "prefix=$prefix\n";
print ECOUT "bindir=$prefix/bin\n";
print ECOUT "datadir=$prefix/share/games\n";
print ECOUT "package=$package\n";
print ECOUT "version=$version\n";
} else {
print ECOUT "$_\n";
}
}
close(ECIN);
close(ECOUT);
print "ok\n";
print "creating eboard.spec... ";
if (!open(ESIN,"<eboard.spec.in")) {
print "FAILED, eboard.spec.in not found.\n";
exit 2;
}
if (!open(ESOUT,">eboard.spec")) {
print "FAILED, cannot create eboard.spec.\n";
exit 2;
}
while($_=<ESIN>) {
chomp;
s/THEVERSION/$version/g;
print ESOUT "$_\n";
}
close(ESIN);
close(ESOUT);
print "ok\n";
print "done.\n";
|