File: configure

package info (click to toggle)
yaskkserv 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,004 kB
  • ctags: 913
  • sloc: cpp: 11,972; perl: 702; sh: 191; makefile: 90
file content (715 lines) | stat: -rwxr-xr-x 24,212 bytes parent folder | download
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
#!/usr/bin/perl -w

use strict;
use warnings;
use Getopt::Long;
use File::Temp;

my %global_options = (
		      'prefix' => '/usr/local',
		      'enable-google-japanese-input' => !0,
		      'enable-https' => !0,
		      'enable-gnutls' => !0,
		      'enable-openssl' => !0,
                      'enable-systemd' => !0,
		     );
my %global;
$global{'project_identifier'} = 'YASKKSERV';
$global{'version'} = '1.1.0';

# CompilerIsSupport($compiler_version, 3, 2, 1);
sub CompilerIsSupport ($$$$) {
    my $compiler_version = $_[0];
    my $major = $_[1];
    my $minor = $_[2];
    my $sub = $_[3];

    if ($compiler_version >= $major * 1000000 + $minor * 1000 + $sub * 1) {
	return !0;
    } else {
	return 0;
    }
}

sub CompilerCheck ($$;$) {
    my $check_header = $_[0];
    my $check_body = $_[1];
    my $check_option = defined($_[2]) ? $_[2] : '';

    # thanks! KURASHIKI-san and Debian
    my $temporary_filename_base = '/tmp/yaskkserv.configure.XXXXX';
    my ($wfh_dummy, $temporary_filename_o) = File::Temp::mkstemps($temporary_filename_base, '.o');
    my ($wfh, $temporary_filename_c) = File::Temp::mkstemps($temporary_filename_base, '.c');
    print $wfh $check_header;
    print $wfh qq!int main(int argc, char *argv[])\n{\n!;
    print $wfh $check_body;
    print $wfh qq!return 0;\n}\n!;
    close($wfh);

    # thanks! KURASHIKI-san
    my $c = "$global{'compiler'} $check_option -c $temporary_filename_c -o $temporary_filename_o >/dev/null 2>&1";
    system($c);
    my $result = $? ? 0 : !0;

    unlink($temporary_filename_o);
    unlink($temporary_filename_c);

    return $result;
}

sub LinkerCheckLibrary ($) {
    my $library_option = $_[0];

    my $temporary_filename_base = '/tmp/yaskkserv.configure.XXXXX';
    my ($wfh_dummy, $temporary_filename_execute) = File::Temp::mkstemps($temporary_filename_base, '');
    my ($wfh, $temporary_filename_c) = File::Temp::mkstemps($temporary_filename_base, '.c');
    print $wfh qq!int main(int argc, char *argv[])\n{\n!;
    print $wfh qq!return 0;\n}\n!;
    close($wfh);

    my $c = "$global{'compiler'} $temporary_filename_c -o $temporary_filename_execute $library_option >/dev/null 2>&1";
    system($c);
    my $result = $? ? 0 : !0;

    unlink($temporary_filename_execute);
    unlink($temporary_filename_c);

    return $result;
}

sub isGcc () {
    if ($global{'compiler'} =~ /gcc/) {
	return !0;
    }
    0;
}

sub isClang () {
    if ($global{'compiler'} =~ /clang/) {
	return !0;
    }
    0;
}

sub getPkgConfig {
    my $command = $_[0];
    my $args = $_[1];
    my $result;
    if (defined($global{'pkg-config'})) {
	my $tmp = `pkg-config $command $args 2>&1`;
	if ($? == 0) {
	    chomp($tmp);
	    $result = $tmp;
	}
    }
    return $result;
}

$global{'data'} .= "# -*- Makefile -*-\n";
$global{'data'} .= "#\n";
$global{'data'} .= "# $0";
foreach (@ARGV) {
    $global{'data'} .= " $_";
}
$global{'data'} .= "\n";
$global{'data'} .= "#\n";
$global{'data'} .= "# " . localtime() . "\n";
$global{'data'} .= "#\n";
$global{'data'} .= "# * DO NOT EDIT! *\n";
$global{'data'} .= "#\n";

