#-----------------------------------------------------------------------------
# $Id: Makefile,v 1.9 89/12/11 12:40:57 chrisb Exp $
#
# Makefile for libc, in six flavors:
#	libcgka.a:	GNU/960 object, for 80960KA
#	libcgkb.a:	GNU/960 object, for 80960KB and 80960MC
#	libcgca.a:	GNU/960 object, for 80960CA
#	libcka.a:	Intel object, for 80960KA
#	libckb.a:	Intel object, for 80960KB and 80960MC
#	libcca.a:	Intel object, for 80960CA
#
# The Intel versions are not part of the standard install target, since
# a person developing with Intel tools will normally want to use the
# Intel libc.
#-----------------------------------------------------------------------------

# The following are names of flag files.  The presence of a flag file indicates
# what format object files were last built in the current directory.  Only one
# format can be present at a time:  when a change of format is required, all
# objects are first deleted, so as to avoid mixing formats within a library.
#
GFLAG = .gnu_objs
IFLAG = .intel_objs
FORMAT_FLAGS = ${GFLAG} ${IFLAG}

# Similarly, these flag files distinguish the different target
# architectures for which object code can be built.
#
KA_FLAG = .ka_objs
KB_FLAG = .kb_objs
CA_FLAG = .ca_objs
ARCH_FLAGS = ${KA_FLAG} ${KB_FLAG} ${CA_FLAG}

ALL_FLAGS = ${FORMAT_FLAGS} ${ARCH_FLAGS}

.SUFFIXES: .s .cpp .c .c,v

# The following rule is provided so an Intel objects can be generated using
# gcc960 and the Intel assembler.  When GNU/960 targets are invoked, this
# rule is overridden
#
COMPILE= ${CC} ${CFLAGS} -S $<; ${AS} ${ASFLAGS} -o $*.o $*.s; rm $*.s

.c.o:
	${COMPILE}

.s.o:
	${AS} ${ASFLAGS} -o $*.o $*.s


# Unpleasant consequence of this makefile organization (supporting 2 object
# formats X 3 target processors) is that you can only say "make x.a".
# An attempt to say "make x.o" will come in at too low a level -- before
# all of the variables have been defined -- and get you the host assembler
# or archiver.  The "uhuh" entries here will at least cause you to bomb
# instead of building the wrong stuff.
#
CC	= gcc960
OS      = NINDY
CFLAGS	= -O3 -D${OS}
AS	= uhuh
AR	= uhuh
ARFLAGS	= rs


OBJS =	_allocbu.o _assert.o _ctype.o _filbuf.o \
	 _file.o _flsbuf.o _fopen.o _slot.o \
	abort.o asin.o acos.o \
	atexit.o atof.o atol.o bsearch.o bzero.o \
	clock.o cosh.o ctype.o exit.o \
	fclose.o fgetc.o fgets.o \
	fflush.o fopen.o fprintf.o fputc.o fputs.o fread.o \
	freopen.o fseek.o ftell.o \
	fwrite.o getenv.o getopt.o init_c.o isatty.o \
	malloc.o math.o memchr.o memccpy.o memcmp.o memcpy.o memset.o \
	mktemp.o perror.o pow.o printf.o puts.o putw.o \
	qsort.o rand.o remove.o rename.o scanf.o setjmp.o setbuf.o setvbuf.o \
	setlocale.o signal.o sinh.o sprintf.o stdio.o stdlib.o \
	strcat.o strchr.o strcmp.o strcoll.o strcpy.o \
	strcspn.o strerror.o strlen.o strncat.o \
	strncmp.o strncpy.o strpbrk.o strspn.o strstr.o strtok.o strxfrm.o \
	system.o tanh.o thread_init.o time.o tmpfile.o tmpnam.o \
	ungetc.o vfprintf.o vfscanf.o vprintf.o vscanf.o vsprintf.o vsscanf.o \
	ver960.o

GNU_LIBS= libcgka.a libcgkb.a libcgca.a
#INTEL_LIBS= libcka.a libckb.a libcca.a
INTEL_LIBS= libckb.a

all:	gnu

gnu:	${GNU_LIBS}

intel:	${INTEL_LIBS}

libcgka.a: FORCE
	make ${KA_FLAG} ${GFLAG} lib				\
		LIB=libcgka.a					\
		COMPILE='${CC} ${CFLAGS} -msoft-float -g -AKA -c $$<'	\
		AS=gas960 					\
		ASFLAGS=-AKA					\
		AR=gar960

libcgkb.a: FORCE
	make ${KB_FLAG} ${GFLAG} lib 				\
		LIB=libcgkb.a					\
		COMPILE='${CC} ${CFLAGS} -g -AKB -c $$<'	\
		AS=gas960 					\
		ASFLAGS=-AKB					\
		AR=gar960

