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