]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/configure.pm
Add daniel's third-party module repository
[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 getmodversion 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 getmodversion {
126         my ($file) = @_;
127         open(FLAGS, $file) or return "";
128         while (<FLAGS>) {
129                 if (m#(?:^/* \$|")ModVersion: (\S+)(?: \*\/$|")#) {
130                         my $x = translate_functions($1, $file);
131                         next if ($x eq "");
132                         close(FLAGS);
133                         return $x;
134                 }
135         }
136         close(FLAGS);
137         return "";
138 }
139
140 sub nopedantic {
141         my ($file) = @_;
142         open(FLAGS, $file) or return "";
143         while (<FLAGS>) {
144                 if ($_ =~ /^\/\* \$NoPedantic \*\/$/) {
145                         my $x = translate_functions($_, $file);
146                         next if ($x eq "");
147                         close(FLAGS);
148                         return 1;
149                 }
150         }
151         close(FLAGS);
152         return 0;
153 }
154
155 sub getmodules
156 {
157         my ($silent) = @_;
158
159         my $i = 0;
160
161         if (!$silent)
162         {
163                 print "Detecting modules ";
164         }
165
166         opendir(DIRHANDLE, "src/modules") or die("WTF, missing src/modules!");
167         foreach my $name (sort readdir(DIRHANDLE))
168         {
169                 if ($name =~ /^m_(.+)\.cpp$/)
170                 {
171                         my $mod = $1;
172                         $main::modlist[$i++] = $mod;
173                         if (!$silent)
174                         {
175                                 print ".";
176                         }
177                 }
178         }
179         closedir(DIRHANDLE);
180
181         if (!$silent)
182         {
183                 print "\nOk, $i modules.\n";
184         }
185 }
186
187 sub promptnumeric($$)
188 {
189         my $continue = 0;
190         my ($prompt, $configitem) = @_;
191         while (!$continue)
192         {
193                 print "Please enter the maximum $prompt?\n";
194                 print "[\e[1;32m$main::config{$configitem}\e[0m] -> ";
195                 chomp(my $var = <STDIN>);
196                 if ($var eq "")
197                 {
198                         $var = $main::config{$configitem};
199                 }
200                 if ($var =~ /^\d+$/) {
201                         # We don't care what the number is, set it and be on our way.
202                         $main::config{$configitem} = $var;
203                         $continue = 1;
204                         print "\n";
205                 } else {
206                         print "You must enter a number in this field. Please try again.\n\n";
207                 }
208         }
209 }
210
211 sub promptstring_s($$)
212 {
213         my ($prompt,$default) = @_;
214         my $var;
215         print "$prompt\n";
216         print "[\e[1;32m$default\e[0m] -> ";
217         chomp($var = <STDIN>);
218         $var = $default if $var eq "";
219         print "\n";
220         return $var;
221 }
222
223 sub dumphash()
224 {
225         print "\n\e[1;32mPre-build configuration is complete!\e[0m\n\n";
226         print "\e[0mBase install path:\e[1;32m\t\t$main::config{BASE_DIR}\e[0m\n";
227         print "\e[0mConfig path:\e[1;32m\t\t\t$main::config{CONFIG_DIR}\e[0m\n";
228         print "\e[0mModule path:\e[1;32m\t\t\t$main::config{MODULE_DIR}\e[0m\n";
229         print "\e[0mLibrary path:\e[1;32m\t\t\t$main::config{LIBRARY_DIR}\e[0m\n";
230         print "\e[0mGCC Version Found:\e[1;32m\t\t$main::config{GCCVER}.$main::config{GCCMINOR}\e[0m\n";
231         print "\e[0mCompiler program:\e[1;32m\t\t$main::config{CC}\e[0m\n";
232         print "\e[0mIPv6 Support:\e[1;32m\t\t\t$main::config{IPV6}\e[0m\n";
233         print "\e[0mIPv6 to IPv4 Links:\e[1;32m\t\t$main::config{SUPPORT_IP6LINKS}\e[0m\n";
234         print "\e[0mGnuTLS Support:\e[1;32m\t\t\t$main::config{USE_GNUTLS}\e[0m\n";
235         print "\e[0mOpenSSL Support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n\n";
236         print "\e[1;32mImportant note: The maximum length values are now configured in the\e[0m\n";
237         print "\e[1;32m                configuration file, not in ./configure! See the <limits>\e[0m\n";
238         print "\e[1;32m                tag in the configuration file for more information.\e[0m\n\n";
239 }
240
241 sub is_dir
242 {
243         my ($path) = @_;
244         if (chdir($path))
245         {
246                 chdir($main::this);
247                 return 1;
248         }
249         else
250         {
251                 # Just in case..
252                 chdir($main::this);
253                 return 0;
254         }
255 }
256
257 sub showhelp
258 {
259         chomp(my $PWD = `pwd`);
260         print "Usage: configure [options]
261
262 *** NOTE: NON-INTERACTIVE CONFIGURE IS *NOT* SUPPORTED BY THE ***
263 *** INSPIRCD DEVELOPMENT TEAM. DO NOT ASK FOR HELP REGARDING  ***
264 ***     NON-INTERACTIVE CONFIGURE ON THE FORUMS OR ON IRC!    ***
265
266 Options: [defaults in brackets after descriptions]
267
268 When no options are specified, interactive
269 configuration is started and you must specify
270 any required values manually. If one or more
271 options are specified, non-interactive configuration
272 is started, and any omitted values are defaulted.
273
274 Arguments with a single \"-\" symbol, as in
275 InspIRCd 1.0.x, are also allowed.
276
277   --disable-interactive        Sets no options intself, but
278                                will disable any interactive prompting.
279   --disable-rpath              Disable runtime paths. DO NOT USE UNLESS
280                                YOU KNOW WHAT YOU ARE DOING!
281   --update                     Update makefiles and dependencies
282   --modupdate                  Detect new modules and write makefiles
283   --svnupdate {--rebuild}      Update working copy via subversion
284                                 {and optionally rebuild if --rebuild
285                                  is also specified}
286   --clean                      Remove .config.cache file and go interactive
287   --enable-gnutls              Enable GnuTLS module [no]
288   --enable-openssl             Enable OpenSSL module [no]
289   --enable-optimization=[n]    Optimize using -O[n] gcc flag
290   --enable-epoll               Enable epoll() where supported [set]
291   --enable-kqueue              Enable kqueue() where supported [set]
292   --disable-epoll              Do not enable epoll(), fall back
293                                to select() [not set]
294   --disable-kqueue             Do not enable kqueue(), fall back
295                                to select() [not set]
296   --enable-ipv6                Build ipv6 native InspIRCd [no]
297   --enable-remote-ipv6         Build with ipv6 support for remote
298                                servers on the network [yes]
299   --disable-remote-ipv6        Do not allow remote ipv6 servers [not set]
300   --with-cc=[filename]         Use an alternative g++ binary to
301                                build InspIRCd [g++]
302   --with-maxbuf=[n]            Change the per message buffer size [512]
303                                DO NOT ALTER THIS OPTION WITHOUT GOOD REASON
304                                AS IT *WILL* BREAK CLIENTS!!!
305   --prefix=[directory]         Base directory to install into (if defined,
306                                can automatically define config, module, bin
307                                and library dirs as subdirectories of prefix)
308                                [$PWD]
309   --config-dir=[directory]     Config file directory for config and SSL certs
310                                [$PWD/conf]
311   --module-dir=[directory]     Modules directory for loadable modules
312                                [$PWD/modules]
313   --binary-dir=[directory]     Binaries directory for core binary
314                                [$PWD/bin]
315   --library-dir=[directory]    Library directory for core libraries
316                                [$PWD/lib]
317   --list-extras                Show current status of extra modules
318   --enable-extras=[extras]     Enable the specified list of extras
319   --disable-extras=[extras]    Disable the specified list of extras
320   --help                       Show this help text and exit
321
322 ";
323         exit(0);
324 }
325
326 1;
327