]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/configure.pm
67e91c825aeb44cf2ad6ec4c6e8647dd206051b2
[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(test_file test_header 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 test_file($$;$) {
39         my ($cc, $file, $args) = @_;
40         my $status = 0;
41         $args ||= '';
42         $status ||= system "$cc -o __test_$file make/test/$file $args >/dev/null 2>&1";
43         $status ||= system "./__test_$file >/dev/null 2>&1";
44         unlink  "./__test_$file";
45         return !$status;
46 }
47
48 sub test_header($$;$) {
49         my ($cc, $header, $args) = @_;
50         $args ||= '';
51         open(CC, "| $cc -E - $args >/dev/null 2>&1") or return 0;
52         print CC "#include <$header>";
53         close(CC);
54         return !$?;
55 }
56
57 sub yesno {
58         my ($flag,$prompt) = @_;
59         print "$prompt [\e[1;32m$main::config{$flag}\e[0m] -> ";
60         chomp(my $tmp = <STDIN>);
61         if ($tmp eq "") { $tmp = $main::config{$flag} }
62         if (($tmp eq "") || ($tmp =~ /^y/i))
63         {
64                 $main::config{$flag} = "y";
65         }
66         else
67         {
68                 $main::config{$flag} = "n";
69         }
70         return;
71 }
72
73 sub resolve_directory
74 {
75         my $ret = $_[0];
76         eval
77         {
78                 use File::Spec;
79                 $ret = File::Spec->rel2abs($_[0]);
80         };
81         return $ret;
82 }
83
84 sub getrevision {
85         if ($no_git)
86         {
87                 return "0";
88         }
89         my $data = `git describe --tags 2>/dev/null`;
90         if ($data eq "")
91         {
92                 $no_git = 1;
93                 return '0';
94         }
95         chomp $data; # remove \n
96         return $data;
97 }
98
99 sub getcompilerflags {
100         my ($file) = @_;
101         open(FLAGS, $file) or return "";
102         while (<FLAGS>) {
103                 if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/$/) {
104                         my $x = translate_functions($1, $file);
105                         next if ($x eq "");
106                         close(FLAGS);
107                         return $x;
108                 }
109         }
110         close(FLAGS);
111         return "";
112 }
113
114 sub getlinkerflags {
115         my ($file) = @_;
116         open(FLAGS, $file) or return "";
117         while (<FLAGS>) {
118                 if ($_ =~ /^\/\* \$LinkerFlags: (.+) \*\/$/) {
119                         my $x = translate_functions($1, $file);
120                         next if ($x eq "");
121                         close(FLAGS);
122                         return $x;
123                 }
124         }
125         close(FLAGS);
126         return "";
127 }
128
129 sub getdependencies {
130         my ($file) = @_;
131         open(FLAGS, $file) or return "";
132         while (<FLAGS>) {
133                 if ($_ =~ /^\/\* \$ModDep: (.+) \*\/$/) {
134                         my $x = translate_functions($1, $file);
135                         next if ($x eq "");
136                         close(FLAGS);
137                         return $x;
138                 }
139         }
140         close(FLAGS);
141         return "";
142 }
143
144 sub nopedantic {
145         my ($file) = @_;
146         open(FLAGS, $file) or return "";
147         while (<FLAGS>) {
148                 if ($_ =~ /^\/\* \$NoPedantic \*\/$/) {
149                         my $x = translate_functions($_, $file);
150                         next if ($x eq "");
151                         close(FLAGS);
152                         return 1;
153                 }
154         }
155         close(FLAGS);
156         return 0;
157 }
158
159 sub getmodules
160 {
161         my ($silent) = @_;
162
163         my $i = 0;
164
165         if (!$silent)
166         {
167                 print "Detecting modules ";
168         }
169
170         opendir(DIRHANDLE, "src/modules") or die("WTF, missing src/modules!");
171         foreach my $name (sort readdir(DIRHANDLE))
172         {
173                 if ($name =~ /^m_(.+)\.cpp$/)
174                 {
175                         my $mod = $1;
176                         $main::modlist[$i++] = $mod;
177                         if (!$silent)
178                         {
179                                 print ".";
180                         }
181                 }
182         }
183         closedir(DIRHANDLE);
184
185         if (!$silent)
186         {
187                 print "\nOk, $i modules.\n";
188         }
189 }
190
191 sub promptnumeric($$)
192 {
193         my $continue = 0;
194         my ($prompt, $configitem) = @_;
195         while (!$continue)
196         {
197                 print "Please enter the maximum $prompt?\n";
198                 print "[\e[1;32m$main::config{$configitem}\e[0m] -> ";
199                 chomp(my $var = <STDIN>);
200                 if ($var eq "")
201                 {
202                         $var = $main::config{$configitem};
203                 }
204                 if ($var =~ /^\d+$/) {
205                         # We don't care what the number is, set it and be on our way.
206                         $main::config{$configitem} = $var;
207                         $continue = 1;
208                         print "\n";
209                 } else {
210                         print "You must enter a number in this field. Please try again.\n\n";
211                 }
212         }
213 }
214
215 sub module_installed($)
216 {
217         my $module = shift;
218         eval("use $module;");
219         return !$@;
220 }
221
222 sub promptstring_s($$)
223 {
224         my ($prompt,$default) = @_;
225         my $var;
226         print "$prompt\n";
227         print "[\e[1;32m$default\e[0m] -> ";
228         chomp($var = <STDIN>);
229         $var = $default if $var eq "";
230         print "\n";
231         return $var;
232 }
233
234 sub dumphash()
235 {
236         print "\n\e[1;32mPre-build configuration is complete!\e[0m\n\n";
237         print "\e[0mBase install path:\e[1;32m\t\t$main::config{BASE_DIR}\e[0m\n";
238         print "\e[0mConfig path:\e[1;32m\t\t\t$main::config{CONFIG_DIR}\e[0m\n";
239         print "\e[0mModule path:\e[1;32m\t\t\t$main::config{MODULE_DIR}\e[0m\n";
240         print "\e[0mGCC Version Found:\e[1;32m\t\t$main::config{GCCVER}.$main::config{GCCMINOR}\e[0m\n";
241         print "\e[0mCompiler program:\e[1;32m\t\t$main::config{CC}\e[0m\n";
242         print "\e[0mGnuTLS Support:\e[1;32m\t\t\t$main::config{USE_GNUTLS}\e[0m\n";
243         print "\e[0mOpenSSL Support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n\n";
244         print "\e[1;32mImportant note: The maximum length values are now configured in the\e[0m\n";
245         print "\e[1;32m                configuration file, not in ./configure! See the <limits>\e[0m\n";
246         print "\e[1;32m                tag in the configuration file for more information.\e[0m\n\n";
247 }
248
249 sub is_dir
250 {
251         my ($path) = @_;
252         if (chdir($path))
253         {
254                 chdir($main::this);
255                 return 1;
256         }
257         else
258         {
259                 # Just in case..
260                 chdir($main::this);
261                 return 0;
262         }
263 }
264
265 sub showhelp
266 {
267         chomp(my $PWD = `pwd`);
268         print <<EOH;
269 Usage: configure [options]
270
271 *** NOTE: NON-INTERACTIVE CONFIGURE IS *NOT* SUPPORTED BY THE ***
272 *** INSPIRCD DEVELOPMENT TEAM. DO NOT ASK FOR HELP REGARDING  ***
273 ***     NON-INTERACTIVE CONFIGURE ON THE FORUMS OR ON IRC!    ***
274
275 Options: [defaults in brackets after descriptions]
276
277 When no options are specified, interactive
278 configuration is started and you must specify
279 any required values manually. If one or more
280 options are specified, non-interactive configuration
281 is started, and any omitted values are defaulted.
282
283 Arguments with a single \"-\" symbol, as in
284 InspIRCd 1.0.x, are also allowed.
285
286   --disable-interactive        Sets no options itself, but
287                                will disable any interactive prompting.
288   --update                     Update makefiles and dependencies
289   --clean                      Remove .config.cache file and go interactive
290   --enable-gnutls              Enable GnuTLS module [no]
291   --enable-openssl             Enable OpenSSL module [no]
292   --enable-epoll               Enable epoll() where supported [set]
293   --enable-kqueue              Enable kqueue() where supported [set]
294   --disable-epoll              Do not enable epoll(), fall back
295                                to select() [not set]
296   --disable-kqueue             Do not enable kqueue(), fall back
297                                to select() [not set]
298   --disable-ipv6               Do not build IPv6 native InspIRCd [not set]
299   --with-cc=[filename]         Use an alternative compiler to
300                                build InspIRCd [g++]
301   --with-maxbuf=[n]            Change the per message buffer size [512]
302                                DO NOT ALTER THIS OPTION WITHOUT GOOD REASON
303                                AS IT *WILL* BREAK CLIENTS!!!
304   --prefix=[directory]         Base directory to install into (if defined,
305                                can automatically define config, module, bin
306                                and library dirs as subdirectories of prefix)
307                                [$PWD]
308   --config-dir=[directory]     Config file directory for config and SSL certs
309                                [$PWD/conf]
310   --log-dir=[directory]        Log file directory for logs
311                                [$PWD/logs]
312   --data-dir=[directory]       Data directory for variable data, such as the permchannel configuration and the XLine database
313                                [$PWD/data]
314   --module-dir=[directory]     Modules directory for loadable modules
315                                [$PWD/modules]
316   --binary-dir=[directory]     Binaries directory for core binary
317                                [$PWD/bin]
318   --library-dir=[directory]    Library directory for core libraries
319                                [$PWD/lib]
320   --list-extras                Show current status of extra modules
321   --enable-extras=[extras]     Enable the specified list of extras
322   --disable-extras=[extras]    Disable the specified list of extras
323   --help                       Show this help text and exit
324
325 EOH
326         exit(0);
327 }
328
329 1;
330