libcgca.a: FORCE
	make ${CA_FLAG} ${GFLAG} lib 				\
		LIB=libcgca.a					\
		COMPILE='${CC} ${CFLAGS} -msoft-float -g -ACA -c $$<'	\
		AS=gas960 					\
		ASFLAGS=-ACA					\
		AR=gar960

libcka.a: FORCE
	make ${KA_FLAG} ${IFLAG} lib 		\
		LIB=libcka.a			\
		CFLAGS='${CFLAGS} -AKA'		\
		AS=asm960 			\
		ASFLAGS=-AKA			\
		AR=arc960

libckb.a: FORCE
	make ${KB_FLAG} ${IFLAG} lib		\
		LIB=libckb.a			\
		CFLAGS='${CFLAGS} -AKB'		\
		AS=asm960 			\
		ASFLAGS=-AKB			\
		AR=arc960

libcca.a: FORCE
	make ${CA_FLAG} ${IFLAG} lib 		\
		LIB=libcca.a			\
		CFLAGS='${CFLAGS} -ACA'		\
		AS=asm960 			\
		ASFLAGS=-ACA_A			\
		AR=arc960

lib:	${OBJS}
	${AR} ${ARFLAGS} ${LIB} ${OBJS}

# Delete all local object files if they're not in the specified format,
# as indicated by the presence of the flag files.
#
${GFLAG}:
	rm -f *.o ${FORMAT_FLAGS}
	touch ${GFLAG}

${IFLAG}:
	rm -f *.o ${FORMAT_FLAGS}
	touch ${IFLAG}

${KA_FLAG}:
	rm -f *.o ${ARCH_FLAGS}
	touch ${KA_FLAG}

${KB_FLAG}:
	rm -f *.o ${ARCH_FLAGS}
	touch ${KB_FLAG}

${CA_FLAG}:
	rm -f *.o ${ARCH_FLAGS}
	touch ${CA_FLAG}


#									#NOSHIP
# Get source files out of RCS						#NOSHIP
#									#NOSHIP

# Target to uncomment RCS dependency lines in this Makefile,		#NOSHIP
# for in-house development.						#NOSHIP
#									#NOSHIP
rcs:									#NOSHIP
	mv -f Makefile Makefile.old					#NOSHIP
	sed "s/^#__rcs__#//" < Makefile.old >Makefile			#NOSHIP