GetOptions('gplusplus=s' => \$global_options{'gplusplus'},
	   'compiler=s' => \$global_options{'compiler'},
           'help' => \$global_options{'help'},
           'enable-google-japanese-input' => \$global_options{'enable-google-japanese-input'},
           'disable-google-japanese-input' => \$global_options{'disable-google-japanese-input'},
           'enable-google-suggest' => \$global_options{'enable-google-suggest'},
           'disable-google-suggest' => \$global_options{'disable-google-suggest'},
           'enable-syslog' => \$global_options{'enable-syslog'},
           'disable-syslog' => \$global_options{'disable-syslog'},
           'enable-error-message' => \$global_options{'enable-error-message'},
           'disable-error-message' => \$global_options{'disable-error-message'},
           'enable-https' => \$global_options{'enable-https'},
           'disable-https' => \$global_options{'disable-https'},
           'enable-gnutls' => \$global_options{'enable-gnutls'},
           'disable-gnutls' => \$global_options{'disable-gnutls'},
           'enable-openssl' => \$global_options{'enable-openssl'},
           'disable-openssl' => \$global_options{'disable-openssl'},
           'enable-systemd' => \$global_options{'enable-systemd'},
           'disable-systemd' => \$global_options{'disable-systemd'},
           'precompile' => \$global_options{'precompile'},
           'prefix=s' => \$global_options{'prefix'});

if (defined($global_options{'help'})) {
    print "$0 usage\n";
    print "    --gplusplus=COMPILER            *DEPRECATED* compiler [default g++]\n";
    print "    --compiler=COMPILER             compiler (g++, clang++ or etc) [default g++]\n";
    print "    --help                          print this message\n";
    print "    --enable-google-japanese-input  enable google japanese input (for yaskkserv_hairy) [default enable]\n";
    print "    --disable-google-japanese-input disable google japanese input (for yaskkserv_hairy) [default enable]\n";
    print "    --enable-google-suggest         enable google suggest (for yaskkserv_hairy) [default disable]\n";
    print "    --disable-google-suggest        disable google suggest (for yaskkserv_hairy) [default disable]\n";
    print "    --enable-syslog                 enable syslog [default]\n";
    print "    --disable-syslog                disable syslog\n";
    print "    --enable-error-message          enable error message [default]\n";
    print "    --disable-error-message         disable error message\n";
    print "    --enable-https                  enable HTTPS [default]\n";
    print "    --disable-https                 disable HTTPS\n";
    print "    --enable-gnutls                 enable GnuTLS [default]\n";
    print "    --disable-gnutls                disable GnuTLS\n";
    print "    --enable-openssl                enable OpenSSL [default]\n";
    print "    --disable-openssl               disable OpenSSL\n";
    print "    --enable-systemd                enable systemd [default]\n";
    print "    --disable-systemd               disable systemd\n";
    print "    --precompile                    use precompile (for G++ 4.0 or newer)\n";
    print "    --prefix=PREFIX                 install root directory [/usr/local]\n";
    die;
}

{
    $_ = `pkg-config --version 2>&1`;
    if (defined($_)) {
	$global{'pkg-config'} = $_;
	print "pkg-config (found)\n";
    } else {
	print "pkg-config (not found)\n";
    }
}

{
    if (defined($global_options{'gplusplus'})) {
	$global{'compiler'} = $global_options{'gplusplus'};
	print "*** Warning : --gplusplus is deprecated\n";
    } elsif (defined($global_options{'compiler'})) {
	$global{'compiler'} = $global_options{'compiler'};
    } else {
	my $tmp = 'g++';
	$_ = `$tmp -v 2>&1`;
	if (defined($_)) {
	} else {
	    $tmp = 'clang++';
	    $_ = `$tmp -v 2>&1`;
	    unless (defined($_)) {
		print STDERR "*** Warning : compiler not found!\n";
	    }
	}
	$global{'compiler'} = $tmp;
    }
    $global{'data'} .= "export COMPILER				= $global{'compiler'}\n";
}

{
    my $tmp = 'make';
    $_ = `$tmp -v 2>&1`;
    if (defined($_) and /gnu\s*make/im) {
	print "GNU Make ($tmp)\n";
    } else {
	$tmp = 'gmake';
	$_ = `$tmp -v 2>&1`;
	if (defined($_) and /gnu\s*make/im) {
	    print "GNU Make ($tmp)\n";
	} else {
	    $tmp = 'gnumake';
	    $_ = `$tmp -v 2>&1`;
	    if (defined($_) and /gnu\s*make/im) {
		print "GNU Make ($tmp)\n";
	    } else {
		print STDERR "*** Warning : GNU Make not found!\n";
	    }
	}
    }
}

