# @(#)Makefile	1.23 05 Jun 1995 (UKC)

# Top level makefile for ups

# You may want to edit some of the following variables.

# Where to install the X11 binary
X11BIN = /usr/local/X11

# Where to install the SunView binary
SUNVIEWBIN = /usr/local/Sunview

# Where to put the manual page
MANDIR = /usr/local/man/man1

# The suffix to use for the manual page
MANSUFFIX = 1

# The directory where X include files live.
# Comment out or change this line if you don't want
# /usr/openwin/include searched
X11INCLUDE=-I/usr/openwin/include

# The arguments to cc needed to link against the Xlib library.
# Change this to an explicit path (e.g. /usr/X11/lib/libX11.a)
# if your Xlib lives in a place that won't be found by -lX11.
X11LIB = -lX11
#
# For Red Hat 5.0 Linux, uncomment the line below to get the X11 library
#X11LIB = /usr/X11/lib/libX11.a

# Extra flags to pass to the build of the Wn library.
X11WNFLAGS=INCLUDEDIRS=${X11INCLUDE}

# If you want you can pass make variable assignments to the
# subdirectory makefiles by uncommenting and editing the
# following assignment to SUBMAKEFLAGS.
#
# You can put multiple space separated assignments here if you want.
#
#
#EXTRA_SUBMAKEFLAGS = "-k"

# Flags for RISC/os from Conor Doherty and Hal R. Brand
# Edit HERE below to the absolute path to the ups source directory
#EXTRA_SUBMAKEFLAGS ="MORE_CFLAGS=-Driscos -DNO_DIRENT -DNO_PUTENV -IHERE/misc/riscos"
#X11LIB=/usr/X11/Rw321/lib/libX11.a	# for MIPS RISCwindows interface

# If you are building ups for a Sun (any architecture) running SunOS 4.0.3
# or earlier then you must uncomment the following line.  If you don't
# you will get incorrect values for char and short parameters.  Note that
# this means you can't share a single ups binary between SunOS 4.1.1 and
# an earlier release.  You need to turn this flag on for SunOS 3.X.
#
#EXTRA_SUBMAKEFLAGS = "ARCH_CFLAGS=-DFIX_SHORT_PARAMS"

MAKE = make	# for makes that don't do this automatically

CC = cc
CFLAGS = -g

# Use these flags by default
RANLIB = :
SVR4_LINKFLAGS=-R/usr/openwin/lib -L/usr/openwin/lib
LINKFLAGS = ${SVR4_LINKFLAGS}

# Flags for SunOS 4.1.3
#RANLIB = ranlib

SUBMAKEFLAGS= CC="${CC}" RANLIB="${RANLIB}" CFLAGS="${CFLAGS}" ${EXTRA_SUBMAKEFLAGS}

BINDIRS = ups
LIBDIRS = lib/libx11wn lib/libmtrprog lib/libukcprog \
	  lib/libarg lib/libMen3 lib/libobj lib/libedit

COMMONLIBS = libmtrprog libukcprog libarg libMen3 libobj libedit
X11LIBS = libx11wn ${COMMONLIBS}
SUNVIEWLIBS = libsunviewwn ${COMMONLIBS}

SUBDIRS = ${LIBDIRS} ${BINDIRS}

# Note: we use MFLAGS for the recursive makes rather than MAKEFLAGS.
# This is because the BDSi make loops forever if you say `make -',
# which is what you get if you say `${MAKE} -${MAKEFLAGS} when MAKEFLAGS
# is not set to anything.

# We pass X11WNFLAGS for xc_builtins.c, which #includes X11 header files.
# We can zap this when we sort out xc_builtins.c.
#
ups: ups/develhdrs ${X11LIBS}
	cd ups && ${MAKE} ${MFLAGS} X11LIB=${X11LIB} LINKFLAGS="${LINKFLAGS}" ${X11WNFLAGS} ${SUBMAKEFLAGS} ${UPS_TARGET}

libx11wn:
	cd lib/$@ && ${MAKE} ${MFLAGS} ${SUBMAKEFLAGS} ${X11WNFLAGS}

sunviewups: ups/develhdrs ${SUNVIEWLIBS}
	cd ups && ${MAKE} ${MFLAGS} ${SUBMAKEFLAGS} svups

libsunviewwn:
	cd lib/libx11wn && ${MAKE} ${MFLAGS} ${SUBMAKEFLAGS} \
				WSNAME=SUNVIEW 'WSLIBS=${SUNVIEWLIBS}'

${COMMONLIBS}:
	cd lib/$@ && ${MAKE} ${MFLAGS} ${SUBMAKEFLAGS}

install:
	cd ups && ${MAKE} ${MFLAGS} ${SUBMAKEFLAGS} \
			X11BIN=${X11BIN} \
			MANDIR=${MANDIR} MANSUFFIX=${MANSUFFIX} \
			SCCS_CHECK= checkinstall

sunviewinstall:
	cd ups && ${MAKE} ${MFLAGS} ${SUBMAKEFLAGS} \
			SUNVIEWBIN=${SUNVIEWBIN} \
			MANDIR=${MANDIR} MANSUFFIX=${MANSUFFIX} \
			SCCS_CHECK= checksunviewinstall