#__rcs__#fcntl.h:	RCS/fcntl.h,v;		co fcntl.h;		#NOSHIP
#__rcs__#fp960.h:	RCS/fp960.h,v;		co fp960.h;		#NOSHIP
#__rcs__#lib.h:		RCS/lib.h,v;		co lib.h;		#NOSHIP
#__rcs__#pml.h:		RCS/pml.h,v;		co pml.h;		#NOSHIP
#__rcs__#stdiolib.h:	RCS/stdiolib.h,v;	co stdiolib.h;		#NOSHIP
#__rcs__#_allocbu.c:	RCS/_allocbu.c,v;	co _allocbu.c;		#NOSHIP
#__rcs__#_assert.c:	RCS/_assert.c,v;	co _assert.c;		#NOSHIP
#__rcs__#_ctype.c:	RCS/_ctype.c,v;		co _ctype.c;		#NOSHIP
#__rcs__#_filbuf.c:	RCS/_filbuf.c,v;	co _filbuf.c;		#NOSHIP
#__rcs__#_file.c:	RCS/_file.c,v;		co _file.c;		#NOSHIP
#__rcs__#_flsbuf.c:	RCS/_flsbuf.c,v;	co _flsbuf.c;		#NOSHIP
#__rcs__#_fopen.c:	RCS/_fopen.c,v;		co _fopen.c;		#NOSHIP
#__rcs__#_slot.c:	RCS/_slot.c,v;		co _slot.c;		#NOSHIP
#__rcs__#abort.c:	RCS/abort.c,v;		co abort.c;		#NOSHIP
#__rcs__#acos.c:	RCS/acos.c,v;		co acos.c;		#NOSHIP
#__rcs__#asin.c:	RCS/asin.c,v;		co asin.c;		#NOSHIP
#__rcs__#atexit.c:	RCS/atexit.c,v;		co atexit.c;		#NOSHIP
#__rcs__#atof.c:	RCS/atof.c,v;		co atof.c;		#NOSHIP
#__rcs__#atol.c:	RCS/atol.c,v;		co atol.c;		#NOSHIP
#__rcs__#bsearch.c:	RCS/bsearch.c,v;	co bsearch.c;		#NOSHIP
#__rcs__#bzero.c:	RCS/bzero.c,v;		co bzero.c;		#NOSHIP
#__rcs__#clock.c:	RCS/clock.c,v;		co clock.c;		#NOSHIP
#__rcs__#cosh.c:	RCS/cosh.c,v;		co cosh.c;		#NOSHIP
#__rcs__#ctype.c:	RCS/ctype.c,v;		co ctype.c;		#NOSHIP
#__rcs__#exit.c:	RCS/exit.c,v;		co exit.c;		#NOSHIP
#__rcs__#fclose.c:	RCS/fclose.c,v;		co fclose.c;		#NOSHIP
#__rcs__#fflush.c:	RCS/fflush.c,v;		co fflush.c;		#NOSHIP
#__rcs__#fgetc.c:	RCS/fgetc.c,v;		co fgetc.c;		#NOSHIP
#__rcs__#fgets.c:	RCS/fgets.c,v;		co fgets.c;		#NOSHIP
#__rcs__#fopen.c:	RCS/fopen.c,v;		co fopen.c;		#NOSHIP
#__rcs__#fprintf.c:	RCS/fprintf.c,v;	co fprintf.c;		#NOSHIP
#__rcs__#fputc.c:	RCS/fputc.c,v;		co fputc.c;		#NOSHIP
#__rcs__#fputs.c:	RCS/fputs.c,v;		co fputs.c;		#NOSHIP
#__rcs__#fread.c:	RCS/fread.c,v;		co fread.c;		#NOSHIP
#__rcs__#freopen.c:	RCS/freopen.c,v;	co freopen.c;		#NOSHIP
#__rcs__#fseek.c:	RCS/fseek.c,v;		co fseek.c;		#NOSHIP
#__rcs__#ftell.c:	RCS/ftell.c,v;		co ftell.c;		#NOSHIP
#__rcs__#fwrite.c:	RCS/fwrite.c,v;		co fwrite.c;		#NOSHIP
#__rcs__#getenv.c:	RCS/getenv.c,v;		co getenv.c;		#NOSHIP
#__rcs__#getopt.c:	RCS/getopt.c,v;		co getopt.c;		#NOSHIP
#__rcs__#init_c.c:	RCS/init_c.c,v;		co init_c.c;		#NOSHIP
#__rcs__#isatty.c:	RCS/isatty.c,v;		co isatty.c;		#NOSHIP
#__rcs__#malloc.c:	RCS/malloc.c,v;		co malloc.c;		#NOSHIP
#__rcs__#math.c:	RCS/math.c,v;		co math.c;		#NOSHIP
#__rcs__#memchr.c:	RCS/memchr.c,v;		co memchr.c;		#NOSHIP
#__rcs__#memccpy.c:	RCS/memccpy.c,v;	co memccpy.c;		#NOSHIP
#__rcs__#memcmp.c:	RCS/memcmp.c,v;		co memcmp.c;		#NOSHIP
#__rcs__#memcpy.c:	RCS/memcpy.c,v;		co memcpy.c;		#NOSHIP
#__rcs__#memset.c:	RCS/memset.c,v;		co memset.c;		#NOSHIP
#__rcs__#mktemp.c:	RCS/mktemp.c,v;		co mktemp.c;		#NOSHIP
#__rcs__#perror.c:	RCS/perror.c,v;		co perror.c;		#NOSHIP
#__rcs__#pow.c:		RCS/pow.c;		co pow.c;		#NOSHIP
#__rcs__#printf.c:	RCS/printf.c,v;		co printf.c;		#NOSHIP
#__rcs__#puts.c:	RCS/puts.c,v;		co puts.c;		#NOSHIP
#__rcs__#putw.c:	RCS/putw.c,v;		co putw.c;		#NOSHIP
#__rcs__#rand.c:	RCS/rand.c,v;		co rand.c;		#NOSHIP
#__rcs__#qsort.c:	RCS/qsort.c,v;		co qsort.c;		#NOSHIP
#__rcs__#remove.c:	RCS/remove.c,v;		co remove.c;		#NOSHIP
#__rcs__#rename.c:	RCS/rename.c,v;		co rename.c;		#NOSHIP
#__rcs__#scanf.c:	RCS/scanf.c,v;		co scanf.c;		#NOSHIP
#__rcs__#setbuf.c:	RCS/setbuf.c,v;		co setbuf.c;		#NOSHIP
#__rcs__#setlocale.c:	RCS/setlocale.c,v;	co setlocale.c		#NOSHIP
#__rcs__#setvbuf.c:	RCS/setvbuf.c,v;	co setvbuf.c;		#NOSHIP
#__rcs__#setjmp.s:	RCS/setjmp.s,v;		co setjmp.s;		#NOSHIP
#__rcs__#signal.c:	RCS/signal.c,v;		co signal.c;		#NOSHIP
#__rcs__#sinh.c:	RCS/sinh.c,v;		co sinh.c;		#NOSHIP
#__rcs__#sprintf.c:	RCS/sprintf.c,v;	co sprintf.c;		#NOSHIP
#__rcs__#stdio.c:	RCS/stdio.c,v;		co stdio.c;		#NOSHIP
#__rcs__#stdlib.c:	RCS/stdlib.c,v;		co stdlib.c;		#NOSHIP
#__rcs__#strcat.c:	RCS/strcat.c,v;		co strcat.c;		#NOSHIP
#__rcs__#strchr.c:	RCS/strchr.c,v;		co strchr.c;		#NOSHIP
#__rcs__#strcmp.c:	RCS/strcmp.c,v;		co strcmp.c;		#NOSHIP
#__rcs__#strcoll.c:	RCS/strcoll.c,v;	co strcoll.c;		#NOSHIP
#__rcs__#strcpy.c:	RCS/strcpy.c,v;		co strcpy.c;		#NOSHIP
#__rcs__#strcspn.c:	RCS/strcspn.c,v;	co strcspn.c;		#NOSHIP
#__rcs__#strerror.c:	RCS/strerror.c,v;	co strerror.c;		#NOSHIP
#__rcs__#strlen.c:	RCS/strlen.c,v;		co strlen.c;		#NOSHIP
#__rcs__#strncat.c:	RCS/strncat.c,v;	co strncat.c;		#NOSHIP
#__rcs__#strncmp.c:	RCS/strncmp.c,v;	co strncmp.c;		#NOSHIP
#__rcs__#strncpy.c:	RCS/strncpy.c,v;	co strncpy.c;		#NOSHIP
#__rcs__#strpbrk.c:	RCS/strpbrk.c,v;	co strpbrk.c;		#NOSHIP
#__rcs__#strspn.c:	RCS/strspn.c,v;		co strspn.c;		#NOSHIP
#__rcs__#strstr.c:	RCS/strstr.c,v;		co strstr.c;		#NOSHIP
#__rcs__#strtok.c:	RCS/strtok.c,v;		co strtok.c;		#NOSHIP
#__rcs__#strxfrm.c:	RCS/strxfrm.c,v;	co strxfrm.c;		#NOSHIP
#__rcs__#system.c:	RCS/system.c,v;		co system.c;		#NOSHIP
#__rcs__#tanh.c:	RCS/tanh.c,v;		co tanh.c;		#NOSHIP
#__rcs__#thread_init.c: RCS/thread_init.c,v;	co thread_init.c;	#NOSHIP
#__rcs__#time.c:	RCS/time.c,v;		co time.c;		#NOSHIP
#__rcs__#tmpfile.c:	RCS/tmpfile.c,v;	co tmpfile.c;		#NOSHIP
#__rcs__#tmpnam.c:	RCS/tmpnam.c,v;		co tmpnam.c;		#NOSHIP
#__rcs__#ungetc.c:	RCS/ungetc.c,v;		co ungetc.c;		#NOSHIP
#__rcs__#vfprintf.c:	RCS/vfprintf.c,v;	co vfprintf.c;		#NOSHIP
#__rcs__#vfscanf.c:	RCS/vfscanf.c,v;	co vfscanf.c;		#NOSHIP
#__rcs__#vprintf.c:	RCS/vprintf.c,v;	co vprintf.c;		#NOSHIP
#__rcs__#vscanf.c:	RCS/vscanf.c,v;		co vscanf.c;		#NOSHIP
#__rcs__#vsprintf.c:	RCS/vsprintf.c,v;	co vsprintf.c;		#NOSHIP
#__rcs__#vsscanf.c:	RCS/vsscanf.c,v;	co vsscanf.c;		#NOSHIP