{
    $global{'data'} .= "export MKDIR				= mkdir\n";
}

{
    $global{'data'} .= "export RM				= rm\n";
}

{
    $global{'data'} .= "export PERL				= perl\n";
}

{
    $global{'data'} .= "export INSTALL				= install\n";
}

{
    $global{'data'} .= "export PREFIX				= $global_options{'prefix'}\n";
}

{
    $global{'data'} .= "export PROJECT_IDENTIFIER		= $global{'project_identifier'}\n";
    $_ = $global{'project_identifier'};
    tr/A-Z/a-z/;
    $global{'data'} .= "export PROJECT_IDENTIFIER_LOWER_CASE	= $_\n";
}

{
    $global{'data'} .= "export PROJECT_VERSION			= $global{'version'}\n";
}

{
    $_ = `pwd 2>&1`;
    chomp;
    $global{'project_root'} = $_;
    $global{'data'} .= "export PROJECT_ROOT			= $global{'project_root'}\n";
}

{
    my @compiler_version;
    foreach (split(/[\r\n]+/, `$global{'compiler'} -v 2>&1`)) {
	if (/\s*clang\s+version/ and m!\s+(\d+)\.(\d+)\.?(\d+)?!) {
	    @compiler_version = ($1, $2, $3);
	    last;
	} elsif (/^\s*gcc\s+version/ and m!\s+(\d+)\.(\d+)\.?(\d+)?!) {
	    @compiler_version = ($1, $2, $3);
	    last;
	}
    }

    if ($#compiler_version == -1) {
	$global{'compiler_version'} = 0;
	print STDERR "*** Warning : compiler version check failed.\n";
    } else {
	my $pow = $#compiler_version;
	foreach (@compiler_version) {
	    $_ = 0 unless defined($_);
	    $global{'compiler_version'} += $_ * (1000 ** $pow);
	    --$pow;
	}
	my $tmp;
	foreach (@compiler_version) {
	    $tmp .= "$_.";
	}
	chop $tmp;
	print "compiler $global{'compiler'} ($tmp)\n";
    }

    if (isGcc()) {
	unless (CompilerIsSupport($global{'compiler_version'}, 3, 3, 0)) {
	    print STDERR "*** Warning : G++ is too old. need version 3.3 or newer.\n";
	}
    }
}

if (defined($global_options{'precompile'})) {
    if (isClang()) {
	$global{'data'} .= "export USE_PRECOMPILE   		= t\n";
    } elsif (isGcc()) {
	if (CompilerIsSupport($global{'compiler_version'}, 4, 0, 0)) {
	    $global{'data'} .= "export USE_PRECOMPILE   		= t\n";
	} else {
	    print STDERR "*** Warning : G++ is too old. need version 4.0 or newer.\n";
	}
    }
}

