#ident "@(#)makefile	35.1     88/08/26     "
#ident "Copyright (c) 1985 AT&T, INC and  MOTOROLA, INC."
#
#	m68k AS MAKEFILE
#	     generic makefile for mc68000 family
#	     The environment/makefile variable PROCESSOR
#	     should be set to indicate which one.
#            Current values are M68000, M68010, M68020, M68030
#	

SGS=
OWN=	bin		#file owner
GRP=	bin		#file group
PROT=	755		#protections
ROOT=	

BINDIR=	$(ROOT)/bin
BASE = ../..
M68INC=	$(BASE)/inc/m68k
COMINC=	$(BASE)/inc/common
COMAS=	$(BASE)/as/common
M68K=   $(BASE)/as/m68k
M68020= $(M68K)/M68020
INC=    /usr/include
INCSYS= /usr/include/sys
INCLOC=/usr/include/local
ARCH=	AR32W
FLEX=	-DFLEXNAMES
SDBFLAG= -g

COPROCESSOR = -DM68881 -DM68851 -DM68030

#CC=     cc
LINT=	lint
YACC=	yacc
LFLAGS=	-p
CFLAGS=         -O # $(SDBFLAG)
INCLIST=        -I$(M68K) -I$(M68020) -I$(M68INC) -I$(COMINC) -I$(COMAS)
DEFLIST=        -DINT32BIT $(DBUG) -DM68020 $(COPROCESSOR)
ODEFLIST=	-DONEPROC $(FLEX) -D$(ARCH)
LDFLAGS=        $(SDBFLAG)
YFLAGS=         -d
#DBUG=
DBUG=           -DNO_DBUG
#LIBS=          /usr/local/lib/libdbug.a
LIBS=

CC_CMD= $(CC) -c $(CFLAGS) $(INCLIST) $(DEFLIST) $(ODEFLIST)
YACC_CMD=	$(YACC) $(YFLAGS)
LINT_CMD= $(LINT) $(LFLAGS) $(INCLIST) $(DEFLIST) $(ODEFLIST)

OFILES= symbols.o expand1.o expand2.o instab.o gencode.o getstab.o \
	symlist.o code.o codeout.o parse.o addr2.o addr1.o obj.o \
	dofpnum.o pass0.o pass1.o pass2.o errors.o
#
HFILES= $(COMAS)/codeout.h    $(M68K)/gendefs.h     $(M68020)/instab.h    \
	$(M68020)/ops.out     $(M68INC)/paths.h     $(COMAS)/expand.h     \
	$(M68K)/expand2.h     parse.h               $(COMINC)/reloc.h     \
	$(COMINC)/syms.h      $(COMINC)/storclass.h $(COMINC)/filehdr.h   \
	$(COMINC)/scnhdr.h    $(COMINC)/linenum.h   $(M68INC)/sgs.h       \
	$(M68K)/fpnum.h       $(M68K)/fpinit.h      $(INC)/stdio.h        \
	$(M68K)/pass0.h       $(M68K)/systems.h     $(COMAS)/dbug.h       \
	$(INC)/string.h       $(M68K)/symbols2.h    $(COMAS)/symbols.h    \
	$(INC)/signal.h       $(INC)/ctype.h        $(INCLOC)/dbug.h      \
	$(INCSYS)/utsname.h
#
CFILES= $(COMAS)/pass0.c      $(COMAS)/instab.c    parse.c        \
	$(M68020)/gencode.c   $(M68020)/addr2.c    $(M68020)/expand2.c    \
	$(COMAS)/pass1.c      $(COMAS)/code.c      $(COMAS)/expand1.c     \
	$(COMAS)/errors.c     $(COMAS)/pass2.c     $(COMAS)/addr1.c       \
	$(COMAS)/codeout.c    $(COMAS)/getstab.c   $(COMAS)/obj.c         \
	$(COMAS)/symlist.c    $(M68K)/dofpnum.c    $(COMAS)/symbols1.c    \
	$(COMAS)/symbols2.c   $(COMAS)/symbols.c
