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