{
    $_ = pack('V', 1);
    if (unpack('C', $_) == 1) {
	$global{'data'} .= "export CXXFLAGS_BYTE_ORDER		= -D $global{'project_identifier'}_ARCHITECTURE_BYTE_ORDER_VAX\n";
    } else {
	$global{'data'} .= "export CXXFLAGS_BYTE_ORDER		= -D $global{'project_identifier'}_ARCHITECTURE_BYTE_ORDER_NETWORK\n";
    }

    $global{'data'} .= "export CXXFLAGS_CONFIG			= \n";
    unless (defined($global_options{'disable-syslog'})) {
	$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_ENABLE_SYSLOG\n";
    }

    unless (defined($global_options{'disable-error-message'})) {
	$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_ENABLE_ERROR_MESSAGE\n";
    }

    if (defined($global_options{'enable-google-japanese-input'}) and
	!defined($global_options{'disable-google-japanese-input'})) {
	{
	    $_ = 'iconv.h';
	    my $found_flag;
	    my $header_symbol = $_;
	    $header_symbol =~ tr/a-z/A-Z/;
	    $header_symbol =~ s![\./]!_!g;
	    if (CompilerCheck("#include <$_>\n", '')) {
		my $const_char_code = <<EOT;
iconv_t icd;
const char *in_buffer = 0;
char *out_buffer = 0;
size_t in_size = 0;
size_t out_size = 0;
iconv(icd, &in_buffer, &in_size, &out_buffer, &out_size);
EOT
		my $char_code = <<EOT;
iconv_t icd;
char *in_buffer = 0;
char *out_buffer = 0;
size_t in_size = 0;
size_t out_size = 0;
iconv(icd, &in_buffer, &in_size, &out_buffer, &out_size);
EOT
		if (CompilerCheck("#include <$_>\n", $const_char_code)) {
		    $found_flag = !0;
		    print qq{$_ (argument "const char *" found)\n};
		    $global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_ICONV_ARGUMENT_CONST_CHAR\n";
		} elsif (CompilerCheck("#include <$_>\n", $char_code)) {
		    $found_flag = !0;
		    print qq{$_ (argument "char *" found)\n};
		    $global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_ICONV_ARGUMENT_CHAR\n";
		} else {
		    print STDERR "*** Warning : iconv not found\n";
		}
		if (defined($found_flag)) {
		    $global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_ENABLE_GOOGLE_JAPANESE_INPUT\n";
		    $global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_HEADER_HAVE_$header_symbol\n";
		    if (defined($global_options{'enable-google-suggest'}) and
			!defined($global_options{'disable-google-suggest'})) {
			$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_ENABLE_GOOGLE_SUGGEST\n";
		    }
		}
	    }
	    unless (defined($found_flag)) {
		print "$_ (not found : DISABLE --enable-google-japanese-input)\n";
		$global_options{'enable-google-japanese-input'} = undef;
	    }
	}
	if (defined($global_options{'enable-https'}) and !defined($global_options{'disable-https'})) {
	    if (defined($global_options{'enable-gnutls'}) and !defined($global_options{'disable-gnutls'})) {
		if (CompilerCheck("#include <gnutls/gnutls.h>\n" .
				  "#include <gnutls/crypto.h>\n" .
				  "#include <gnutls/openssl.h>\n"
				  ,
				  '')) {
		    $global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_HEADER_HAVE_GNUTLS_OPENSSL\n";
		    $global{'HAVE_GNUTLS_OPENSSL'} = !0;
		    print STDERR "SSL GnuTLS\n";
		}
		if (defined($global{'HAVE_GNUTLS_OPENSSL'})) {
		    if (CompilerCheck("#include <gnutls/gnutls.h>\n" .
				      "#include <gnutls/crypto.h>\n" .
				      "#include <gnutls/openssl.h>\n"
				      ,
				      'RAND_poll();')) {
			$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_HEADER_HAVE_RAND_POLL\n";
			print STDERR "SSL GnuTLS RAND_poll() (found)\n";
		    } else {
			print STDERR "SSL GnuTLS RAND_poll() (not found)\n";
		    }
		}
	    }
	    if (!defined($global{'HAVE_GNUTLS_OPENSSL'}) and
		defined($global_options{'enable-openssl'}) and !defined($global_options{'disable-openssl'})) {
		if (CompilerCheck("#include <openssl/crypto.h>\n" .
				  "#include <openssl/ssl.h>\n" .
				  "#include <openssl/err.h>\n" .
				  "#include <openssl/rand.h>\n"
				  ,
				  '')) {
		    $global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_HEADER_HAVE_OPENSSL\n";
		    $global{'HAVE_OPENSSL'} = !0;
		    print STDERR "SSL OpenSSL\n";
		}
		if (defined($global{'HAVE_OPENSSL'})) {
		    if (CompilerCheck("#include <openssl/crypto.h>\n" .
				      "#include <openssl/ssl.h>\n" .
				      "#include <openssl/err.h>\n" .
				      "#include <openssl/rand.h>\n"
				      ,
				      'RAND_poll();')) {
			$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_HEADER_HAVE_RAND_POLL\n";
			print STDERR "SSL OpenSSL RAND_poll() (found)\n";
		    } else {
			print STDERR "SSL OpenSSL RAND_poll() (not found)\n";
		    }
		}
	    }
	    if (!defined($global{'HAVE_GNUTLS_OPENSSL'}) and !defined($global{'HAVE_OPENSSL'})) {
		if (!defined($global{'HAVE_GNUTLS_OPENSSL'})) {
		    print STDERR "*** Warning : GnuTLS not found(or disable)\n";
		}
		if (!defined($global{'HAVE_OPENSSL'})) {
		    print STDERR "*** Warning : OpenSSL not found(or disable)\n";
		}
	    }
	} else {
	    print STDERR "*** Warning : HTTPS disabled\n";
	}
    } else {
	$global_options{'enable-google-japanese-input'} = undef;
    }

    if (defined($global_options{'enable-systemd'}) and !defined($global_options{'disable-systemd'})) {
	my $includes = "#include <systemd/sd-daemon.h>\n";
	my $body = "int fd = SD_LISTEN_FDS_START;\n" .
		   "int ret = sd_listen_fds(1);\n";
	if (CompilerCheck($includes, $body)) {
	    $global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_HAVE_SYSTEMD\n";
	    $global{'HAVE_SYSTEMD'} = !0;
	    print "SD_LISTEN_FDS_START and sd_listen_fds (found)\n";
	} else {
	    print STDERR "*** Warning : SD_LISTEN_FDS_START and sd_listen_fds are not found\n";
	}
    }
}