#
SRCFILES=$(COMAS)/pass0.c     $(COMAS)/instab.c    $(M68020)/parse.y \
	$(M68020)/gencode.c   $(M68020)/addr2.c    $(M68020)/expand2.c \
	$(COMAS)/pass1.c      $(COMAS)/code.c      $(COMAS)/expand1.c  \
	$(COMAS)/errors.c     $(COMAS)/pass2.c     $(COMAS)/addr1.c    \
	$(COMAS)/codeout.c    $(COMAS)/getstab.c   $(COMAS)/obj.c      \
	$(COMAS)/symlist.c    $(M68K)/dofpnum.c    $(COMAS)/symbols2.c \
	$(COMAS)/symbols.c
#

build:	$(SGS)as

#-------------------------
$(SGS)as:	$(OFILES)
		$(CC) $(CFLAGS) $(LDFLAGS) -o $(SGS)as $(OFILES) $(LIBS)

pass0.o:        $(COMAS)/pass0.c $(INC)/stdio.h $(INC)/signal.h $(INC)/ctype.h \
		$(M68INC)/paths.h $(M68K)/systems.h $(M68K)/pass0.h \
		$(M68INC)/sgs.h  $(COMAS)/dbug.h $(M68K)/gendefs.h  \
		$(M68K)/expand2.h $(INCSYS)/utsname.h
		$(CC_CMD) $(COMAS)/pass0.c

# The baroque code here tries to keep file times in sync to
# avoid unnecessary re-compilations.

parse.o:        parse.c $(INC)/stdio.h $(INC)/string.h $(COMAS)/symbols.h \
		$(M68020)/instab.h $(M68K)/gendefs.h $(M68K)/fpnum.h \
		$(COMAS)/dbug.h
		$(CC_CMD) parse.c

instab.o:       $(COMAS)/instab.c $(COMAS)/symbols.h $(M68020)/instab.h \
		parse.h $(M68020)/ops.out
		$(CC_CMD) $(COMAS)/instab.c

parse.c:	y.tab.c
		if cmp -s y.tab.c parse.c;then :;else cp y.tab.c parse.c;fi
parse.h:	y.tab.h
		if cmp -s y.tab.h parse.h;then :;else cp y.tab.h parse.h;fi

y.tab.c y.tab.h :       $(M68020)/parse.y
		$(YACC_CMD) $(M68020)/parse.y

# end baroque code

$(COMINC)/syms.h:       $(COMINC)/storclass.h

$(COMAS)/dbug.h:        $(INC)/stdio.h $(INCLOC)/dbug.h

$(COMAS)/symbols.h:     $(COMINC)/syms.h $(M68K)/systems.h

code.o:         $(COMAS)/code.c $(INC)/stdio.h $(COMAS)/symbols.h \
		$(COMAS)/codeout.h $(M68K)/gendefs.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/code.c

errors.o:       $(COMAS)/errors.c $(INC)/stdio.h $(INC)/signal.h \
		$(M68K)/systems.h $(M68K)/gendefs.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/errors.c

pass1.o:        $(COMAS)/pass1.c $(INC)/stdio.h $(INC)/ctype.h \
		$(INC)/signal.h $(M68INC)/paths.h $(COMAS)/symbols.h \
		$(M68K)/gendefs.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/pass1.c

gencode.o:      $(M68020)/gencode.c $(INC)/stdio.h $(COMAS)/symbols.h \
		$(M68020)/instab.h $(M68K)/gendefs.h $(COMAS)/expand.h \
		$(M68K)/expand2.h $(COMAS)/dbug.h $(M68K)/fpnum.h
		$(CC_CMD) $(M68020)/gencode.c

expand1.o:      $(COMAS)/expand1.c $(INC)/stdio.h $(COMAS)/symbols.h \
		$(COMAS)/expand.h $(M68K)/gendefs.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/expand1.c

expand2.o:      $(M68020)/expand2.c $(COMAS)/symbols.h $(COMAS)/expand.h \
		$(M68K)/expand2.h
		$(CC_CMD) $(M68020)/expand2.c

addr1.o:        $(COMAS)/addr1.c $(INC)/stdio.h $(COMINC)/filehdr.h \
		$(COMINC)/reloc.h $(COMINC)/linenum.h $(COMAS)/symbols.h \
		$(M68K)/gendefs.h $(COMAS)/codeout.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/addr1.c

