]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/configure.pm
Fix valgrind issues and crashes on exit
[user/henk/code/inspircd.git] / make / configure.pm
1 #       +------------------------------------+
2 #       | Inspire Internet Relay Chat Daemon |
3 #       +------------------------------------+
4 #
5 #  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 # See: http://wiki.inspircd.org/Credits
7 #
8 # This program is free but copyrighted software; see
9 #      the file COPYING for details.
10 #
11 # ---------------------------------------------------
12
13 package make::configure;
14
15 require 5.8.0;
16
17 use strict;
18 use warnings FATAL => qw(all);
19
20 use Exporter 'import';
21 use POSIX;
22 use make::utilities;
23 our @EXPORT = qw(promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s);
24
25 my $no_svn = 0;
26
27 sub yesno {
28         my ($flag,$prompt) = @_;
29         print "$prompt [\e[1;32m$main::config{$flag}\e[0m] -> ";
30         chomp(my $tmp = <STDIN>);
31         if ($tmp eq "") { $tmp = $main::config{$flag} }
32         if (($tmp eq "") || ($tmp =~ /^y/i))
33         {
34                 $main::config{$flag} = "y";
35         }
36         else
37         {
38                 $main::config{$flag} = "n";
39         }
40         return;
41 }
42
43 sub resolve_directory
44 {
45         my $ret = $_[0];
46         eval
47         {
48                 use File::Spec;
49                 $ret = File::Spec->rel2abs($_[0]);
50         };
51         return $ret;
52 }
53
54 sub getrevision {
55         if ($no_svn)
56         {
57                 return "0";
58         }
59         my $data = `svn info 2>/dev/null`;
60         if ($data eq "")
61         {
62                 $data = `git describe --tags 2>/dev/null`;
63                 if ($data eq "")
64                 {
65                         $no_svn = 1;
66                         return '0';
67                 }
68                 chomp $data; # remove \n
69                 return $data;
70         }
71         $data =~ /Revision: (\d+)/;
72         my $rev = $1;
73         if (!defined($rev))
74         {
75                 $rev = "0";
76         }
77         return $rev;
78 }
79
80 sub getcompilerflags {
81         my ($file) = @_;
82         open(FLAGS, $file) or return "";
83         while (<FLAGS>) {
84                 if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/$/) {
85                         my $x = translate_functions($1, $file);
86                         next if ($x eq "");
87                         close(FLAGS);
88                         return $x;
89                 }
90         }
91         close(FLAGS);
92         return "";
93 }
94
95 sub getlinkerflags {
96         my ($file) = @_;
97         open(FLAGS, $file) or return "";
98         while (<FLAGS>) {
99                 if ($_ =~ /^\/\* \$LinkerFlags: (.+) \*\/$/) {
100                         my $x = translate_functions($1, $file);
101                         next if ($x eq "");
102                         close(FLAGS);
103                         return $x;
104                 }
105         }
106         close(FLAGS);
107         return "";
108 }
109
110 sub getdependencies {
111         my ($file) = @_;
112         open(FLAGS, $file) or return "";
113         while (<FLAGS>) {
114                 if ($_ =~ /^\/\* \$ModDep: (.+) \*\/$/) {
115                         my $x = translate_functions($1, $file);
116                         next if ($x eq "");
117                         close(FLAGS);
118                         return $x;
119                 }
120         }
121         close(FLAGS);
122         return "";
123 }
124
125 sub nopedantic {
126         my ($file) = @_;
127         open(FLAGS, $file) or return "";
128         while (<FLAGS>) {
129                 if ($_ =~ /^\/\* \$NoPedantic \*\/$/) {
130                         my $x = translate_functions($_, $file);
131                         next if ($x eq "");
132                         close(FLAGS);
133                         return 1;
134                 }
135         }
136         close(FLAGS);
137         return 0;
138 }
139
140 sub getmodules
141 {
142         my ($silent) = @_;
143
144         my $i = 0;
145
146         if (!$silent)
147         {
148                 print "Detecting modules ";
149         }
150
151         opendir(DIRHANDLE, "src/modules") or die("WTF, missing src/modules!");
152         foreach my $name (sort readdir(DIRHANDLE))
153         {
154                 if ($name =~ /^m_(.+)\.cpp$/)
155                 {
156                         my $mod = $1;
157                         $main::modlist[$i++] = $mod;
158                         if (!$silent)
159                         {
160                                 print ".";
161                         }
162                 }
163         }
164         closedir(DIRHANDLE);
165
166         if (!$silent)
167         {
168                 print "\nOk, $i modules.\n";
169         }
170 }
171
172 sub promptnumeric($$)
173 {
174         my $continue = 0;
175         my ($prompt, $configitem) = @_;
176         while (!$continue)
177         {
178                 print "Please enter the maximum $prompt?\n";
179                 print "[\e[1;32m$main::config{$configitem}\e[0m] -> ";
180                 chomp(my $var = <STDIN>);
181                 if ($var eq "")
182                 {
183                         $var = $main::config{$configitem};
184                 }
185                 if ($var =~ /^\d+$/) {
186                         # We don't care what the number is, set it and be on our way.
187                         $main::config{$configitem} = $var;
188                         $continue = 1;
189                         print "\n";
190                 } else {
191                         print "You must enter a number in this field. Please try again.\n\n";
192                 }
193         }
194 }
195
196 sub promptstring_s($$)
197 {
198         my ($prompt,$default) = @_;
199         my $var;
200         print "$prompt\n";
201         print "[\e[1;32m$default\e[0m] -> ";
202         chomp($var = <STDIN>);
203         $var = $default if $var eq "";
204         print "\n";
205         return $var;
206 }
207
208 sub dumphash()
209 {
210         print "\n\e[1;32mPre-build configuration is complete!\e[0m\n\n";
211         print "\e[0mBase install path:\e[1;32m\t\t$main::config{BASE_DIR}\e[0m\n";
212         print "\e[0mConfig path:\e[1;32m\t\t\t$main::config{CONFIG_DIR}\e[0m\n";
213         print "\e[0mModule path:\e[1;32m\t\t\t$main::config{MODULE_DIR}\e[0m\n";
214         print "\e[0mGCC Version Found:\e[1;32m\t\t$main::config{GCCVER}.$main::config{GCCMINOR}\e[0m\n";
215         print "\e[0mCompiler program:\e[1;32m\t\t$main::config{CC}\e[0m\n";
216         print "\e[0mIPv6 Support:\e[1;32m\t\t\t$main::config{IPV6}\e[0m\n";
217         print "\e[0mGnuTLS Support:\e[1;32m\t\t\t$main::config{USE_GNUTLS}\e[0m\n";
218         print "\e[0mOpenSSL Support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n\n";
219         print "\e[1;32mImportant note: The maximum length values are now configured in the\e[0m\n";
220         print "\e[1;32m                configuration file, not in ./configure! See the <limits>\e[0m\n";
221         print "\e[1;32m                tag in the configuration file for more information.\e[0m\n\n";
222 }
223
224 sub is_dir
225 {
226         my ($path) = @_;
227         if (chdir($path))
228         {
229                 chdir($main::this);
230                 return 1;
231         }
232         else
233         {
234                 # Just in case..
235                 chdir($main::this);
236                 return 0;
237         }
238 }
239
240 sub showhelp
241 {
242         chomp(my $PWD = `pwd`);
243         print "Usage: configure [options]
244
245 *** NOTE: NON-INTERACTIVE CONFIGURE IS *NOT* SUPPORTED BY THE ***
246 *** INSPIRCD DEVELOPMENT TEAM. DO NOT ASK FOR HELP REGARDING  ***
247 ***     NON-INTERACTIVE CONFIGURE ON THE FORUMS OR ON IRC!    ***
248
249 Options: [defaults in brackets after descriptions]
250
251 When no options are specified, interactive
252 configuration is started and you must specify
253 any required values manually. If one or more
254 options are specified, non-interactive configuration
255 is started, and any omitted values are defaulted.
256
257 Arguments with a single \"-\" symbol, as in
258 InspIRCd 1.0.x, are also allowed.
259
260   --disable-interactive        Sets no options itself, but
261                                will disable any interactive prompting.
262   --disable-rpath              Disable runtime paths. DO NOT USE UNLESS
263                                YOU KNOW WHAT YOU ARE DOING!
264   --update                     Update makefiles and dependencies
265   --modupdate                  Detect new modules and write makefiles
266   --svnupdate {--rebuild}      Update working copy via subversion
267                                 {and optionally rebuild if --rebuild
268                                  is also specified}
269   --clean                      Remove .config.cache file and go interactive
270   --enable-gnutls              Enable GnuTLS module [no]
271   --enable-openssl             Enable OpenSSL module [no]
272   --enable-optimization=[n]    Optimize using -O[n] gcc flag
273   --enable-epoll               Enable epoll() where supported [set]
274   --enable-kqueue              Enable kqueue() where supported [set]
275   --disable-epoll              Do not enable epoll(), fall back
276                                to select() [not set]
277   --disable-kqueue             Do not enable kqueue(), fall back
278                                to select() [not set]
279   --disable-ipv6               Do not build ipv6 native InspIRCd [not set]
280   --with-cc=[filename]         Use an alternative g++ binary to
281                                build InspIRCd [g++]
282   --with-maxbuf=[n]            Change the per message buffer size [512]
283                                DO NOT ALTER THIS OPTION WITHOUT GOOD REASON
284                                AS IT *WILL* BREAK CLIENTS!!!
285   --prefix=[directory]         Base directory to install into (if defined,
286                                can automatically define config, module, bin
287                                and library dirs as subdirectories of prefix)
288                                [$PWD]
289   --config-dir=[directory]     Config file directory for config and SSL certs
290                                [$PWD/conf]
291   --module-dir=[directory]     Modules directory for loadable modules
292                                [$PWD/modules]
293   --binary-dir=[directory]     Binaries directory for core binary
294                                [$PWD/bin]
295   --library-dir=[directory]    Library directory for core libraries
296                                [$PWD/lib]
297   --list-extras                Show current status of extra modules
298   --enable-extras=[extras]     Enable the specified list of extras
299   --disable-extras=[extras]    Disable the specified list of extras
300   --help                       Show this help text and exit
301
302 ";
303         exit(0);
304 }
305
306 1;
307