]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/configure.pm
Also redirect errors to /dev/null to avoid messy output on VCS that aren't installed...
[user/henk/code/inspircd.git] / make / configure.pm
1 #       +------------------------------------+
2 #       | Inspire Internet Relay Chat Daemon |
3 #       +------------------------------------+
4 #
5 #  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 # See: http://www.inspircd.org/wiki/index.php/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-svn info 2>/dev/null`;
63                 if ($data eq "")
64                 {
65                         $no_svn = 1;
66                         my $rev = "0";
67                         return $rev;
68                 }
69         }
70         $data =~ /Revision: (\d+)/;
71         my $rev = $1;
72         if (!defined($rev))
73         {
74                 $rev = "0";
75         }
76         return $rev;
77 }
78
79 sub getcompilerflags {
80         my ($file) = @_;
81         open(FLAGS, $file) or return "";
82         while (<FLAGS>) {
83                 if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/$/) {
84                         my $x = translate_functions($1, $file);
85                         next if ($x eq "");
86                         close(FLAGS);
87                         return $x;
88                 }
89         }
90         close(FLAGS);
91         return "";
92 }
93
94 sub getlinkerflags {
95         my ($file) = @_;
96         open(FLAGS, $file) or return "";
97         while (<FLAGS>) {
98                 if ($_ =~ /^\/\* \$LinkerFlags: (.+) \*\/$/) {
99                         my $x = translate_functions($1, $file);
100                         next if ($x eq "");
101                         close(FLAGS);
102                         return $x;
103                 }
104         }
105         close(FLAGS);
106         return "";
107 }
108
109 sub getdependencies {
110         my ($file) = @_;
111         open(FLAGS, $file) or return "";
112         while (<FLAGS>) {
113                 if ($_ =~ /^\/\* \$ModDep: (.+) \*\/$/) {
114                         my $x = translate_functions($1, $file);
115                         next if ($x eq "");
116                         close(FLAGS);
117                         return $x;
118                 }
119         }
120         close(FLAGS);
121         return "";
122 }
123
124 sub getmodversion {
125         my ($file) = @_;
126         open(FLAGS, $file) or return "";
127         while (<FLAGS>) {
128                 if ($_ =~ /^\/\* \$ModVersion: (.+) \*\/$/) {
129                         my $x = translate_functions($1, $file);
130                         next if ($x eq "");
131                         close(FLAGS);
132                         return $x;
133                 }
134         }
135         close(FLAGS);
136         return "";
137 }
138
139 sub nopedantic {
140         my ($file) = @_;
141         open(FLAGS, $file) or return "";
142         while (<FLAGS>) {
143                 if ($_ =~ /^\/\* \$NoPedantic \*\/$/) {
144                         my $x = translate_functions($_, $file);
145                         next if ($x eq "");
146                         close(FLAGS);
147                         return 1;
148                 }
149         }
150         close(FLAGS);
151         return 0;
152 }
153
154 sub getmodules
155 {
156         my $i = 0;
157         print "Detecting modules ";
158         opendir(DIRHANDLE, "src/modules") or die("WTF, missing src/modules!");
159         foreach my $name (sort readdir(DIRHANDLE))
160         {
161                 if ($name =~ /^m_(.+)\.cpp$/)
162                 {
163                         my $mod = $1;
164                         $main::modlist[$i++] = $mod;
165                         print ".";
166                 }
167         }
168         closedir(DIRHANDLE);
169         print "\nOk, $i modules.\n";
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[0mLibrary path:\e[1;32m\t\t\t$main::config{LIBRARY_DIR}\e[0m\n";
215         print "\e[0mGCC Version Found:\e[1;32m\t\t$main::config{GCCVER}.$main::config{GCCMINOR}\e[0m\n";
216         print "\e[0mCompiler program:\e[1;32m\t\t$main::config{CC}\e[0m\n";
217         print "\e[0mIPv6 Support:\e[1;32m\t\t\t$main::config{IPV6}\e[0m\n";
218         print "\e[0mIPv6 to IPv4 Links:\e[1;32m\t\t$main::config{SUPPORT_IP6LINKS}\e[0m\n";
219         print "\e[0mGnuTLS Support:\e[1;32m\t\t\t$main::config{USE_GNUTLS}\e[0m\n";
220         print "\e[0mOpenSSL Support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n\n";
221         print "\e[1;32mImportant note: The maximum length values are now configured in the\e[0m\n";
222         print "\e[1;32m                configuration file, not in ./configure! See the <limits>\e[0m\n";
223         print "\e[1;32m                tag in the configuration file for more information.\e[0m\n\n";
224 }
225
226 sub is_dir
227 {
228         my ($path) = @_;
229         if (chdir($path))
230         {
231                 chdir($main::this);
232                 return 1;
233         }
234         else
235         {
236                 # Just in case..
237                 chdir($main::this);
238                 return 0;
239         }
240 }
241
242 sub showhelp
243 {
244         chomp(my $PWD = `pwd`);
245         print "Usage: configure [options]
246
247 *** NOTE: NON-INTERACTIVE CONFIGURE IS *NOT* SUPPORTED BY THE ***
248 *** INSPIRCD DEVELOPMENT TEAM. DO NOT ASK FOR HELP REGARDING  ***
249 ***     NON-INTERACTIVE CONFIGURE ON THE FORUMS OR ON IRC!    ***
250
251 Options: [defaults in brackets after descriptions]
252
253 When no options are specified, interactive
254 configuration is started and you must specify
255 any required values manually. If one or more
256 options are specified, non-interactive configuration
257 is started, and any omitted values are defaulted.
258
259 Arguments with a single \"-\" symbol, as in
260 InspIRCd 1.0.x, are also allowed.
261
262   --disable-interactive        Sets no options intself, but
263                                will disable any interactive prompting.
264   --disable-rpath              Disable runtime paths. DO NOT USE UNLESS
265                                YOU KNOW WHAT YOU ARE DOING!
266   --update                     Update makefiles and dependencies
267   --modupdate                  Detect new modules and write makefiles
268   --svnupdate {--rebuild}      Update working copy via subversion
269                                 {and optionally rebuild if --rebuild
270                                  is also specified}
271   --clean                      Remove .config.cache file and go interactive
272   --enable-gnutls              Enable GnuTLS module [no]
273   --enable-openssl             Enable OpenSSL module [no]
274   --enable-optimization=[n]    Optimize using -O[n] gcc flag
275   --enable-epoll               Enable epoll() where supported [set]
276   --enable-kqueue              Enable kqueue() where supported [set]
277   --disable-epoll              Do not enable epoll(), fall back
278                                to select() [not set]
279   --disable-kqueue             Do not enable kqueue(), fall back
280                                to select() [not set]
281   --enable-ipv6                Build ipv6 native InspIRCd [no]
282   --enable-remote-ipv6         Build with ipv6 support for remote
283                                servers on the network [yes]
284   --disable-remote-ipv6        Do not allow remote ipv6 servers [not set]
285   --with-cc=[filename]         Use an alternative g++ binary to
286                                build InspIRCd [g++]
287   --with-maxbuf=[n]            Change the per message buffer size [512]
288                                DO NOT ALTER THIS OPTION WITHOUT GOOD REASON
289                                AS IT *WILL* BREAK CLIENTS!!!
290   --prefix=[directory]         Base directory to install into (if defined,
291                                can automatically define config, module, bin
292                                and library dirs as subdirectories of prefix)
293                                [$PWD]
294   --config-dir=[directory]     Config file directory for config and SSL certs
295                                [$PWD/conf]
296   --module-dir=[directory]     Modules directory for loadable modules
297                                [$PWD/modules]
298   --binary-dir=[directory]     Binaries directory for core binary
299                                [$PWD/bin]
300   --library-dir=[directory]    Library directory for core libraries
301                                [$PWD/lib]
302   --list-extras                Show current status of extra modules
303   --enable-extras=[extras]     Enable the specified list of extras
304   --disable-extras=[extras]    Disable the specified list of extras
305   --help                       Show this help text and exit
306
307 ";
308         exit(0);
309 }
310
311 1;
312