# Try to leave the source directory as it came in the distribution
clean:
	for i in ${SUBDIRS}; do \
		(cd $$i && ${MAKE} ${MFLAGS} clean); \
		rm -rf $$i/develhdrs; \
	done

count:
	for i in ${SUBDIRS}; do \
		(cd $$i && ${MAKE} ${MFLAGS} count | sed -n "s@total@$$i@p"); \
	done

rmlinks:
	for i in ${SUBDIRS}; do \
		rm -rf $$i/develhdrs; \
	done

# The ups source assumes that various UKC libraries and header files
# are installed.  We distribute ups so that the source is self contained:
# this target makes the symlinks needed to support this.
ups/develhdrs:
	@echo Making links ...
	@-for i in ${SUBDIRS}; do mkdir $$i/develhdrs; done
	@-for i in Men3 arg mtrprog obj edit x11wn; do \
		mkdir lib/lib$$i/develhdrs/local; \
	done
	@-for i in Men3 obj edit; do \
		ln -s ../../../libx11wn/wn.h lib/lib$$i/develhdrs/local/wn.h; \
	done
	@-for i in arg mtrprog obj edit x11wn; do \
		ln -s ../../../libukcprog/ukcprog.h \
					lib/lib$$i/develhdrs/local/ukcprog.h; \
	done
	@-for i in arg obj edit; do \
		ln -s ../../libmtrprog lib/lib$$i/develhdrs/mtrprog; \
	done
	@-ln -s ../../lib/libmtrprog ups/develhdrs/mtrprog
	@-mkdir ups/develhdrs/local
	@-ln -s ../../../lib/libarg/arg.h ups/develhdrs/local/arg.h
	@-ln -s ../../../lib/libMen3/menu3.h ups/develhdrs/local/menu3.h
	@-ln -s ../../../lib/libobj ups/develhdrs/local/obj
	@-ln -s ../../../lib/libedit ups/develhdrs/local/edit
	@-ln -s ../../../lib/libukcprog/ukcprog.h ups/develhdrs/local/ukcprog.h
	@-ln -s ../../../lib/libx11wn/wn.h ups/develhdrs/local/wn.h

# The rest of this makefile is concerned only with making releases from
# the master source directory.

# Odd files needed for particular architecures.
MISCFILES = misc/riscos/stdlib.h imake.sh imakefiles.shar 

# The gdb munging scripts and steering files
GDBFILES = gdbconf/initlist	 \
	   gdbconf/mkcalltree	 \
	   gdbconf/mkfunclist	 \
	   gdbconf/mkupsgdb	 \
	   gdbconf/mkccinfo	 \
	   gdbconf/mungeinit	 \
	   gdbconf/mungemakefile \
	   gdbconf/srcmunge	 \
	   gdbconf/zapcalls

FILES = Makefile README README.gdb README.multiarch ${GDBFILES} ${MISCFILES}
FILELIST = releasefiles
CHECKRELEASE = checkrelease
RELROOT = releases
RELNAME = ups-`sccs prs -d:I: ups/sccsdata.c`${RELTAG}

# Make a release as a compressed tar file
release: ${CHECKRELEASE} filelist ${RELROOT}
	@echo Creating release file ${RELNAME} ...
	@sed -e "s;^;${RELNAME}/;" -e 's;/./;/;' < ${FILELIST} > thesefiles
	@rm -f ${RELNAME}
	@ln -s . ${RELNAME}
	@tar cf - `cat thesefiles` | gzip > ${RELROOT}/${RELNAME}.tar.gz
	@chmod 444 ${RELROOT}/${RELNAME}.tar.gz
	@rm -f ${RELNAME}

testrelease:
	rm -f releases/ups-test.tar.gz
	${MAKE} ${MFLAGS} CHECKRELEASE= RELNAME=ups-${RELTAG} release

${RELROOT}:
	mkdir ${RELROOT}

# Check that everything is checked in OK for a release
checkrelease:
	@echo "Checking release status ..."
	@here=`pwd`;                                      \
	 for i in ${SUBDIRS} .; do                        \
		if cd $$i && make sccs_check; then        \
			echo $$i OK for release;          \
		else                                      \
			failed="$$failed $$i";            \
		fi;                                       \
		cd $$here;                                \
	 done ;                                           \
	                                                  \
	 if test -n "$$failed"; then                      \
		echo;                                     \
		echo Not ready for release: $$failed;     \
		exit 0;                                   \
	 fi

sccs_check:
	@sccsinfo ${FILES}

# Put into ${FILELIST} a list of all the files that make up an
# ups source release.
filelist:
	@: > ${FILELIST}
	@for i in . ${SUBDIRS}; do \
		echo Adding files from $$i; \
		(cd $$i && make list) | sed "s;^;$$i/;" >> ${FILELIST}; \
	done

# List one to a line the files in this directory that should go in a release
list:
	@echo CHANGES ${FILES} | tr ' ' '\012'
