1#!/usr/local/bin/perl 2# If this doesn't work, just call it as .../perl configure 3 4# Copyright (c) 1995-1999 Hannah Schroeter <hannah@mamba.pond.sub.org> 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer, 11# either in a separate file included with the distribution, or 12# copied into the source files. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND HIS CONTRIBUTORS ``AS IS'' AND 18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR HIS CONTRIBUTORS BE LIABLE 21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27# SUCH DAMAGE. 28 29$redo = 0; 30if ($#ARGV == 0) { 31 if ($ARGV[0] =~ /^-?-?r(e(do?)?)?$/) { 32 if (! -f "./config.sed") { 33 die "Can't redo without prior configuration\n"; 34 } 35 $redo = 1; 36 } 37} 38 39@conffiles = ( 40 "Makefile", 41 "batcher", 42 "batcher.c", 43 "bsmtp.c", 44 "bsmtp.m4.8.14", 45 "bsmtp.m4.8.13", 46 "bsmtp.m4.8.12", 47 "bsmtp.m4.8.11", 48 "bsmtp.m4.8.10", 49 "bsmtp.m4.8.9", 50 "bsmtp.m4.8.8", 51 "bsmtp.m4.8.7", 52 "bsmtp.m4.8.6", 53 "rcsmtp", 54 "rsmtp", 55 "rsmtp.wrapper.c", 56 "transmitter.c-cbsmtp", 57 "transmitter.c-rcsmtp", 58 "transmitter.g-rcsmtp", 59 "transmitter.g-rgsmtp", 60 "transmitter.n-rsmtp", 61 "_bqueue.c", 62 "bqueue", 63 "contrib/andyr/deliver.pl" 64); 65if (! $redo) { 66 open (CONFIGIN, "config.in") || die "Can't open config.in\n"; 67 $i = 0; 68 while (<CONFIGIN>) { 69 next if (/^\s*\#.*$/); 70 if (/^\>/) { 71 s/^\>[ \t]*//; 72 print; next; 73 } 74 /^([^\s]+)\s+(([^\s]|\\.)+)\s+([^\[\s]+([^\[]*[^\[\s])?)(\s*\[(.*)\])?\s*$/; 75 $macro[$i] = $1; 76 $default[$i] = $2; $default[$i] =~ s/\\(.)/\1/g; 77 $help[$i] = $4; 78 $flag[$i] = $7; 79 if ($flag[$i] =~ /auto/) { 80 $macro = $macro[$i]; 81 if ($macro eq "\@CC\@") { 82 for (split (/:/, $ENV{'PATH'})) { 83 s/^$/$ENV{'HOME'}/; 84 if (-f "$_/cc" && -x "$_/cc") { 85 $cc = "$_/cc"; 86 last; 87 } 88 } 89 for (split (/:/, $ENV{'PATH'})) { 90 s/^$/$ENV{'HOME'}/; 91 if (-f "$_/gcc" && -x "$_/gcc") { 92 $gcc = "$_/gcc"; 93 last; 94 } 95 } 96 if ($cc && $gcc) { 97 print "cc and gcc found. Preferring gcc.\n"; 98 } 99 $cc = $gcc if ($gcc); 100 $default[$i] = $cc; 101 } elsif ($macro eq "\@INSTALL\@") { 102 for (split (/:/, $ENV{'PATH'})) { 103 s/^$/$ENV{'HOME'}/; 104 if (-f "$_/install" && -x "$_/install") { 105 $default[$i] = "$_/install"; last; 106 } 107 } 108 } elsif ($macro eq "\@SH\@") { 109 for (split (/:/, $ENV{'PATH'})) { 110 s/^$/$ENV{'HOME'}/; 111 if (-f "$_/sh" && -x "$_/sh") { 112 $default[$i] = "$_/sh"; last; 113 } 114 } 115 } elsif ($macro eq "\@GZIP\@") { 116 for (split (/:/, $ENV{'PATH'})) { 117 s/^$/$ENV{'HOME'}/; 118 if (-f "$_/gzip" && -x "$_/gzip") { 119 $default[$i] = "$_/gzip"; last; 120 } 121 } 122 } elsif ($macro eq "\@COMPRESS\@") { 123 for (split (/:/, $ENV{'PATH'})) { 124 s/^$/$ENV{'HOME'}/; 125 if (-f "$_/compress" && -x "$_/compress") { 126 $default[$i] = "$_/compress"; last; 127 } 128 } 129 } elsif ($macro eq "\@PERL\@") { 130 for (split (/:/, $ENV{'PATH'})) { 131 s/^$/$ENV{'HOME'}/; 132 if (-f "$_/perl" && -x "$_/perl") { 133 $default[$i] = "$_/perl"; last; 134 } 135 if (-x "$_/perl5") { 136 $default[$i] = "$_/perl5"; last; 137 } 138 } 139 } elsif ($macro eq "\@UUX\@") { 140 for (split (/:/, $ENV{'PATH'})) { 141 s/^$/$ENV{'HOME'}/; 142 if (-f "$_/uux" && -x "$_/uux") { 143 $default[$i] = "$_/uux"; last; 144 } 145 } 146 } elsif ($macro eq "\@SENDMAIL\@") { 147 for (split (/:/, $ENV{'PATH'} . ":/sbin:/usr/sbin:/usr/libexec:/usr/lib")) { 148 s/^$/$ENV{'HOME'}/; 149 if (-f "$_/sendmail" && -x "$_/sendmail") { 150 $default[$i] = "$_/sendmail"; last; 151 } 152 } 153 } elsif ($macro eq "\@DAEMONUID\@") { 154 if (! @getpwnam) { 155 if (! defined $value{'@DAEMONUSER@'}) { 156 die "\@DAEMONUSER\@ must be defined before \@DAEMONUID\@\n"; 157 } 158 @getpwnam = getpwnam ($value{'@DAEMONUSER@'}); 159 if (! @getpwnam) { 160 die "User $value{'@DAEMONUSER@'} doesn't exist\n"; 161 } 162 } 163 ($name, $_, $uid, $_, $_, $_, $_, $_, $_) = @getpwnam; 164 $default[$i] = $uid; 165 } elsif ($macro eq "\@DAEMONGID\@") { 166 if (! @getpwnam) { 167 if (! defined $value{'@DAEMONUSER@'}) { 168 die "\@DAEMONUSER\@ must be defined before \@DAEMONUID\@\n"; 169 } 170 @getpwnam = getpwnam ($value{'@DAEMONUSER@'}); 171 if (! @getpwnam) { 172 die "User $value{'@DAEMONUSER@'} doesn't exist\n"; 173 } 174 } 175 ($name, $_, $_, $gid, $_, $_, $_, $_, $_) = @getpwnam; 176 $default[$i] = $gid; 177 } elsif ($macro eq '@CFLAGS@') { 178 if (defined $value{'@CC@'} && $value{'@CC@'} =~ /gcc/) { 179 $default[$i] = "-O2 -Wall -W"; 180 } else { 181 $default[$i] = "-O"; 182 } 183 } elsif ($macro eq '@INSTALLMAILER@') { 184 if (defined ($value{'@SENDMAILVERS@'})) { 185 if ($value{'@SENDMAILVERS@'} =~ /^\s*8\.[6-9](\..*)?\s*$/) { 186 $default[$i] = 'true'; 187 } else { 188 $default[$i] = 'false'; 189 } 190 } elsif (defined ($value{'@OLDSENDMAIL@'})) { 191 $default[$i] = "true"; 192 } else { 193 die "Either \@OLDSENDMAIL\@ or \@SENDMAILVERS\@ must be defined\n" . 194 "before \@INSTALLMAILER\@\n"; 195 } 196 } elsif ($macro eq '@MAILERVERSION@') { 197 if (defined ($value{'@SENDMAILVERS@'})) { 198 if ($value{'@SENDMAILVERS@'} =~ /^\s*8\.6(\..*)?\s*$/) { 199 $default[$i] = '8.6'; 200 } elsif ($value{'@SENDMAILVERS@'} =~ /^\s*8\.7(\..*)?\s*$/) { 201 $default[$i] = '8.7'; 202 } elsif ($value{'@SENDMAILVERS@'} =~ /^\s*8\.8(\..*)?\s*$/) { 203 $default[$i] = '8.8'; 204 } elsif ($value{'@SENDMAILVERS@'} =~ /^\s*8\.9(\..*)?\s*$/) { 205 $default[$i] = '8.9'; 206 } elsif ($value{'@SENDMAILVERS@'} =~ /^\s*8\.10(\..*)?\s*$/) { 207 $default[$i] = '8.10'; 208 } elsif ($value{'@SENDMAILVERS@'} =~ /^\s*8\.11(\..*)?\s*$/) { 209 $default[$i] = '8.11'; 210 } elsif ($value{'@SENDMAILVERS@'} =~ /^\s*8\.12(\..*)?\s*$/) { 211 $default[$i] = '8.12'; 212 } elsif ($value{'@SENDMAILVERS@'} =~ /^\s*8\.13(\..*)?\s*$/) { 213 $default[$i] = '8.13'; 214 } elsif ($value{'@SENDMAILVERS@'} =~ /^\s*8\.14(\..*)?\s*$/) { 215 $default[$i] = '8.14'; 216 } else { 217 $default[$i] = ''; # Will not be installed 218 } 219 } elsif (defined ($value{'@OLDSENDMAIL@'})) { 220 if ($value{'@OLDSENDMAIL@'} =~ /^false$/) { 221 $default[$i] = '8.7'; 222 } else { 223 $default[$i] = '8.6'; 224 } 225 } else { 226 die "Either \@OLDSENDMAIL\@ or \@SENDMAILVERS\@ must be defined\n" . 227 "before \@MAILERVERSION\@\n"; 228 } 229 } elsif ($macro eq '@LOCKDEFINE@') { 230 if (! defined ($value{'@FLOCK@'})) { 231 die "\@FLOCK\@ must be defined before \@LOCKDEFINE\@\n"; 232 } 233 if ($value{'@FLOCK@'} =~ /^\s*(y(es?)?|t(r(ue?)?)?)\s*$/i) { 234 $default[$i] = '-DUSE_FLOCK'; 235 } else { 236 $default[$i] = '-DUSE_LOCKFILES'; 237 } 238 } elsif ($macro eq '@BATCHER@') { 239 if (! defined ($value{'@FLOCK@'})) { 240 die "\@FLOCK\@ must be defined before \@BATCHER\@\n"; 241 } 242 if ($value{'@FLOCK@'} =~ /^\s*(y(es?)?|t(r(ue?)?)?)\s*$/i) { 243 $default[$i] = 'batcher.new'; 244 } else { 245 $default[$i] = 'batcher'; 246 } 247 } else { 248 die "Autoconf macro $macro not defined yet\n"; 249 } 250 } else { 251 $flag[$i] = "conf"; 252 } 253 if ($flag[$i] =~ /conf/) { 254 print "$help[$i] [$default[$i]]: "; 255 $answer = <STDIN>; 256 $answer =~ tr/\r\n//d; 257 if ($answer =~ /^$/) { 258 $answer = $default[$i]; 259 } 260 $default[$i] = $answer; 261 } 262 $value{$macro[$i]} = $default[$i]; 263 $i ++; 264 } 265 $max = $i; 266 267 close CONFIGIN; 268 print "Writing config.sed\n"; 269 open (CONFIGSED, ">config.sed") || die "Can\'t open config.sed\n"; 270 for ($i = 0; $i < $max; $i ++) { 271 next if ($macro[$i] =~ /^\>/); 272 print "s,", $macro[$i], ","; 273 print CONFIGSED "s,", $macro[$i], ","; 274 $_ = $value{$macro[$i]}; 275 s/\,/\\\,/g; 276 print; 277 print CONFIGSED; 278 print ",\n"; 279 print CONFIGSED ",\n"; 280 } 281 close CONFIGSED; 282} else { 283 print "Redoing configuration with old values\n"; 284} 285for (@conffiles) { 286 print "$_.in -> $_: "; 287 if (system ("sed -f config.sed <$_.in >$_")) { 288 print "Error\n"; 289 } else { 290 print "ok\n"; 291 } 292} 293exit 0; 294