{
    if (CompilerCheck("#include <sys/socket.h>\n", "int tmp = MSG_NOSIGNAL;\n")) {
	$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_MACRO_HAVE_SYMBOL_MSG_NOSIGNAL\n";
	print "MSG_NOSIGNAL (found)\n";
    } else {
	print "MSG_NOSIGNAL (not found)\n";
    }
}

{
    if (CompilerCheck("#include <resolv.h>\n", "res_state r = &_res; int retrans = r->retrans; int retry = r->retry;\n")) {
	$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_MACRO_HAVE_SYMBOL_RESOLV_RETRANS_RETRY\n";
	print "RESOLV_RETRANS_RETRY (found)\n";
    } else {
	print "RESOLV_RETRANS_RETRY (not found)\n";
    }
}

{
    if (CompilerCheck("#include <signal.h>\n" .
		      "#include <time.h>\n"
		      ,
		      "timer_t timer_id;\n" .
		      "timer_create(CLOCK_REALTIME, 0, &timer_id);\n")) {
	$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_FUNCTION_HAVE_TIMER_CREATE\n";
	$global{'HAVE_TIMER_CREATE'} = !0;
	print "timer_create() (found)\n";
    } else {
	print "timer_create() (not found)\n";
    }
}

{
    if (CompilerCheck("#include <signal.h>\n" .
		      "#include <pthread.h>\n"
		      ,
		      "sigset_t sigset;\n" .
		      "pthread_sigmask(SIG_SETMASK, &sigset, NULL);\n")) {
	$global{'data'} .= "CXXFLAGS_CONFIG				+= -D $global{'project_identifier'}_CONFIG_HAVE_PTHREAD\n";
	$global{'HAVE_PTHREAD'} = !0;
	print "pthread (found)\n";
    } else {
	print "pthread (not found)\n";
    }
}

