]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/configure.pm
Merge pull request #935 from SaberUK/insp20+fix-crlf
[user/henk/code/inspircd.git] / make / configure.pm
1 #
2 # InspIRCd -- Internet Relay Chat Daemon
3 #
4 #   Copyright (C) 2012 Peter Powell <petpow@saberuk.com>
5 #   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6 #   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
7 #   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
8 #   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
9 #
10 # This file is part of InspIRCd.  InspIRCd is free software: you can
11 # redistribute it and/or modify it under the terms of the GNU General Public
12 # License as published by the Free Software Foundation, version 2.
13 #
14 # This program is distributed in the hope that it will be useful, but WITHOUT
15 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17 # details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23
24 package make::configure;
25
26 require 5.8.0;
27
28 use strict;
29 use warnings FATAL => qw(all);
30
31 use Exporter 'import';
32 use POSIX;
33 use make::utilities;
34 our @EXPORT = qw(promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s module_installed);
35
36 my $no_git = 0;
37
38 sub yesno {
39         my ($flag,$prompt) = @_;
40         print "$prompt [\e[1;32m$main::config{$flag}\e[0m] -> ";
41         chomp(my $tmp = <STDIN>);
42         if ($tmp eq "") { $tmp = $main::config{$flag} }
43         if (($tmp eq "") || ($tmp =~ /^y/i))
44         {
45                 $main::config{$flag} = "y";
46         }
47         else
48         {
49                 $main::config{$flag} = "n";
50         }
51         return;
52 }
53
54 sub resolve_directory
55 {
56         my $ret = $_[0];
57         eval
58         {
59                 use File::Spec;
60                 $ret = File::Spec->rel2abs($_[0]);
61         };
62         return $ret;
63 }
64
65 sub getrevision {
66         if ($no_git)
67         {
68                 return "0";
69         }
70         my $data = `git describe --tags 2>/dev/null`;
71         if ($data eq "")
72         {
73                 $no_git = 1;
74                 return '0';
75         }
76         chomp $data; # remove \n
77         return $data;
78 }
79
80 sub getcompilerflags {
81         my ($file) = @_;
82         open(FLAGS, $file) or return "";
83         while (<FLAGS>) {
84                 if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/\r?$/) {
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: (.+) \*\/\r?$/) {
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: (.+) \*\/\r?$/) {
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 \*\/\r?$/) {
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 module_installed($)
197 {
198         my $module = shift;
199         eval("use $module;");
200         return !$@;
201 }
202
203 sub promptstring_s($$)
204 {
205         my ($prompt,$default) = @_;
206         my $var;
207         print "$prompt\n";
208         print "[\e[1;32m$default\e[0m] -> ";
209         chomp($var = <STDIN>);
210         $var = $default if $var eq "";
211         print "\n";
212         return $var;
213 }
214
215 sub dumphash()
216 {
217         print "\n\e[1;32mPre-build configuration is complete!\e[0m\n\n";
218         print "\e[0mBase install path:\e[1;32m\t\t$main::config{BASE_DIR}\e[0m\n";
219         print "\e[0mConfig path:\e[1;32m\t\t\t$main::config{CONFIG_DIR}\e[0m\n";
220         print "\e[0mModule path:\e[1;32m\t\t\t$main::config{MODULE_DIR}\e[0m\n";
221         print "\e[0mGCC Version Found:\e[1;32m\t\t$main::config{GCCVER}.$main::config{GCCMINOR}\e[0m\n";
222         print "\e[0mCompiler program:\e[1;32m\t\t$main::config{CC}\e[0m\n";
223         print "\e[0mGnuTLS Support:\e[1;32m\t\t\t$main::config{USE_GNUTLS}\e[0m\n";
224         print "\e[0mOpenSSL Support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n\n";
225         print "\e[1;32mImportant note: The maximum length values are now configured in the\e[0m\n";
226         print "\e[1;32m                configuration file, not in ./configure! See the <limits>\e[0m\n";
227         print "\e[1;32m                tag in the configuration file for more information.\e[0m\n\n";
228 }
229
230 sub is_dir
231 {
232         my ($path) = @_;
233         if (chdir($path))
234         {
235                 chdir($main::this);
236                 return 1;
237         }
238         else
239         {
240                 # Just in case..
241                 chdir($main::this);
242                 return 0;
243         }
244 }
245
246 sub showhelp
247 {
248         chomp(my $PWD = `pwd`);
249         print <<EOH;
250 Usage: configure [options]
251
252 *** NOTE: NON-INTERACTIVE CONFIGURE IS *NOT* SUPPORTED BY THE ***
253 *** INSPIRCD DEVELOPMENT TEAM. DO NOT ASK FOR HELP REGARDING  ***
254 ***     NON-INTERACTIVE CONFIGURE ON THE FORUMS OR ON IRC!    ***
255
256 Options: [defaults in brackets after descriptions]
257
258 When no options are specified, interactive
259 configuration is started and you must specify
260 any required values manually. If one or more
261 options are specified, non-interactive configuration
262 is started, and any omitted values are defaulted.
263
264 Arguments with a single \"-\" symbol, as in
265 InspIRCd 1.0.x, are also allowed.
266
267   --disable-interactive        Sets no options itself, but
268                                will disable any interactive prompting.
269   --update                     Update makefiles and dependencies
270   --clean                      Remove .config.cache file and go interactive
271   --enable-gnutls              Enable GnuTLS module [no]
272   --enable-openssl             Enable OpenSSL module [no]
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   --with-cc=[filename]         Use an alternative compiler to
280                                build InspIRCd [g++]
281   --with-maxbuf=[n]            Change the per message buffer size [512]
282                                DO NOT ALTER THIS OPTION WITHOUT GOOD REASON
283                                AS IT *WILL* BREAK CLIENTS!!!
284   --prefix=[directory]         Base directory to install into (if defined,
285                                can automatically define config, module, bin
286                                and library dirs as subdirectories of prefix)
287                                [$PWD]
288   --config-dir=[directory]     Config file directory for config and SSL certs
289                                [$PWD/run/conf]
290   --log-dir=[directory]        Log file directory for logs
291                                [$PWD/run/logs]
292   --data-dir=[directory]       Data directory for variable data, such as the
293                                permchannel configuration and the XLine database
294                                [$PWD/run/data]
295   --module-dir=[directory]     Modules directory for loadable modules
296                                [$PWD/run/modules]
297   --binary-dir=[directory]     Binaries directory for core binary
298                                [$PWD/run/bin]
299   --list-extras                Show current status of extra modules
300   --enable-extras=[extras]     Enable the specified list of extras
301   --disable-extras=[extras]    Disable the specified list of extras
302   --help                       Show this help text and exit
303
304 EOH
305         exit(0);
306 }
307
308 1;
309