3 # Copyright (c) 1998-2002 Sendmail, Inc. and its suppliers.
5 # Copyright (c) 1993, 1996-1997 Eric P. Allman. All rights reserved.
7 # The Regents of the University of California. All rights reserved.
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.
14 # $Id: Build,v 8.186 2006/03/15 19:46:04 eric Exp $
18 # A quick-and-dirty script to compile sendmail and related programs
19 # in the presence of multiple architectures. To use, just use
23 trap "rm -f $obj/.settings$$; exit" 1 2 3 15
43 SENDMAIL_BUILD_FLAGS=""
50 # default to a optimized build to behave like the old system.
51 build_variant="optimized"
56 src_dir=`basename ${full_src_dir}`
58 absolute_base_dir=`echo ${full_src_dir} | sed "s#${src_dir}\\$##"`
59 obj_rel_base_dir='../..'
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.
73 echo "Missing arg for -src" >&2
78 /*) echo "Arg for -src must not begin with / ($arg)" >&2
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}
88 -c) # clean out existing $obj tree
90 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS $1"
94 -m) # show Makefile name only
99 -M) # show the name of the obj. directory
104 -A) # show the name of the architecture
109 -E*) # environment variables to pass into Build
110 arg=`echo $1 | sed 's/^-E//'`
113 shift # move to argument
118 echo "Empty -E flag" >&2
125 export `echo $arg | sed 's;=.*;;'`
126 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -E \"$arg\""
129 echo "Bad format for -E argument ($arg)" >&2
137 -L*) # set up LIBDIRS
138 libdirs="$libdirs $1"
139 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS $1"
143 -I*) # set up INCDIRS
144 incdirs="$incdirs $1"
145 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS $1"
149 -f*) # select site config file
150 arg=`echo $1 | sed 's/^-f//'`
153 shift # move to argument
158 echo "May not use -f and -Q together"
163 echo "Only one -f flag allowed" >&2
167 if [ -z "$siteconfig" ]
169 echo "Missing argument for -f flag" >&2
171 elif [ ! -f "$siteconfig" ]
173 echo "${siteconfig}: File not found"
176 shift # move past argument
180 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -f \"$siteconfig\""
183 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -f \"${full_src_dir}/$siteconfig\""
190 -O*) # Set object directory manually.
191 arg="`echo $1 | sed 's/^-O//'`"
194 shift # move to argument
201 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -O \"$OBJ_ROOT\""
202 obj_rel_base_dir=$absolute_base_dir
205 echo "Absolute directory path required for -O flag" >&2
212 -S) # skip auto-configure
214 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS $1"
218 -Q*) # Select a prefix for the Site/*.config.m4 file
219 arg=`echo $1 | sed 's/^-Q//'`
222 shift # move to argument
227 echo "Empty -Q flag" >&2
229 elif [ "$siteconfig" ]
231 echo "May not use -Q and -f together" >&2
235 echo "Only one -Q allowed" >&2
239 SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS -Q \"$pfx\""
244 -v) # Select a build variant: debug, optimized, purify, whatever.
247 if [ -z "$build_variant" ]
249 echo "Usage error with \"-v\" <build_variant>" >&2
250 echo "You must specify exactly one build variant of debug|optimized|purify" >&2
256 *) # pass argument to make
257 makeargs="$makeargs \"$1\""
258 #SENDMAIL_BUILD_FLAGS="$SENDMAIL_BUILD_FLAGS \"$1\""
264 # process selected build variant.
265 case $build_variant in
267 M4_BLDVARIANT_FLAGS="-DconfBLDVARIANT=DEBUG"
270 M4_BLDVARIANT_FLAGS="-DconfBLDVARIANT=OPTIMIZED"
273 M4_BLDVARIANT_FLAGS="-DconfBLDVARIANT=PURIFY"
274 echo "Sorry, the purify build variant has not been plumbed yet. (Bummer.)" >&2
284 # Do heuristic guesses !ONLY! for machines that do not have uname
286 if [ -d /NextApps -a ! -f /bin/uname -a ! -f /usr/bin/uname ]
288 # probably a NeXT box
289 arch=`hostinfo | sed -n 's/.*Processor type: \([^ ]*\).*/\1/p'`
291 rel=`hostinfo | sed -n 's/.*NeXT Mach \([0-9\.]*\).*/\1/p'`
292 elif [ -f /usr/sony/bin/machine -a -f /etc/osversion ]
294 # probably a Sony NEWS 4.x
296 rel=`awk '{ print $3}' /etc/osversion`
297 arch=`/usr/sony/bin/machine`
298 elif [ -d /usr/omron -a -f /bin/luna ]
300 # probably a Omron LUNA
302 if [ -f /bin/luna1 ] && /bin/luna1
306 elif [ -f /bin/luna2 ] && /bin/luna2
310 elif [ -f /bin/luna88k ] && /bin/luna88k
315 elif [ -d /usr/apollo -a -d \`node_data ]
317 # probably a Apollo/DOMAIN
320 rel=`/usr/apollo/bin/bldt | grep Domain | awk '{ print $4 }' | sed -e 's/,//g'`
323 if [ ! "$arch" -a ! "$os" -a ! "$rel" ]
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'`
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.
339 # tweak machine architecture
344 9000/*) arch=`echo $arch | sed -e 's/9000.//' -e 's/..$/xx/'`;;
346 DS/907000) arch=ds90;;
351 CRAYT3E) os=UNICOS-mk;;
353 CRAY[CJT]90*|CRAYTS|CRAYSV1*|CRAYY-MP)
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 ]
361 # old versions of SCO UNIX set uname -s the same as uname -n
367 3[34]??|3[34]??,*|3[34]??[A-Z]|4[48]??|56??)
368 if [ -d /usr/sadm/sysadm/add-ons/WIN-TCP ]
373 elif [ -d /usr/sadm/sysadm/add-ons/inet ]
386 Paragon*) os=Paragon;;
387 HP-UX) rel=`echo $rel | sed -e 's/^[^.]*\.0*//'`;;
391 osl=`/bin/lslpp -Lcq bos.rte | cut -f3 -d: | cut -f1-3 -d. 2>/dev/null`
392 if [ $? = 0 -a -n "$osl" ]
396 # command failed; fall back to old method
400 # check whether it worked
410 SCO_SV) os=SCO; rel=`uname -X | sed -n 's/Release = 3.2v//p'`;;
411 UNIX_System_V) if [ "$arch" = "ds90" ]
414 rel=`uname -v | sed -e 's/\(V.*\)L.*/\1/'`
416 ReliantUNIX-?|SINIX-?) os=SINIX;;
417 DomainOS) case $rel in
421 IRIX*) rel=`echo $rel | sed -e 's/-.*$//'`;;
422 NeXT) mkdir="mkdirs";;
423 UNICOSMK) rel=`echo $rel | sed -e 's/\(.*\)\.\(.*\)\.\(.*\)\..*$/\1.\2.\3/'`;;
424 UNICOS*) rel=`echo $rel | sed -e 's/\(.*\)\.\(.*\)\..*$/\1.\2/'`;;
427 # get "base part" of operating system release
428 rroot=`echo $rel | sed -e 's/\.[^.]*$//'`
429 rbase=`echo $rel | sed -e 's/\..*//'`
430 if [ "$rroot" = "$rbase" ]
435 # heuristic tweaks to clean up names -- PLEASE LIMIT THESE!
436 if [ "$os" = "unix" ]
438 # might be Altos System V
443 elif [ -r /unix -a -r /usr/lib/libseq.a -a -r /lib/cpp ]
445 # might be a DYNIX/ptx 2.x system, which has a broken uname
446 if strings /lib/cpp | grep _SEQUENT_ > /dev/null
452 # NEC machine -- what is it running?
453 if [ "$os" = "UNIX_System_V" ]
456 elif [ "$os" = "UNIX_SV" ]
460 elif [ "$arch" = "mips" ]
465 if [ `uname -v` = "UMIPS" ]
472 # see if there is a "user suffix" specified
473 if [ "${SENDMAIL_SUFFIX-}x" = "x" ]
477 sfx=".${SENDMAIL_SUFFIX}"
480 if [ ! -n "$Mflag" -a ! -n "$Aflag" ]
482 echo "Configuration: pfx=$pfx, os=$os, rel=$rel, rbase=$rbase, rroot=$rroot, arch=$arch, sfx=$sfx, variant=$build_variant"
485 SMROOT=${SMROOT-`(cd ..;pwd)`}
486 BUILDTOOLS=${BUILDTOOLS-$SMROOT/devtools}
487 export SMROOT BUILDTOOLS
489 # see if we are in a Build-able directory
490 if [ ! -f Makefile.m4 -a ! -n "$Aflag" ]; then
491 echo "Makefile.m4 not found. Build can only be run from a source directory."
495 incdirs="$incdirs -I\${SRCDIR}/include"
497 if [ -z "$OBJ_ROOT" ]; then
501 if [ "${pfx}x" = "x" ]
508 # Print out the architecture (to build up an obj dir path) and exit
511 echo "$os.$rel.$arch$sfx"
515 # now try to find a reasonable object directory
516 if [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rel.$arch$sfx ]; then
517 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rel.$arch$sfx
518 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rroot.$arch$sfx ]; then
519 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rroot.$arch$sfx
520 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rbase.x.$arch$sfx ]; then
521 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rbase.x.$arch$sfx
522 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rel$sfx ]; then
523 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rel$sfx
524 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$rbase.x$sfx ]; then
525 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rbase.x$sfx
526 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os.$arch$sfx ]; then
527 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$arch$sfx
528 elif [ -r ${OBJ_ROOT}/obj${prefix}.$rel.$arch$sfx ]; then
529 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$rel.$arch$sfx
530 elif [ -r ${OBJ_ROOT}/obj${prefix}.$rbase.x.$arch$sfx ]; then
531 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$rbase.x.$arch$sfx
532 elif [ -r ${OBJ_ROOT}/obj${prefix}.$os$sfx ]; then
533 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os$sfx
534 elif [ -r ${OBJ_ROOT}/obj${prefix}.$arch$sfx ]; then
535 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$arch$sfx
536 elif [ -r ${OBJ_ROOT}/obj${prefix}.$rel$sfx ]; then
537 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$rel$sfx
538 elif [ -r ${OBJ_ROOT}/obj${prefix}.$sfx ]; then
539 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$sfx
542 if [ -n "$abs_obj_dir" ]
544 obj=${abs_obj_dir}/${src_dir}
547 # Print the directory which would be used for the build and exit
552 obj=${OBJ_ROOT}/obj.$os.$rel.$arch$sfx/${src_dir}
558 # Check if trying to use -f with an existing obj directory
559 if [ -n "$siteconfig" -a -n "$obj" -a -d "$obj" -a -z "$cflag" ]
561 echo "Can not use Build's -f flag with an existing object tree."
562 echo "If you wish to change configuration information, use the -c flag to clear"
563 echo "the existing $obj tree."
567 # Check if trying to use -Q with an existing obj directory
568 if [ -n "$pfx" -a -n "$obj" -a -d "$obj" -a -z "$cflag" ]
570 echo "Can not use Build's -Q flag with an existing object tree."
571 echo "If you wish to change configuration information, use the -c flag to clear"
572 echo "the existing $obj tree."
577 # Clean out the directory before building.
582 echo "Clearing out existing $obj tree"
587 # If we didn't detect an existing obj directory, makeup a new obj name.
590 abs_obj_dir=${OBJ_ROOT}/obj${prefix}.$os.$rel.$arch$sfx
591 obj=${abs_obj_dir}/${src_dir}
594 # Check if obj directory exists
597 if [ -r $BUILDTOOLS/OS/$os.$rel.$arch$sfx ]; then
598 oscf=$os.$rel.$arch$sfx
599 elif [ -r $BUILDTOOLS/OS/$os.$rel.$arch ]; then
601 elif [ -r $BUILDTOOLS/OS/$os.$rroot.$arch$sfx ]; then
602 oscf=$os.$rroot.$arch$sfx
603 elif [ -r $BUILDTOOLS/OS/$os.$rroot.$arch ]; then
604 oscf=$os.$rroot.$arch
605 elif [ -r $BUILDTOOLS/OS/$os.$rbase.x.$arch$sfx ]; then
606 oscf=$os.$rbase.x.$arch$sfx
607 elif [ -r $BUILDTOOLS/OS/$os.$rbase.x.$arch ]; then
608 oscf=$os.$rbase.x.$arch
609 elif [ -r $BUILDTOOLS/OS/$os.$rel$sfx ]; then
611 elif [ -r $BUILDTOOLS/OS/$os.$rel ]; then
613 elif [ -r $BUILDTOOLS/OS/$os.$rroot$sfx ]; then
615 elif [ -r $BUILDTOOLS/OS/$os.$rroot ]; then
617 elif [ -r $BUILDTOOLS/OS/$os.$rbase.x$sfx ]; then
618 oscf=$os.$rbase.x$sfx
619 elif [ -r $BUILDTOOLS/OS/$os.$rbase.x ]; then
621 elif [ -r $BUILDTOOLS/OS/$os.$arch$sfx ]; then
623 elif [ -r $BUILDTOOLS/OS/$os.$arch ]; then
625 elif [ -r $BUILDTOOLS/OS/$rel.$arch$sfx ]; then
627 elif [ -r $BUILDTOOLS/OS/$rel.$arch ]; then
629 elif [ -r $BUILDTOOLS/OS/$rroot.$arch$sfx ]; then
630 oscf=$rroot.$arch$sfx
631 elif [ -r $BUILDTOOLS/OS/$rroot.$arch ]; then
633 elif [ -r $BUILDTOOLS/OS/$rbase.x.$arch$sfx ]; then
634 oscf=$rbase.x.$arch$sfx
635 elif [ -r $BUILDTOOLS/OS/$rbase.x.$arch ]; then
637 elif [ -r $BUILDTOOLS/OS/$os$sfx ]; then
639 elif [ -r $BUILDTOOLS/OS/$os ]; then
641 elif [ -r $BUILDTOOLS/OS/$arch$sfx ]; then
643 elif [ -r $BUILDTOOLS/OS/$arch ]; then
645 elif [ -r $BUILDTOOLS/OS/$rel$sfx ]; then
647 elif [ -r $BUILDTOOLS/OS/$rel ]; then
649 elif [ -r $BUILDTOOLS/OS/$rel$sfx ]; then
652 echo "Cannot determine how to support $os.$rel.$arch" >&2
655 M4=`$SHELL $BUILDTOOLS/bin/find_m4.sh`
665 echo "Will run in virgin $obj using $BUILDTOOLS/OS/$oscf"
669 echo "Creating $obj using $BUILDTOOLS/OS/$oscf"
674 # This glob doesn't actually glob to something everywhere,
675 # thus the protective measures.
676 for i in ${obj_rel_base_dir}/${src_dir}/*.[chly13458]
683 # This glob doesn't actually glob to something everywhere,
684 # thus the protective measures.
685 for i in ${obj_rel_base_dir}/${src_dir}/*.0
689 $ln $i `basename $i`.dist
694 (cd $obj; $ln ${obj_rel_base_dir}/${src_dir}/helpfile .)
697 rm -f $obj/.settings$$
698 echo 'divert(-1)' > $obj/.settings$$
699 cat $BUILDTOOLS/M4/header.m4 >> $obj/.settings$$
700 echo "define(\`bldOS', \`\`$os'')" >> $obj/.settings$$
701 echo "define(\`bldREL', \`\`$rel'')" >> $obj/.settings$$
702 echo "define(\`bldARCH', \`\`$arch'')" >> $obj/.settings$$
703 cat $BUILDTOOLS/OS/$oscf >> $obj/.settings$$
707 absolute_obj_dir=`pwd`
711 echo "ifdef(\`bldABS_OBJ_DIR',,\`define(\`bldABS_OBJ_DIR', \`$absolute_obj_dir')')" >> $obj/.settings$$
712 rel_src_dir="$obj_rel_base_dir/$src_dir"
713 echo "define(\`bldSRC_NAME', \`$src_dir')" >> $obj/.settings$$
714 echo "define(\`bldREL_SRC_DIR', \`$rel_src_dir')" >> $obj/.settings$$
718 # They gave us a specific prefix, let's try it out.
719 if [ -f $BUILDTOOLS/Site/$pfx.$oscf$sfx.m4 ]
721 siteconfig=$BUILDTOOLS/Site/$pfx.$oscf$sfx.m4
722 elif [ -f $BUILDTOOLS/Site/$pfx.$oscf.m4 ]
724 siteconfig=$BUILDTOOLS/Site/$pfx.$oscf.m4
726 if [ -f $BUILDTOOLS/Site/$pfx.config.m4 ]
728 siteconfig="$BUILDTOOLS/Site/$pfx.config.m4 $siteconfig"
730 elif [ -z "$siteconfig" ]
732 # none specified, use defaults
733 if [ -f $BUILDTOOLS/Site/site.$oscf$sfx.m4 ]
735 siteconfig=$BUILDTOOLS/Site/site.$oscf$sfx.m4
736 elif [ -f $BUILDTOOLS/Site/site.$oscf.m4 ]
738 siteconfig=$BUILDTOOLS/Site/site.$oscf.m4
740 if [ -f $BUILDTOOLS/Site/site.config.m4 ]
742 siteconfig="$BUILDTOOLS/Site/site.config.m4 $siteconfig"
744 if [ -f $BUILDTOOLS/Site/site.post.m4 ]
746 siteconfig="$siteconfig $BUILDTOOLS/Site/site.post.m4"
749 if [ ! -z "$siteconfig" ]
751 echo "Including $siteconfig"
752 cat $siteconfig >> $obj/.settings$$
756 echo "define(\`confLIBDIRS', confLIBDIRS \`\`$libdirs'')" >> $obj/.settings$$
760 echo "define(\`confINCDIRS', \`\`$incdirs'' confINCDIRS)" >> $obj/.settings$$
762 echo "define(\`_SRC_PATH_', \`\`$obj_rel_base_dir'')" >> $obj/.settings$$
763 echo "define(\`bldSRC_PATH', \`\`$obj_rel_base_dir'')" >> $obj/.settings$$
764 echo 'divert(0)dnl' >> $obj/.settings$$
765 libdirs=`(cat $obj/.settings$$; echo "_SRIDBIL_= confLIBDIRS" ) | \
766 sed -e 's/\(.\)include/\1_include_/g' -e 's/#define/#_define_/g' | \
767 ${M4} ${M4_BLDVARIANT_FLAGS} -DconfBUILDTOOLSDIR=$BUILDTOOLS - | \
768 grep "^_SRIDBIL_=" | \
769 sed -e 's/#_define_/#define/g' -e 's/_include_/include/g' -e "s/^_SRIDBIL_=//"`
770 libsrch=`(cat $obj/.settings$$; echo "_HCRSBIL_= confLIBSEARCH" ) | \
771 sed -e 's/\(.\)include/\1_include_/g' -e 's/#define/#_define_/g' | \
772 ${M4} ${M4_BLDVARIANT_FLAGS} -DconfBUILDTOOLSDIR=$BUILDTOOLS - | \
773 grep "^_HCRSBIL_=" | \
774 sed -e 's/#_define_/#define/g' -e 's/_include_/include/g' -e "s/^_HCRSBIL_=//"`
775 libpath=`(cat $obj/.settings$$; echo "_HCRSBIL_= confLIBSEARCHPATH" ) | \
776 sed -e 's/\(.\)include/\1_include_/g' -e 's/#define/#_define_/g' | \
777 ${M4} ${M4_BLDVARIANT_FLAGS} -DconfBUILDTOOLSDIR=$BUILDTOOLS - | \
778 grep "^_HCRSBIL_=" | \
779 sed -e 's/#_define_/#define/g' -e 's/_include_/include/g' -e "s/^_HCRSBIL_=//"`
780 echo 'divert(-1)' >> $obj/.settings$$
781 LIBDIRS="$libdirs" LIBSRCH="$libsrch" LIBPATH="$libpath" SITECONFIG="$siteconfig" $SHELL $BUILDTOOLS/bin/configure.sh $sflag $oscf >> $obj/.settings$$
782 echo 'divert(0)dnl' >> $obj/.settings$$
783 sed -e 's/\(.\)include/\1_include_/g' -e 's/#define/#_define_/g' -e 's/
\r//g' $obj/.settings$$ | \
784 ${M4} ${M4_BLDVARIANT_FLAGS} -DconfBUILDTOOLSDIR=$BUILDTOOLS - Makefile.m4 | \
785 sed -e 's/#_define_/#define/g' -e 's/_include_/include/g' -e 's/
\r//g' > $obj/Makefile
786 # That ^M up there was added by quoting it in emacs.
787 # Make has problems if lines end in ^M^M, but not in ^M apparently
788 if [ $? -ne 0 -o ! -s $obj/Makefile ]
790 echo "ERROR: ${M4} failed; You may need a newer version of M4, at least as new as System V or GNU" 1>&2
794 rm -f $obj/.settings$$
795 echo "Making dependencies in $obj"
796 (cd $obj; ${MAKE-make} depend)
801 makefile=`ls -l $obj/Makefile | sed 's/.* //'`
802 if [ -z "$makefile" ]
804 echo "ERROR: $obj exists but has no Makefile" >&2
807 echo "Will run in existing $obj using $makefile"
811 echo "Making in $obj"
813 eval exec ${MAKE-make} SENDMAIL_BUILD_FLAGS=\"$SENDMAIL_BUILD_FLAGS\" $makeargs