{
    $_ = `uname 2>&1`;
    if (/(bsd)/i or /(darwin)/i or /(cygwin)/i or /(linux)/i or /(GNU)/i) {
	$global{'OSNAME'} = $1;
    } else {
	print STDERR "*** Warning : unknown architecture ($_)\n";
	$global{'OSNAME'} = 'linux';
    }
    $global{'architecture'} = 'BSD_CYGWIN_LINUX_GCC';
    $global{'CXXFLAGS_ARCHITECTURE'} = "-D $global{'project_identifier'}_ARCHITECTURE_BSD_CYGWIN_LINUX_GCC";
    if (CompilerCheck('', '', '-std=c++11')) {
	$global{'CXXFLAGS_ARCHITECTURE'} .= ' -std=c++11 -D YASKKSERV_ARCHITECTURE_CXX11';
	print STDERR "c++11 supported\n";
    }
    $global{'LDFLAGS_ARCHITECTURE'} = '';
    $global{'LDFLAGS_LIBRARY_SIMPLE'} = '';
    $global{'LDFLAGS_LIBRARY_NORMAL'} = '';
    $global{'LDFLAGS_LIBRARY_HAIRY'} = '';
    if (LinkerCheckLibrary('-liconv')) {
	$global{'LDFLAGS_LIBRARY_HAIRY'} .= ' -liconv';
    }
    $global{'LDFLAGS_LIBRARY_HAIRY'} .= ' -lrt' if defined($global{'HAVE_TIMER_CREATE'});
    if (defined($global{'HAVE_GNUTLS_OPENSSL'})) {
	my $tmp = getPkgConfig('gnutls', '--libs');
	my $libs;
	if (defined($tmp)) {
	    $libs = ' ' . $tmp . ' -lgnutls-openssl';
	    unless (LinkerCheckLibrary($libs)) {
		$libs = undef;
	    }
	}
	unless (defined($libs)) {
	    if (LinkerCheckLibrary('-lgnutls-openssl')) {
		$libs = ' -lgnutls-openssl';
	    }
	}
	if (defined($libs)) {
	    $global{'LDFLAGS_LIBRARY_HAIRY'} .= $libs;
	} else {
	    print STDERR "*** Warning : GnuTLS library NOT FOUND\n";
	}
    }
    if (defined($global{'HAVE_OPENSSL'})) {
	my $tmp = getPkgConfig('openssl', '--libs');
	my $libs;
	if (defined($tmp)) {
	    $libs = ' ' . $tmp;
	    unless (LinkerCheckLibrary($libs)) {
		$libs = undef;
	    }
	}
	unless (defined($libs)) {
	    if (LinkerCheckLibrary('-lssl -lcrypto')) {
		$libs = ' -lssl -lcrypto';
	    }
	}
	if (defined($libs)) {
	    $global{'LDFLAGS_LIBRARY_HAIRY'} .= $libs;
	} else {
	    print STDERR "*** Warning : OpenSSL library NOT FOUND\n";
	}
    }
    if (defined($global{'HAVE_PTHREAD'})) {
	if (LinkerCheckLibrary('-lpthread')) {
	    $global{'LDFLAGS_LIBRARY_HAIRY'} .= ' -lpthread';
	}
    }
    if (defined($global{'HAVE_SYSTEMD'})) {
	if (LinkerCheckLibrary('-lsystemd')) {
	    $global{'LDFLAGS_LIBRARY_SIMPLE'} .= ' -lsystemd';
	    $global{'LDFLAGS_LIBRARY_NORMAL'} .= ' -lsystemd';
	    $global{'LDFLAGS_LIBRARY_HAIRY'} .= ' -lsystemd';
	}
    }

    if (/cygwin/i) {
	$global{'EXECUTE_FILE_SUFFIX'} = '.exe';
    } else {
	$global{'EXECUTE_FILE_SUFFIX'} = '';
    }

    die "unknown architecture \"$_\"" unless defined($global{'architecture'});

    $global{'data'} .= "export CXXFLAGS_ARCHITECTURE		= $global{'CXXFLAGS_ARCHITECTURE'}\n";
    $global{'data'} .= "export LDFLAGS_ARCHITECTURE		= $global{'LDFLAGS_ARCHITECTURE'}\n";
    $global{'data'} .= "export LDFLAGS_LIBRARY_SIMPLE		= $global{'LDFLAGS_LIBRARY_SIMPLE'}\n";
    $global{'data'} .= "export LDFLAGS_LIBRARY_NORMAL		= $global{'LDFLAGS_LIBRARY_NORMAL'}\n";
    $global{'data'} .= "export LDFLAGS_LIBRARY_HAIRY		= $global{'LDFLAGS_LIBRARY_HAIRY'}\n";
    $global{'data'} .= "export ARCHITECTURE			= $global{'architecture'}\n";
    $_ = $global{'architecture'};
    tr/A-Z/a-z/;
    $global{'data'} .= "export ARCHITECTURE_LOWER_CASE		= $_\n";
    $global{'data'} .= "export EXECUTE_FILE_SUFFIX		= $global{'EXECUTE_FILE_SUFFIX'}\n";
    $global{'data'} .= "export OSNAME				= $global{'OSNAME'}\n";
}

{
    $_ = `ccache 2>&1`;
    if ($? >= 0) {
	$global{'data'} .= "export CCACHE				= ccache\n";
	print "ccache (found)\n";
    } else {
	print "ccache (not found)\n";
    }
}

