164269Seric#!/bin/sh
264269Seric
364269Seric# Copyright (c) 1993 Eric P. Allman
464269Seric# Copyright (c) 1993 The Regents of the University of California.
564269Seric# All rights reserved.
664269Seric#
764269Seric# %sccs.include.redist.sh%
864269Seric#
9*69944Seric#       @(#)makesendmail	8.26 (Berkeley) 06/20/95
1064269Seric#
1164269Seric
1264269Seric#
1364269Seric#  A quick-and-dirty script to compile sendmail in the presence of
1464269Seric#  multiple architectures and Makefiles.
1564269Seric#
1664269Seric
1769859Sericif [ "x${1-""}" = "x-m" ]
1869859Sericthen
1969859Seric	# show Makefile name only
2069859Seric	mflag=1
2169859Sericelse
2269859Seric	mflag=""
2369859Sericfi
2469859Seric
2569459Seric#
2669459Seric#  Do heuristic guesses for machines that do not have uname
2769459Seric#
2868154Sericif [ -d /LocalApps -a ! -f /bin/uname -a ! -f /usr/bin/uname ]
2968154Sericthen
3068154Seric	# probably a NeXT box
3168154Seric	arch=NeXT
3268154Seric	os=Mach
3368771Seric	rel=`strings /mach | grep 'Mach.*:' | sed -e 's/.* Mach //' -e 's/:.*//'`
3469459Sericelif [ -f /usr/sony/bin/machine -a -f /etc/osversion ]
3569459Sericthen
3669459Seric	# probably a Sony NEWS 4.x
3769459Seric	os=NEWS-OS
3869459Seric	rel=`awk '{ print $3}' /etc/osversion`
3969459Seric	arch=`/usr/sony/bin/machine`
4069459Sericelif [ -d /usr/omron -a -f /bin/luna ]
4169459Sericthen
4269459Seric	# probably a Omron LUNA
4369459Seric	os=LUNA
4469462Seric	if [ -f /bin/luna1 ] && /bin/luna1
4569459Seric	then
4669459Seric		rel=unios-b
4769459Seric		arch=luna1
4869462Seric	elif [ -f /bin/luna2 ] && /bin/luna2
4969459Seric	then
5069459Seric		rel=Mach
5169459Seric		arch=luna2
5269462Seric	elif [ -f /bin/luna88k ] && /bin/luna88k
5369459Seric	then
5469459Seric		rel=Mach
5569459Seric		arch=luna88k
5669459Seric	fi
5769459Sericfi
5869459Seric
5969459Sericif [ ! "$arch" -a ! "$os" -a ! "$rel" ]
6069459Sericthen
6168154Seric	arch=`uname -m | sed -e 's/ //g'`
6268754Seric	os=`uname -s | sed 's/\//-/g'`
6368154Seric	rel=`uname -r`
6468154Sericfi
6568154Seric
6668154Seric# tweak machine architecture
6764269Sericcase $arch
6864269Sericin
6964269Seric  sun4*)	arch=sun4;;
7065868Seric
7165868Seric  9000/*)	arch=`echo $arch | sed -e 's/9000.//' -e 's/..$/xx/'`;;
7264269Sericesac
7364269Seric
7468896Seric# tweak operating system type and release
7568032Sericcase $os
7668032Sericin
7768754Seric  DYNIX-ptx)	os=PTX;;
7868084Seric  Paragon*)	os=Paragon;;
7968896Seric  HP-UX)	rel=`echo $rel | sed -e 's/^[^.]*\.0*//'`;;
8069562Seric  AIX)		rel=`uname -v`;;
8169862Seric  BSD-386)	os=BSD-OS;;
8268032Sericesac
8364269Seric
8468896Seric# get "base part" of operating system release
8568896Sericrbase=`echo $rel | sed -e 's/\..*//'`
8664269Seric
8768032Seric# heuristic tweaks to clean up names
8868040Sericif [ "$os" = "unix" ]
8968040Sericthen
9068040Seric	# might be Altos System V
9168040Seric	case $rel
9268040Seric	in
9368040Seric	  5.3*)		os=Altos;;
9468040Seric	esac
9568090Sericfi
9668040Seric
9768032Sericif [ -r /unix -a -r /usr/lib/libseq.a -a -r /lib/cpp ]
9868032Sericthen
9968032Seric	# might be a DYNIX/ptx 2.x system, which has a broken uname
10068032Seric	if strings /lib/cpp | grep _SEQUENT_ > /dev/null
10168032Seric	then
10268032Seric		os=PTX
10368032Seric	fi
10468032Sericfi
10568032Seric
10669459Sericif [ -d /usr/nec -a "$os" = "UNIX_System_V" ]
10769459Sericthen
10869459Seric	os=EWS-UX_V
10969459Sericfi
11069459Seric
11168746Seric# see if there is a "user suffix" specified
11268754Sericif [ "${SENDMAIL_SUFFIX-}x" = "x" ]
11368746Sericthen
11468746Seric	sfx=""
11568746Sericelse
11668754Seric	sfx=".${SENDMAIL_SUFFIX}"
11768746Sericfi
11868746Seric
11969859Sericecho "Configuration: os=$os, rel=$rel, rbase=$rbase, arch=$arch, sfx=$sfx"
12068895Seric
12164269Seric# now try to find a reasonable object directory
12268746Sericif [ -r obj.$os.$rel.$arch$sfx ]; then
12368746Seric	obj=obj.$os.$rel.$arch$sfx
12468746Sericelif [ -r obj.$os.$rbase.x.$arch$sfx ]; then
12568746Seric	obj=obj.$os.$rbase.x.$arch$sfx
12668746Sericelif [ -r obj.$os.$rel$sfx ]; then
12768746Seric	obj=obj.$os.$rel$sfx
12868746Sericelif [ -r obj.$os.$rbase.x$sfx ]; then
12968746Seric	obj=obj.$os.$rbase.x$sfx
13068746Sericelif [ -r obj.$os.$arch$sfx ]; then
13168746Seric	obj=obj.$os.$arch$sfx
13268746Sericelif [ -r obj.$rel.$arch$sfx ]; then
13368746Seric	obj=obj.$rel.$arch$sfx
13468746Sericelif [ -r obj.$rbase.x.$arch$sfx ]; then
13568746Seric	obj=obj.$rbase.x.$arch$sfx
13668746Sericelif [ -r obj.$os$sfx ]; then
13768746Seric	obj=obj.$os$sfx
13868746Sericelif [ -r obj.$arch$sfx ]; then
13968746Seric	obj=obj.$arch$sfx
14068746Sericelif [ -r obj.$rel$sfx ]; then
14168746Seric	obj=obj.$rel$sfx
14268746Sericelif [ -r obj$sfx ]; then
14368746Seric	obj=obj$sfx
14465868Sericelse
14565868Seric	# no existing obj directory -- try to create one if Makefile found
14668746Seric	obj=obj.$os.$rel.$arch$sfx
14768746Seric	if [ -r Makefiles/Makefile.$os.$rel.$arch$sfx ]; then
14868746Seric		makefile=Makefile.$os.$rel.$arch$sfx
14968746Seric	elif [ -r Makefiles/Makefile.$os.$rel.$arch ]; then
15068588Seric		makefile=Makefile.$os.$rel.$arch
15168746Seric	elif [ -r Makefiles/Makefile.$os.$rbase.x.$arch$sfx ]; then
15268746Seric		makefile=Makefile.$os.$rbase.x.$arch$sfx
15368588Seric	elif [ -r Makefiles/Makefile.$os.$rbase.x.$arch ]; then
15468588Seric		makefile=Makefile.$os.$rbase.x.$arch
15568746Seric	elif [ -r Makefiles/Makefile.$os.$rel$sfx ]; then
15668746Seric		makefile=Makefile.$os.$rel$sfx
15767855Seric	elif [ -r Makefiles/Makefile.$os.$rel ]; then
15865868Seric		makefile=Makefile.$os.$rel
15968746Seric	elif [ -r Makefiles/Makefile.$os.$rbase.x$sfx ]; then
16068746Seric		makefile=Makefile.$os.$rbase.x$sfx
16167855Seric	elif [ -r Makefiles/Makefile.$os.$rbase.x ]; then
16266281Seric		makefile=Makefile.$os.$rbase.x
16368746Seric	elif [ -r Makefiles/Makefile.$os.$arch$sfx ]; then
16468746Seric		makefile=Makefile.$os.$arch$sfx
16567855Seric	elif [ -r Makefiles/Makefile.$os.$arch ]; then
16665868Seric		makefile=Makefile.$os.$arch
16768746Seric	elif [ -r Makefiles/Makefile.$rel.$arch$sfx ]; then
16868746Seric		makefile=Makefile.$rel.$arch$sfx
16968588Seric	elif [ -r Makefiles/Makefile.$rel.$arch ]; then
17068588Seric		makefile=Makefile.$rel.$arch
17168746Seric	elif [ -r Makefiles/Makefile.$rbase.x.$arch$sfx ]; then
17268746Seric		makefile=Makefile.$rbase.x.$arch$sfx
17368588Seric	elif [ -r Makefiles/Makefile.$rbase.x.$arch ]; then
17468588Seric		makefile=Makefile.$rbase.x.$arch
17568746Seric	elif [ -r Makefiles/Makefile.$os$sfx ]; then
17668746Seric		makefile=Makefile.$os$sfx
17767855Seric	elif [ -r Makefiles/Makefile.$os ]; then
17865868Seric		makefile=Makefile.$os
17968746Seric	elif [ -r Makefiles/Makefile.$arch$sfx ]; then
18068746Seric		makefile=Makefile.$arch$sfx
18167855Seric	elif [ -r Makefiles/Makefile.$arch ]; then
18265868Seric		makefile=Makefile.$arch
18368746Seric	elif [ -r Makefiles/Makefile.$rel$sfx ]; then
18468746Seric		makefile=Makefile.$rel$sfx
18567855Seric	elif [ -r Makefiles/Makefile.$rel ]; then
18665868Seric		makefile=Makefile.$rel
18768746Seric	elif [ -r Makefiles/Makefile.$rel$sfx ]; then
18868746Seric		makefile=Makefile.$rel$sfx
18965868Seric	else
19065868Seric		echo "Cannot determine how to support $arch.$os.$rel"
19165868Seric		exit 1
19265868Seric	fi
19369859Seric	if [ "$mflag" ]
19469859Seric	then
19569859Seric		echo "Will run in virgin $obj using $makefile"
19669859Seric		exit 0
19769859Seric	fi
19865868Seric	echo "Creating $obj using $makefile"
19964269Seric	mkdir $obj
20067855Seric	(cd $obj; ln -s ../*.[ch158] ../sendmail.hf .; ln -s ../Makefiles/$makefile Makefile)
201*69944Seric	echo "Making dependencies in $obj"
202*69944Seric	(cd $obj; ${MAKE-make} depend)
20364269Sericfi
20469859Seric
20569859Sericif [ "$mflag" ]
20669859Sericthen
20769859Seric	makefile=`ls -l $obj/Makefile | sed 's/.* //'`
20869859Seric	if [ -z "$makefile" ]
20969859Seric	then
21069859Seric		echo "ERROR: $obj exists but has no Makefile"
21169859Seric		exit 1
21269859Seric	fi
21369859Seric	case $makefile
21469859Seric	in
21569859Seric	  ../Makefiles/*)
21669859Seric		makefile=`echo $makefile | sed 's/...Makefiles.//'`
21769859Seric		echo "Will run in existing $obj using $makefile"
21869859Seric		;;
21969859Seric
22069859Seric	  *)
22169859Seric		echo "Will run in existing $obj using custom $makefile"
22269859Seric		;;
22369859Seric	esac
22469859Seric	exit 0
22569859Sericfi
22669859Seric
22764269Sericecho "Making in $obj"
22864269Sericcd $obj
22968143Sericif [ $# = 0 ]
23068143Sericthen
23168143Seric	exec ${MAKE-make}
23268143Sericelse
23368143Seric	exec ${MAKE-make} "$@"
23468143Sericfi
235