addr2.o:        $(M68020)/addr2.c $(INC)/stdio.h $(COMAS)/symbols.h \
		$(M68020)/instab.h $(M68K)/gendefs.h $(COMAS)/codeout.h \
		$(COMINC)/reloc.h $(COMAS)/dbug.h
		$(CC_CMD) $(M68020)/addr2.c

codeout.o:      $(COMAS)/codeout.c $(INC)/stdio.h $(COMAS)/symbols.h \
		$(COMAS)/codeout.h $(M68K)/gendefs.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/codeout.c

getstab.o:      $(COMAS)/getstab.c $(INC)/stdio.h $(M68K)/gendefs.h \
		$(COMAS)/symbols.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/getstab.c

pass2.o:        $(COMAS)/pass2.c $(INC)/stdio.h $(INC)/signal.h \
		$(INC)/ctype.h $(M68K)/gendefs.h $(COMAS)/symbols.h \
		$(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/pass2.c

obj.o:          $(COMAS)/obj.c $(INC)/stdio.h $(M68INC)/sgs.h \
		$(COMINC)/filehdr.h $(COMINC)/linenum.h $(COMINC)/reloc.h \
		$(COMINC)/scnhdr.h $(COMAS)/symbols.h $(M68K)/gendefs.h \
		$(COMAS)/codeout.h $(COMAS)/dbug.h $(M68020)/instab.h
		$(CC_CMD) $(COMAS)/obj.c

symlist.o:      $(COMAS)/symlist.c $(INC)/stdio.h $(INC)/string.h \
		$(M68K)/gendefs.h $(COMAS)/symbols.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/symlist.c

symbols.o:      $(COMAS)/symbols.c $(INC)/stdio.h $(INC)/string.h\
		$(COMAS)/symbols.h $(M68K)/symbols2.h $(COMAS)/dbug.h
		$(CC_CMD) $(COMAS)/symbols.c

dofpnum.o:      $(M68K)/dofpnum.c $(M68K)/systems.h $(M68K)/fpnum.h \
		$(M68K)/fpinit.h $(COMAS)/dbug.h
		$(CC_CMD) dofpnum.c

symbols2.o:     $(COMAS)/symbols2.c $(COMAS)/symbols.c

#-------------------------

install:	$(SGS)as
		-rm -f $(BINDIR)/$(SGS)as
		cp $(SGS)as $(BINDIR)
		strip $(BINDIR)/$(SGS)as
		chmod $(PROT) $(BINDIR)/$(SGS)as
		chgrp $(GRP) $(BINDIR)/$(SGS)as
		chown $(OWN) $(BINDIR)/$(SGS)as
		if [ "$(SGS)" = "" -o "$(SGS)" = "20" ] ; \
		then : \
			ln $(BINDIR)/$(SGS)as $(BINDIR)/$(SGS)ljas ;  \
			ln $(BINDIR)/$(SGS)as $(BINDIR)/as00 ;  \
			ln $(BINDIR)/$(SGS)as $(BINDIR)/as10 ;  \
			ln $(BINDIR)/$(SGS)as $(BINDIR)/as20 ;  \
			ln $(BINDIR)/$(SGS)as $(BINDIR)/as30 ;  \
		fi

#--------------------------

save:	$(BINDIR)/$(SGS)as
	-rm -f $(BINDIR)/$(SGS)as.bak
	cp $(BINDIR)/$(SGS)as $(BINDIR)/$(SGS)as.bak

#--------------------------

uninstall:      $(BINDIR)/$(SGS)as.bak
		-rm -f $(BINDIR)/$(SGS)as
		cp $(BINDIR)/$(SGS)as.bak $(BINDIR)/$(SGS)as

#--------------------------

clean:
	-rm -f $(OFILES)

#--------------------------

clobber shrink: clean
		-rm -f $(SGS)as parse.c parse.h y.tab.c y.tab.h

#--------------------------

lint:	$(COMINC)/a.out.h $(COMINC)/ar.h \
	$(CFILES)
	$(LINT_CMD) $(CFILES) >lint.out

#--------------------------

cflow: $(SRCFILES)
	cflow -ix -i_ $(INCLIST) $(DEFLIST) $(ODEFLIST) $(SRCFILES)