#-----------------------------------------------------------------------------
#		'STANDARD' GNU/960 TARGETS BELOW THIS POINT
#
# 'VERSION' file must be present and contain a string of the form "x.y"
#-----------------------------------------------------------------------------

ver960.c: FORCE
	rm -f ver960.c
	echo "char libc_ver[]= \"libc `cat VERSION`, `date`\";" > ver960.c

# This target should be invoked before building a new release.
# 'VERSION' file must be present and contain a string of the form "x.y"
#
roll:
	@V=`cat VERSION`		; \
	MAJ=`sed 's/\..*//' VERSION`	; \
	MIN=`sed 's/.*\.//' VERSION`	; \
	V=$$MAJ.`expr $$MIN + 1`	; \
	rm -f VERSION			; \
	echo $$V >VERSION		; \
	echo Version $$V

# Dummy target to force execution of dependent targets.
#
FORCE:


# 'G960BASE' should be defined at invocation

install: install_gnu install_intel

install_gnu:	${GNU_LIBS}
	mv -f ${GNU_LIBS} ${G960BASE}/lib

#install_intel:	${INTEL_LIBS}
#	mv -f ${INTEL_LIBS} ${G960BASE}/lib

install_intel:
	@echo "Use version of libc supplied with Intel tools"

clean:
	rm -f *.o *.a ${ALL_FLAGS}
