Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / contrib / sendmail-8.14 / devtools / bin / Build
1 #!/bin/sh
2
3 # Copyright (c) 1998-2002, 2008 Sendmail, Inc. and its suppliers.
4 #       All rights reserved.
5 # Copyright (c) 1993, 1996-1997 Eric P. Allman.  All rights reserved.
6 # Copyright (c) 1993
7 #       The Regents of the University of California.  All rights reserved.
8 #
9 # By using this file, you agree to the terms and conditions set
10 # forth in the LICENSE file which can be found at the top level of
11 # the sendmail distribution.
12 #
13 #
14 #       $Id: Build,v 8.187 2008/01/11 18:40:17 ca Exp $
15 #
16
17 #
18 #  A quick-and-dirty script to compile sendmail and related programs
19 #  in the presence of multiple architectures.  To use, just use
20 #  "sh Build".
21 #
22
23 trap "rm -f $obj/.settings$$; exit" 1 2 3 15
24
25 cflag=""
26 mflag=""
27 Mflag=""
28 Aflag=""
29 sflag=""
30 makeargs=""
31 libdirs=""
32 incdirs=""
33 libsrch=""
34 libpath=""
35 siteconfig=""
36 pfx=""
37 obj=""
38 oscf=""
39 arch=""
40 os=""
41 rel=""
42 mkdir="mkdir -p"
43 SENDMAIL_BUILD_FLAGS=""
44 EX_OK=0
45 EX_USAGE=64
46 EX_NOINPUT=66
47 EX_UNAVAILABLE=69
48 SHELL=/bin/sh
49
50 # default to a optimized build to behave like the old system.
51 build_variant="optimized"
52
53 full_src_dir=`pwd`
54 if [ -z "$src_dir" ]
55 then
56         src_dir=`basename ${full_src_dir}`
57 fi
58 absolute_base_dir=`echo ${full_src_dir} | sed "s#${src_dir}\\$##"`
59 obj_rel_base_dir='../..'
60
61 while [ ! -z "$1" ]
62 do
63         case $1
64         in
65           -src) # Specify pathname of source directory relative to
66                 # root of cvs tree.  This relative pathname may have
67                 # multiple components, as in 'foo/bar/baz', and will also
68                 # be used to form the pathname of the object directory.
69                 shift
70                 arg=$1
71                 if [ -z "$arg" ]
72                 then
73                         echo "Missing arg for -src" >&2
74                         exit $EX_USAGE
75                 fi
76                 case $arg
77                 in
78                   /*)   echo "Arg for -src must not begin with / ($arg)" >&2
79                         exit $EX_USAGE
80                         ;;
81                 esac
82                 src_dir="$arg"
83                 absolute_base_dir=`echo ${full_src_dir} | sed "s;/${src_dir}$;;"`
84                 obj_rel_base_dir=`echo x/${src_dir} | sed "s;[^/][^/]*;..;g"`
85                 SMROOT=${absolute_base_dir}
86                 shift
87                 ;;
88           -c)   # clean out existing $obj tree
89                 cflag=1
90                 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS $1"
91                 shift
92                 ;;
93
94           -m)   # show Makefile name only
95                 mflag=1
96                 shift
97                 ;;
98
99           -M)   # show the name of the obj. directory
100                 Mflag=1
101                 shift
102                 ;;
103
104           -A)   # show the name of the architecture
105                 Aflag=1
106                 shift
107                 ;;
108
109           -E*)  # environment variables to pass into Build
110                 arg=`echo $1 | sed 's/^-E//'`
111                 if [ -z "$arg" ]
112                 then
113                         shift   # move to argument
114                         arg=$1
115                 fi
116                 if [ -z "$arg" ]
117                 then
118                         echo "Empty -E flag" >&2
119                         exit $EX_USAGE
120                 else
121                         case $arg
122                         in
123                           *=*)  # check format
124                                 eval $arg
125                                 export `echo $arg | sed 's;=.*;;'`
126                                 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -E \"$arg\""
127                                 ;;
128                           *)    # bad format
129                                 echo "Bad format for -E argument ($arg)" >&2
130                                 exit $EX_USAGE
131                                 ;;
132                         esac
133                         shift
134                 fi
135                 ;;
136
137           -L*)  # set up LIBDIRS
138                 libdirs="$libdirs $1"
139                 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS $1"
140                 shift
141                 ;;
142
143           -I*)  # set up INCDIRS
144                 incdirs="$incdirs $1"
145                 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS $1"
146                 shift
147                 ;;
148
149           -f*)  # select site config file
150                 arg=`echo $1 | sed 's/^-f//'`
151                 if [ -z "$arg" ]
152                 then
153                         shift   # move to argument
154                         arg=$1
155                 fi
156                 if [ "$pfx" ]
157                 then
158                         echo "May not use -f and -Q together"
159                         exit $EX_USAGE
160                 fi
161                 if [ "$siteconfig" ]
162                 then
163                         echo "Only one -f flag allowed" >&2
164                         exit $EX_USAGE
165                 else
166                         siteconfig=$arg
167                         if [ -z "$siteconfig" ]
168                         then
169                                 echo "Missing argument for -f flag" >&2
170                                 exit $EX_USAGE
171                         elif [ ! -f "$siteconfig" ]
172                         then
173                                 echo "${siteconfig}: File not found"
174                                 exit $EX_NOINPUT
175                         else
176                                 shift   # move past argument
177                                 case $arg
178                                 in
179                                         /*)
180                                         SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -f \"$siteconfig\""
181                                         ;;
182                                         *)
183                                         SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -f \"${full_src_dir}/$siteconfig\""
184                                         ;;
185                                 esac
186                         fi
187                 fi
188                 ;;
189
190           -O*) # Set object directory manually.
191                 arg="`echo $1 | sed 's/^-O//'`"
192                 if [ -z "$arg" ]
193                 then
194                         shift   # move to argument
195                         arg="$1"
196                 fi
197                 case $arg
198                 in
199                         /*)
200                         OBJ_ROOT="$arg"
201                         SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -O \"$OBJ_ROOT\""
202                         obj_rel_base_dir=$absolute_base_dir
203                         ;;
204                         *)
205                         echo "Absolute directory path required for -O flag" >&2
206                         exit $EX_USAGE
207                         ;;
208                 esac
209                 shift
210                 ;;
211
212           -S)   # skip auto-configure
213                 sflag="-s"
214                 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS $1"
215                 shift
216                 ;;
217
218           -Q*)  # Select a prefix for the Site/*.config.m4 file
219                 arg=`echo $1 | sed 's/^-Q//'`
220                 if [ -z "$arg" ]
221                 then
222                         shift   # move to argument
223                         arg=$1
224                 fi
225                 if [ -z "$arg" ]
226                 then
227                         echo "Empty -Q flag" >&2
228                         exit $EX_USAGE
229                 elif [ "$siteconfig" ]
230                 then
231                         echo "May not use -Q and -f together" >&2
232                         exit $EX_USAGE
233                 elif [ "$pfx" ]
234                 then
235                         echo "Only one -Q allowed" >&2
236                         exit $EX_USAGE
237                 else
238                         pfx=$arg
239                         SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -Q \"$pfx\""
240                 fi
241                 shift
242                 ;;
243
244           -v)   # Select a build variant: debug, optimized, purify, whatever.
245                 shift
246                 build_variant=$1
247                 if [ -z "$build_variant" ]
248                 then
249                         echo "Usage error with \"-v\" <build_variant>"  >&2
250                         echo "You must specify exactly one build variant of debug|optimized|purify"  >&2
251                         exit $EX_USAGE
252                 fi
253                 shift
254                 ;;
255
256           *)    # pass argument to make
257                 makeargs="$makeargs \"$1\""
258                 #SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS \"$1\""
259                 shift
260                 ;;
261         esac
262 done
263
264 # process selected build variant.
265 case $build_variant in
266         debug)
267                 M4_BLDVARIANT_FLAGS="-DconfBLDVARIANT=DEBUG"
268                 ;;
269         optimized)
270                 M4_BLDVARIANT_FLAGS="-DconfBLDVARIANT=OPTIMIZED"
271                 ;;
272         purify)
273                 M4_BLDVARIANT_FLAGS="-DconfBLDVARIANT=PURIFY"
274                 echo "Sorry, the purify build variant has not been plumbed yet. (Bummer.)"  >&2
275                 exit $EX_USAGE
276                 ;;
277         *)
278                 exit $EX_USAGE
279                 ;;
280 esac
281
282
283 #
284 #  Do heuristic guesses !ONLY! for machines that do not have uname
285 #
286 if [ -d /NextApps -a ! -f /bin/uname -a ! -f /usr/bin/uname ]
287 then
288         # probably a NeXT box
289         arch=`hostinfo | sed -n 's/.*Processor type: \([^ ]*\).*/\1/p'`
290         os=NeXT
291         rel=`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`
292 elif [ -f /usr/sony/bin/machine -a -f /etc/osversion ]
293 then
294         # probably a Sony NEWS 4.x
295         os=NEWS-OS
296         rel=`awk '{ print $3}' /etc/osversion`
297         arch=`/usr/sony/bin/machine`
298 elif [ -d /usr/omron -a -f /bin/luna ]
299 then
300         # probably a Omron LUNA
301         os=LUNA
302         if [ -f /bin/luna1 ] && /bin/luna1
303         then
304                 rel=unios-b
305                 arch=luna1
306         elif [ -f /bin/luna2 ] && /bin/luna2
307         then
308                 rel=Mach
309                 arch=luna2
310         elif [ -f /bin/luna88k ] && /bin/luna88k
311         then
312                 rel=Mach
313                 arch=luna88k
314         fi
315 elif [ -d /usr/apollo -a -d \`node_data ]
316 then
317         # probably a Apollo/DOMAIN
318         os=DomainOS
319         arch=$ISP
320         rel=`/usr/apollo/bin/bldt | grep Domain | awk '{ print $4 }' | sed -e 's/,//g'`
321 fi
322
323 if [ ! "$arch" -a ! "$os" -a ! "$rel" ]
324 then
325         arch=`uname -m | sed -e 's/ //g' -e 's/\//-/g'`
326         os=`uname -s | sed -e 's/\//-/g' -e 's/ //g'`
327         rel=`uname -r | sed -e 's/(/-/g' -e 's/)//g' -e 's/ //g'`
328 fi
329
330 #
331 #  Tweak the values we have already got.  PLEASE LIMIT THESE to
332 #  tweaks that are absolutely necessary because your system uname
333 #  routine doesn't return something sufficiently unique.  Don't do
334 #  it just because you don't like the name that is returned.  You
335 #  can combine the architecture name with the os name to create a
336 #  unique Makefile name.
337 #
338
339 # tweak machine architecture
340 case $arch
341 in
342   sun4*)        arch=sun4;;
343
344   9000/*)       arch=`echo $arch | sed -e 's/9000.//' -e 's/..$/xx/'`;;
345
346   DS/907000)    arch=ds90;;
347
348   NILE*)        arch=NILE
349                 os=`uname -v`;;
350
351   CRAYT3E)      os=UNICOS-mk;;
352                 
353   CRAY[CJT]90*|CRAYTS|CRAYSV1*|CRAYY-MP)
354                 os=UNICOS;;
355 esac
356
357 # tweak operating system type and release
358 node=`uname -n | sed -e 's/\//-/g' -e 's/ //g'`
359 if [ "$os" = "$node" -a "$arch" = "i386" -a "$rel" = 3.2 -a "`uname -v`" = 2 ]
360 then
361         # old versions of SCO UNIX set uname -s the same as uname -n
362         os=SCO_SV
363 fi
364 if [ "$rel" = 4.0 ]
365 then
366         case $arch in
367           3[34]??|3[34]??,*|3[34]??[A-Z]|4[48]??|56??)
368                 if [ -d /usr/sadm/sysadm/add-ons/WIN-TCP ]
369                 then
370                         os=NCR.MP-RAS
371                         rel=2.x
372                         arch=i486
373                 elif [ -d /usr/sadm/sysadm/add-ons/inet ]
374                 then
375                         os=NCR.MP-RAS
376                         rel=3.x
377                         arch=i486
378                 fi
379                 ;;
380         esac
381 fi
382
383 case $os
384 in
385   DYNIX-ptx)    os=PTX;;
386   Paragon*)     os=Paragon;;
387   HP-UX)        rel=`echo $rel | sed -e 's/^[^.]*\.0*//'`;;
388   AIX)          osl=""
389                 if [ -x /bin/lslpp ]
390                 then
391                         osl=`/bin/lslpp -Lcq bos.rte | cut -f3 -d: | cut -f1-3 -d. 2>/dev/null`
392                         if [ $? = 0  -a -n "$osl" ]
393                         then
394                                 rel=$osl
395                         else
396                                 # command failed; fall back to old method
397                                 osl=""
398                         fi
399                 fi
400                 # check whether it worked
401                 if [ -z "$osl" ]
402                 then
403                         rela=$rel
404                         rel=`uname -v`
405                         rel=$rel.$rela
406                 fi
407                 arch=PPC
408                 ;;
409   BSD-386)      os=BSD-OS;;
410   SCO_SV)       rel=`uname -X | sed -n 's/Release = //p'`
411                 if [ "$rel" = "5v6.0.0" ]
412                 then
413                   os=OSR; rel=`uname -X | sed -n 's/Release = //p'`
414                 else
415                   os=SCO; rel=`uname -X | sed -n 's/Release = 3.2v//p'`
416                 fi;;
417   UNIX_System_V) if [ "$arch" = "ds90" ]
418                 then
419                         os="UXPDS"
420                         rel=`uname -v | sed -e 's/\(V.*\)L.*/\1/'`
421                 fi;;
422   ReliantUNIX-?|SINIX-?)        os=SINIX;;
423   DomainOS)     case $rel in
424                   10.4*)        rel=10.4;;
425                 esac
426                 ;;
427   IRIX*)        rel=`echo $rel | sed -e 's/-.*$//'`;;
428   NeXT)         mkdir="mkdirs";;
429   UNICOSMK)     rel=`echo $rel | sed -e 's/\(.*\)\.\(.*\)\.\(.*\)\..*$/\1.\2.\3/'`;;
430   UNICOS*)      rel=`echo $rel | sed -e 's/\(.*\)\.\(.*\)\..*$/\1.\2/'`;;
431 esac
432
433 # get "base part" of operating system release
434 rroot=`echo $rel | sed -e 's/\.[^.]*$//'`
435 rbase=`echo $rel | sed -e 's/\..*//'`
436 if [ "$rroot" = "$rbase" ]
437 then
438         rroot=$rel
439 fi
440
441 # heuristic tweaks to clean up names -- PLEASE LIMIT THESE!
442 if [ "$os" = "unix" ]
443 then
444         # might be Altos System V
445         case $rel
446         in
447           5.3*)         os=Altos;;
448         esac
449 elif [ -r /unix -a -r /usr/lib/libseq.a -a -r /lib/cpp ]
450 then
451         # might be a DYNIX/ptx 2.x system, which has a broken uname
452         if strings /lib/cpp | grep _SEQUENT_ > /dev/null
453         then
454                 os=PTX
455         fi
456 elif [ -d /usr/nec ]
457 then
458         # NEC machine -- what is it running?
459         if [ "$os" = "UNIX_System_V" ]
460         then
461                 os=EWS-UX_V
462         elif [ "$os" = "UNIX_SV" ]
463         then
464                 os=UX4800
465         fi
466 elif [ "$arch" = "mips" ]
467 then
468         case $rel
469         in
470           4_*)
471                 if [ `uname -v` = "UMIPS" ]
472                 then
473                         os=RISCos
474                 fi;;
475         esac
476 fi
477
478 # see if there is a "user suffix" specified
479 if [ "${SENDMAIL_SUFFIX-}x" = "x" ]
480 then
481         sfx=""
482 else
483         sfx=".${SENDMAIL_SUFFIX}"
484 fi
485
486 if [ ! -n "$Mflag" -a ! -n "$Aflag" ]
487 then
488         echo "Configuration: pfx=$pfx, os=$os, rel=$rel, rbase=$rbase, rroot=$rroot, arch=$arch, sfx=$sfx, variant=$build_variant"
489 fi
490
491 SMROOT=${SMROOT-`(cd ..;pwd)`}
492 BUILDTOOLS=${BUILDTOOLS-$SMROOT/devtools}
493 export SMROOT BUILDTOOLS
494
495 # see if we are in a Build-able directory
496 if [ ! -f Makefile.m4 -a ! -n "$Aflag" ]; then
497         echo "Makefile.m4 not found.  Build can only be run from a source directory."
498         exit $EX_UNAVAILABLE
499 fi
500
501 incdirs="$incdirs -I\${SRCDIR}/include"
502
503 if [ -z "$OBJ_ROOT" ]; then
504         OBJ_ROOT=${SMROOT}
505 fi
506
507 if [ "${pfx}x" = "x" ]
508 then
509         prefix=""
510 else
511         prefix=".$pfx"
512 fi
513
514 # Print out the architecture (to build up an obj dir path) and exit
515 if [ -n "$Aflag" ]
516 then
517         echo "$os.$rel.$arch$sfx"
518         exit $EX_OK
519 fi
520
521 # now try to find a reasonable object directory
522 if [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rel.$arch$sfx ]; then
523         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rel.$arch$sfx
524 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rroot.$arch$sfx ]; then
525         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rroot.$arch$sfx
526 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rbase.x.$arch$sfx ]; then
527         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rbase.x.$arch$sfx
528 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rel$sfx ]; then
529         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rel$sfx
530 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rbase.x$sfx ]; then
531         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rbase.x$sfx
532 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$arch$sfx ]; then
533         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$arch$sfx
534 elif [ -r ${OBJ_ROOT}/obj${prefix}.$rel.$arch$sfx ]; then
535         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$rel.$arch$sfx
536 elif [ -r ${OBJ_ROOT}/obj${prefix}.$rbase.x.$arch$sfx ]; then
537         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$rbase.x.$arch$sfx
538 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os$sfx ]; then
539         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os$sfx
540 elif [ -r ${OBJ_ROOT}/obj${prefix}.$arch$sfx ]; then
541         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$arch$sfx
542 elif [ -r ${OBJ_ROOT}/obj${prefix}.$rel$sfx ]; then
543         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$rel$sfx
544 elif [ -r ${OBJ_ROOT}/obj${prefix}.$sfx ]; then
545         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$sfx
546 fi
547
548 if [ -n "$abs_obj_dir" ]
549 then
550         obj=${abs_obj_dir}/${src_dir}
551 fi
552
553 # Print the directory which would be used for the build and exit
554 if [ -n "$Mflag" ]
555 then
556         if [ ! -n "$obj" ]
557         then
558                 obj=${OBJ_ROOT}/obj.$os.$rel.$arch$sfx/${src_dir}
559         fi
560         echo "$obj"
561         exit $EX_OK
562 fi
563
564 # Check if trying to use -f with an existing obj directory
565 if [ -n "$siteconfig" -a -n "$obj" -a -d "$obj" -a -z "$cflag" ]
566 then
567         echo "Can not use Build's -f flag with an existing object tree."
568         echo "If you wish to change configuration information, use the -c flag to clear"
569         echo "the existing $obj tree."
570         exit $EX_USAGE
571 fi
572
573 # Check if trying to use -Q with an existing obj directory
574 if [ -n "$pfx" -a -n "$obj" -a -d "$obj" -a -z "$cflag" ]
575 then
576         echo "Can not use Build's -Q flag with an existing object tree."
577         echo "If you wish to change configuration information, use the -c flag to clear"
578         echo "the existing $obj tree."
579         exit $EX_USAGE
580 fi
581
582
583 # Clean out the directory before building.
584 if [ "$cflag" ]
585 then
586         if [ -n "$obj" ]
587         then
588                 echo "Clearing out existing $obj tree"
589                 rm -rf $obj
590         fi
591 fi
592
593 # If we didn't detect an existing obj directory, makeup a new obj name.
594 if [ -z "$obj" ]
595 then
596         abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rel.$arch$sfx
597         obj=${abs_obj_dir}/${src_dir}
598 fi
599
600 # Check if obj directory exists
601 if [ ! -r "$obj" ]
602 then
603         if [ -r $BUILDTOOLS/OS/$os.$rel.$arch$sfx ]; then
604                 oscf=$os.$rel.$arch$sfx
605         elif [ -r $BUILDTOOLS/OS/$os.$rel.$arch ]; then
606                 oscf=$os.$rel.$arch
607         elif [ -r $BUILDTOOLS/OS/$os.$rroot.$arch$sfx ]; then
608                 oscf=$os.$rroot.$arch$sfx
609         elif [ -r $BUILDTOOLS/OS/$os.$rroot.$arch ]; then
610                 oscf=$os.$rroot.$arch
611         elif [ -r $BUILDTOOLS/OS/$os.$rbase.x.$arch$sfx ]; then
612                 oscf=$os.$rbase.x.$arch$sfx
613         elif [ -r $BUILDTOOLS/OS/$os.$rbase.x.$arch ]; then
614                 oscf=$os.$rbase.x.$arch
615         elif [ -r $BUILDTOOLS/OS/$os.$rel$sfx ]; then
616                 oscf=$os.$rel$sfx
617         elif [ -r $BUILDTOOLS/OS/$os.$rel ]; then
618                 oscf=$os.$rel
619         elif [ -r $BUILDTOOLS/OS/$os.$rroot$sfx ]; then
620                 oscf=$os.$rroot$sfx
621         elif [ -r $BUILDTOOLS/OS/$os.$rroot ]; then
622                 oscf=$os.$rroot
623         elif [ -r $BUILDTOOLS/OS/$os.$rbase.x$sfx ]; then
624                 oscf=$os.$rbase.x$sfx
625         elif [ -r $BUILDTOOLS/OS/$os.$rbase.x ]; then
626                 oscf=$os.$rbase.x
627         elif [ -r $BUILDTOOLS/OS/$os.$arch$sfx ]; then
628                 oscf=$os.$arch$sfx
629         elif [ -r $BUILDTOOLS/OS/$os.$arch ]; then
630                 oscf=$os.$arch
631         elif [ -r $BUILDTOOLS/OS/$rel.$arch$sfx ]; then
632                 oscf=$rel.$arch$sfx
633         elif [ -r $BUILDTOOLS/OS/$rel.$arch ]; then
634                 oscf=$rel.$arch
635         elif [ -r $BUILDTOOLS/OS/$rroot.$arch$sfx ]; then
636                 oscf=$rroot.$arch$sfx
637         elif [ -r $BUILDTOOLS/OS/$rroot.$arch ]; then
638                 oscf=$rroot.$arch
639         elif [ -r $BUILDTOOLS/OS/$rbase.x.$arch$sfx ]; then
640                 oscf=$rbase.x.$arch$sfx
641         elif [ -r $BUILDTOOLS/OS/$rbase.x.$arch ]; then
642                 oscf=$rbase.x.$arch
643         elif [ -r $BUILDTOOLS/OS/$os$sfx ]; then
644                 oscf=$os$sfx
645         elif [ -r $BUILDTOOLS/OS/$os ]; then
646                 oscf=$os
647         elif [ -r $BUILDTOOLS/OS/$arch$sfx ]; then
648                 oscf=$arch$sfx
649         elif [ -r $BUILDTOOLS/OS/$arch ]; then
650                 oscf=$arch
651         elif [ -r $BUILDTOOLS/OS/$rel$sfx ]; then
652                 oscf=$rel$sfx
653         elif [ -r $BUILDTOOLS/OS/$rel ]; then
654                 oscf=$rel
655         elif [ -r $BUILDTOOLS/OS/$rel$sfx ]; then
656                 oscf=$rel$sfx
657         else
658                 echo "Cannot determine how to support $os.$rel.$arch" >&2
659                 exit $EX_UNAVAILABLE
660         fi
661         M4=`$SHELL $BUILDTOOLS/bin/find_m4.sh`
662         ret=$?
663         if [ $ret -ne 0 ]
664         then
665                 exit $ret
666         fi
667         echo "Using M4=$M4"
668         export M4
669         if [ "$mflag" ]
670         then
671                 echo "Will run in virgin $obj using $BUILDTOOLS/OS/$oscf"
672                 exit $EX_OK
673         fi
674
675         echo "Creating $obj using $BUILDTOOLS/OS/$oscf"
676         ${mkdir} $obj
677
678                 ln="ln -s"
679                 (cd $obj
680                 # This glob doesn't actually glob to something everywhere,
681                 # thus the protective measures.
682                 for i in ${obj_rel_base_dir}/${src_dir}/*.[chly13458]
683                 do
684                         if [ -f $i ]
685                         then
686                                 $ln $i .
687                         fi
688                 done
689                 # This glob doesn't actually glob to something everywhere,
690                 # thus the protective measures.
691                 for i in ${obj_rel_base_dir}/${src_dir}/*.0
692                 do
693                         if [ -f $i ]
694                         then
695                                 $ln $i `basename $i`.dist
696                         fi
697                 done)
698                 if [ -f helpfile ]
699                 then
700                         (cd $obj; $ln ${obj_rel_base_dir}/${src_dir}/helpfile .)
701                 fi
702
703         rm -f $obj/.settings$$
704         echo 'divert(-1)' > $obj/.settings$$
705         cat $BUILDTOOLS/M4/header.m4 >> $obj/.settings$$
706         echo "define(\`bldOS', \`\`$os'')" >> $obj/.settings$$
707         echo "define(\`bldREL', \`\`$rel'')" >> $obj/.settings$$
708         echo "define(\`bldARCH', \`\`$arch'')" >> $obj/.settings$$
709         cat $BUILDTOOLS/OS/$oscf >> $obj/.settings$$
710
711         cur_dir=`pwd`
712         cd $obj/..
713         absolute_obj_dir=`pwd`
714
715
716         cd $cur_dir
717         echo "ifdef(\`bldABS_OBJ_DIR',,\`define(\`bldABS_OBJ_DIR', \`$absolute_obj_dir')')" >> $obj/.settings$$
718         rel_src_dir="$obj_rel_base_dir/$src_dir"
719         echo "define(\`bldSRC_NAME', \`$src_dir')" >> $obj/.settings$$
720         echo "define(\`bldREL_SRC_DIR', \`$rel_src_dir')" >> $obj/.settings$$
721
722         if [ ! -z "$pfx" ]
723         then
724                 # They gave us a specific prefix, let's try it out.
725                 if [ -f $BUILDTOOLS/Site/$pfx.$oscf$sfx.m4 ]
726                 then
727                         siteconfig=$BUILDTOOLS/Site/$pfx.$oscf$sfx.m4
728                 elif [ -f $BUILDTOOLS/Site/$pfx.$oscf.m4 ]
729                 then
730                         siteconfig=$BUILDTOOLS/Site/$pfx.$oscf.m4
731                 fi
732                 if [ -f $BUILDTOOLS/Site/$pfx.config.m4 ]
733                 then
734                         siteconfig="$BUILDTOOLS/Site/$pfx.config.m4 $siteconfig"
735                 fi
736         elif [ -z "$siteconfig" ]
737         then
738                 # none specified, use defaults
739                 if [ -f $BUILDTOOLS/Site/site.$oscf$sfx.m4 ]
740                 then
741                         siteconfig=$BUILDTOOLS/Site/site.$oscf$sfx.m4
742                 elif [ -f $BUILDTOOLS/Site/site.$oscf.m4 ]
743                 then
744                         siteconfig=$BUILDTOOLS/Site/site.$oscf.m4
745                 fi
746                 if [ -f $BUILDTOOLS/Site/site.config.m4 ]
747                 then
748                         siteconfig="$BUILDTOOLS/Site/site.config.m4 $siteconfig"
749                 fi
750                 if [ -f $BUILDTOOLS/Site/site.post.m4 ]
751                 then
752                         siteconfig="$siteconfig $BUILDTOOLS/Site/site.post.m4"
753                 fi
754         fi
755         if [ ! -z "$siteconfig" ]
756         then
757                 echo "Including $siteconfig"
758                 cat $siteconfig >> $obj/.settings$$
759         fi
760         if [ "$libdirs" ]
761         then
762                 echo "define(\`confLIBDIRS', confLIBDIRS \`\`$libdirs'')" >> $obj/.settings$$
763         fi
764         if [ "$incdirs" ]
765         then
766                 echo "define(\`confINCDIRS', \`\`$incdirs'' confINCDIRS)" >> $obj/.settings$$
767         fi
768         echo "define(\`_SRC_PATH_', \`\`$obj_rel_base_dir'')" >> $obj/.settings$$
769         echo "define(\`bldSRC_PATH', \`\`$obj_rel_base_dir'')" >> $obj/.settings$$
770         echo 'divert(0)dnl' >> $obj/.settings$$
771         libdirs=`(cat $obj/.settings$$; echo "_SRIDBIL_= confLIBDIRS" ) | \
772                 sed -e 's/\(.\)include/\1_include_/g' -e 's/#define/#_define_/g' | \
773                 ${M4} ${M4_BLDVARIANT_FLAGS} -DconfBUILDTOOLSDIR=$BUILDTOOLS - | \
774                 grep "^_SRIDBIL_=" | \
775                 sed -e 's/#_define_/#define/g' -e 's/_include_/include/g' -e "s/^_SRIDBIL_=//"`
776         libsrch=`(cat $obj/.settings$$; echo "_HCRSBIL_= confLIBSEARCH" ) | \
777                 sed -e 's/\(.\)include/\1_include_/g' -e 's/#define/#_define_/g' | \
778                 ${M4}  ${M4_BLDVARIANT_FLAGS} -DconfBUILDTOOLSDIR=$BUILDTOOLS - | \
779                 grep "^_HCRSBIL_=" | \
780                 sed -e 's/#_define_/#define/g' -e 's/_include_/include/g' -e "s/^_HCRSBIL_=//"`
781         libpath=`(cat $obj/.settings$$; echo "_HCRSBIL_= confLIBSEARCHPATH" ) | \
782                 sed -e 's/\(.\)include/\1_include_/g' -e 's/#define/#_define_/g' | \
783                 ${M4} ${M4_BLDVARIANT_FLAGS} -DconfBUILDTOOLSDIR=$BUILDTOOLS - | \
784                 grep "^_HCRSBIL_=" | \
785                 sed -e 's/#_define_/#define/g' -e 's/_include_/include/g' -e "s/^_HCRSBIL_=//"`
786         echo 'divert(-1)' >> $obj/.settings$$
787         LIBDIRS="$libdirs" LIBSRCH="$libsrch" LIBPATH="$libpath" SITECONFIG="$siteconfig" $SHELL $BUILDTOOLS/bin/configure.sh $sflag $oscf >> $obj/.settings$$
788         echo 'divert(0)dnl' >> $obj/.settings$$
789         sed -e 's/\(.\)include/\1_include_/g' -e 's/#define/#_define_/g' -e 's/\r//g' $obj/.settings$$ | \
790                 ${M4}  ${M4_BLDVARIANT_FLAGS} -DconfBUILDTOOLSDIR=$BUILDTOOLS - Makefile.m4 | \
791                 sed -e 's/#_define_/#define/g' -e 's/_include_/include/g' -e 's/\r//g' > $obj/Makefile
792         # That ^M up there was added by quoting it in emacs.
793         # Make has problems if lines end in ^M^M, but not in ^M apparently
794         if [ $? -ne 0 -o ! -s $obj/Makefile ]
795         then
796                 echo "ERROR: ${M4} failed; You may need a newer version of M4, at least as new as System V or GNU" 1>&2
797                 rm -rf $obj
798                 exit $EX_UNAVAILABLE
799         fi
800         rm -f $obj/.settings$$
801         echo "Making dependencies in $obj"
802         (cd $obj; ${MAKE-make} depend)
803 fi
804
805 if [ "$mflag" ]
806 then
807         makefile=`ls -l $obj/Makefile | sed 's/.* //'`
808         if [ -z "$makefile" ]
809         then
810                 echo "ERROR: $obj exists but has no Makefile" >&2
811                 exit $EX_NOINPUT
812         fi
813         echo "Will run in existing $obj using $makefile"
814         exit $EX_OK
815 fi
816
817 echo "Making in $obj"
818 cd $obj
819 eval exec ${MAKE-make} SENDMAIL_BUILD_FLAGS=\"$SENDMAIL_BUILD_FLAGS\" $makeargs