{
    my $common = '';
    my $optimize = '';
    if (isClang() or CompilerIsSupport($global{'compiler_version'}, 4, 0, 0)) {
	if (CompilerCheck("#include <math.h>\n", '', '-Ofast')) {
	    $optimize .= '-Ofast';
	} elsif (CompilerCheck("#include <math.h>\n", '', '-O3')) {
	    $optimize .= '-O3';
	    print STDERR "*** Warning : -Ofast failed\n";
	} else {
	    $optimize .= '-Os';
	    print STDERR "*** Warning : -Ofast, -O3 failed\n";
	}
    } else {
	# gcc3 �Ϥ�ʪ�����꤬���ꥵ�����ʲ������뤤�ϵ��路���ʤ�С�
	# ����ѥ���Х����򤱤뤿��˥��ץƥ��ޥ�����٥�򲼤��ޤ���
	$_ = `cat /proc/meminfo 2>&1`;
	my $memory_size = 0 * 1024;
	if (/^MemTotal:\s+(\d+)\s+kB/) {
	    $memory_size = $1;
	    print "memory ($memory_size kB)\n";
	} else {
	    print "memory (unknown)\n";
	}

	if ($memory_size < 320000) {
	    $optimize .= '-Os';
	    print STDERR "*** Warning : optimize level changed (-O3 to -Os)\n";
	} elsif (CompilerCheck("#include <math.h>\n", '', '-O3')) {
	    $optimize .= '-O3';
	} else {
	    $optimize .= '-Os';
	    print STDERR "*** Warning : -O3 failed\n";
	}
    }

    {
	$global{'data'} .= 'export CXXFLAGS_OPTIMIZE_SERVER_SIMPLE	= ';

	$global{'data'} .= "$common -Os\n";
    }

    {
	$global{'data'} .= 'export CXXFLAGS_OPTIMIZE_SERVER_NORMAL	= ';

	$global{'data'} .= "$common -Os\n";
    }

    {
	$global{'data'} .= 'export CXXFLAGS_OPTIMIZE_SERVER_HAIRY	= ';

	$global{'data'} .= "$common $optimize\n";
    }

    {
	$global{'data'} .= 'export CXXFLAGS_OPTIMIZE_TOOL		= ';

	$global{'data'} .= "$common $optimize\n";
    }
}

{
    my $common = '-Wall -Wextra -W -Weffc++ -Wold-style-cast -Woverloaded-virtual -Wsign-promo -Wsynth -Wundef -Wshadow -Wlarger-than-16384 -Wpointer-arith -Wcast-qual -Wcast-align -Wconversion -Wsign-compare -Waggregate-return -Wmissing-noreturn -Wredundant-decls -Wnon-virtual-dtor -Wreorder -Wswitch-default -Wswitch-enum';
    my $common_4_2_0 = '-Wabi -Wcomments -Wctor-dtor-privacy -Wdeprecated -Wendif-labels -Wfloat-equal -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimport -Winvalid-pch -Wmissing-include-dirs -Wmultichar -Wpragmas -Wredundant-decls -Wundef -Wunused-macros -Wvariadic-macros -Winvalid-offsetof -Wnon-template-friend -Wpmf-conversions -Wstrict-null-sentinel';
    {
	$global{'data'} .= 'export CXXFLAGS_WARNING_SERVER_SIMPLE	= ';

	$global{'data'} .= "$common_4_2_0 " if isClang() or CompilerIsSupport($global{'compiler_version'}, 4, 2, 0);
	$global{'data'} .= "$common\n";
    }

    {
	$global{'data'} .= 'export CXXFLAGS_WARNING_SERVER_NORMAL	= ';

	$global{'data'} .= "$common_4_2_0 " if isClang() or CompilerIsSupport($global{'compiler_version'}, 4, 2, 0);
	$global{'data'} .= "$common\n";
    }

    {
	$global{'data'} .= 'export CXXFLAGS_WARNING_SERVER_HAIRY	= ';

	$global{'data'} .= "$common_4_2_0 " if isClang() or CompilerIsSupport($global{'compiler_version'}, 4, 2, 0);
	$global{'data'} .= "$common\n";
    }

    {
	$global{'data'} .= "export CXXFLAGS_WARNING_TOOL		= ";

	$global{'data'} .= "$common_4_2_0 " if isClang() or CompilerIsSupport($global{'compiler_version'}, 4, 2, 0);
	$global{'data'} .= "$common\n";
    }
}

if (defined($global_options{'enable-google-japanese-input'})) {
    print "************************************\n";
    print "** enable google japanese input ! **\n";
    print "**     enable google suggest !    **\n" if defined $global_options{'enable-google-suggest'};
    print "************************************\n";
} else {
    if (defined($global_options{'enable-google-suggest'})) {
	die "illegal options --enable-google-suggest";
    }
}

{
    open(my $wfh, '>', 'Makefile.config') or die;
    print $wfh $global{'data'};
}