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
|
#!/bin/sh
#
# The yChat Project (2003 - 2004)
#
if ! which perl >/dev/null
then
echo You need to have Perl in your PATH
exit 1
fi
if ! test -f ../g++.version
then
echo You need to run ./configure of the top level source dir first
exit 1
fi
perl -e '
use strict;
$|=1;
my %libadd;
my %incadd;
my $deepness = 500;
my @headers = (
"dlfcn.h",
"pthread.h",
"mysql/mysql.h", #//<< Not needed for yhttpd
"netinet/in.h",
"time.h",
"ncurses.h"
);
my @libs = (
"libmysqlclient.so", #//<< Not needed for yhttpd
"libncurses.so"
);
sub remove_from_array
{
my $elem = shift;
my $array = shift;
for ( my $i = 0; $i <= $#$array; ++$i )
{
if ( $$array[$i] eq $elem )
{
splice(@$array,$i,1);
last;
}
}
}
open FILE, "glob.h" or die "glob.h: $!\n";
while(<FILE>)
{
if ( /\/\/#define DATABASE/ )
{
remove_from_array("mysql/mysql.h",\@headers);
remove_from_array("libmysqlclient.so",\@libs);
}
elsif ( /\/\/#define NCURSES/ )
{
remove_from_array("ncurses.h",\@headers);
remove_from_array("libncurses.so",\@libs);
}
}
close FILE;
my @headerpaths = (
$ENV{HOME}."/include",
$ENV{HOME}."/usr/include",
"/include",
"/usr/include",
"/usr/local/include",
"/usr/pkg/include",
"/opt/include",
"/opt/local/include"
);
my @libpaths = (
$ENV{HOME}."/lib",
$ENV{HOME}."/usr/lib",
"/lib",
"/usr/lib",
"/usr/local/lib",
"/usr/pkg/lib",
"/opt/lib",
"/opt/local/lib"
);
if ( defined $ENV{YCHATHEADERPATHS} ) {
map { print "Adding $_...\n";
unshift @headerpaths, $_ } split /:/, $ENV{YCHATHEADERPATHS};
}
if ( defined $ENV{YCHATLIBPATHS} ) {
map { print "Adding $_...\n";
unshift @libpaths, $_ } split /:/, $ENV{YCHATLIBPATHS};
}
sub check {
my $deep = shift;
if ($deep == 0) {
print "Looking too deep! ($deepness)\n";
exit(1);
}
my $check = shift;
my $print = 1;
if ( $_[-1] eq "subsearch" ) {
$print = 0;
pop(@_);
}
print "Checking for $check... " if $print;
foreach (@_) {
if ( -f "$_/$check" ) {
print "OK\n";
return "" if $_ eq "/usr/lib" or $_ eq "/usr/include";
return $_;
}
}
foreach (@_) {
next unless -d $_;
opendir D, $_ or warn "$_: $!\n"; my @dir = readdir(D);
closedir D;
foreach my $dir ( @dir ) {
next if $dir =~ /^\.+$/ or !-d "$_/$dir";
my $path = &check($deep-1, $check, "$_/$dir", "subsearch");
return $path if $path ne "";
}
}
if ($print) {
print "NOT OK\n";
print "Please make sure that you have the needed software installed!\n";
print "If you have a special path for your includes then edit src/configure!\n";
print "Or set the environment variables YCHATHEADERPATHS and YCHATLIBPATHS.\n";
print " Example: setenv YCHATHEADERPATHS \"/your/header/includes:/a/includes\"\n";
print "(The environment variables have to be seperated by an :)\n";
exit(1);
}
return "";
}
map { $incadd{&check($deepness, $_, @headerpaths)}++ }
@headers;
map { $libadd{&check($deepness, $_, @libpaths)}++ }
@libs;
sub makeadd {
my $flag = shift;
my $add = shift;
my $ret = "";
foreach (keys %$add) {
next unless /.+/;
$ret .= "$flag$_ ";
}
return $ret;
}
my $incadd = &makeadd("-I", \%incadd);
my $libadd = &makeadd("-L", \%libadd);
foreach ( @libs )
{
$libadd .= "-l$_ "
if s/^lib// and s/\.so$//;
}
print "Incadd: $incadd\n";
print "Libadd: $libadd\n";
`echo $incadd > includes.add`;
`echo $libadd > libs.add`;
print "Creating new base Makefile...\n";
unlink("Makefile") if -f "Makefile";
open Fin, "Makefile.in" or die "Makefile.in: $!\n";
open Fout, ">Makefile" or die "Makefile: $!\n";
my $cpp = `echo *.cpp */*.cpp contrib/*/*.cpp | sort`;
my $compiler = `tail -n 1 ../g++.version`;
my $version = `tail -n 2 ../g++.version | head -n 1`;
my $uname = `uname -srm`;
chomp $uname;
print "Configuring for $uname...\n";
chomp $cpp;
chomp $version;
while (<Fin>) {
s/^(CC=).*\n/$1$compiler/;
s/^(SRCS=).*/$1$cpp/;
s/ -frepo// unless $version =~ /3\.4/;
if ( $uname !~ /Linux/i ) {
print "Disabling -ldl flag...\n" if s/ -ldl//;
}
print Fout;
}
close Fin;
my $args = join(" -",@ARGV);
$args = "-".$args unless $args eq "";
foreach my $cppfile (split / /, $cpp) {
my $ofile = $cppfile;
$ofile =~ s/\.cpp/\.o/;
print Fout "../obj/$ofile: $cppfile\n";
print Fout "\t\@if ! test -d `dirname ../obj/$ofile`; then mkdir -p `dirname ../obj/$ofile`; fi\n";
if ( $ofile =~ /contrib\/.+/ ) {
my $dirname = `dirname $ofile`;
print Fout "\t\@echo -n \"Compiling contributed class $ofile \"\n";
} else {
print Fout "\t\@echo -n \"Compiling base class $ofile \"\n";
}
print Fout "\t\@\$(CC) \$(CFLAGS) \$(INCLUDES) $args -c -o ../obj/$ofile $cppfile\n";
print Fout "\t\@du -hc ../obj/$ofile | tail -n 1 | sed s/total// | sed \"s/ //g\"\n";
}
close Fout;
open F, "msgs.h" or die "msgs.h: $!\n";
my @msgs = <F>;
close F;
unlink("msgs.h");
open F, ">msgs.h" or die "msgs.h: $!\n";
foreach (@msgs) {
s/(UNAME)(.+)$/UNAME "$uname"/;
print F;
}
close F;
if ( -d "mods" ) {
chdir("mods");
my $cflags = "-fno-inline -fno-default-inline";
$cflags .= " -nostdlib" if $uname !~ /Linux/i;
system("echo $cflags > cflags.add");
system("./configure");
chdir("..");
}
exit(0);
' `echo "$*" | sed "s/-//g"`
|