# Makefile for Intel 960 GNU C compiler.
#   Copyright (C) 1987, 1988 Free Software Foundation, Inc.

# this file has been adapted for the Intel GNU/960 distribution by Intel Corp.

#This file is part of GNU CC.

#GNU CC is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 1, or (at your option)
#any later version.

#GNU CC is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with GNU CC; see the file COPYING.  If not, write to
#the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.


# Variables that exist for you to override.
# See below for how to change them for certain systems.

#__i386v__#USG=-DUSG
#__i386v__#GCCCP=./gcccp
OPT = -g
CFLAGS = $(OPT) $(XCFLAGS)
CPPFLAGS=$(USG)
CC = cc
BISON = bison
BISONFLAGS = -v
AR = ar
SHELL = /bin/sh

WHOAMI=whoami
LINK = ln -s
# sysV equivalents for the above, uncommented by 'mkmake'
#__i386v__#WHOAMI = logname
#__i386v__#LINK = ln

# Directory where sources are, from where we are.
srcdir = .

# Additional system libraries to link with.
CLIB=

# Change this to a null string if obstacks are installed in the
# system library.
OBSTACK=obstack.o

# Directory to link to, when using the target `maketest'.
DIR = ../gcc

# End of variables for you to override.

# Variables you should change for certain systems.

# These are what you would need on HPUX:
# CFLAGS = -Wc,-Ns2000 -Wc,-Ne700 -Wc,-Np300
# If you are using the GNU assembler and linker on HPUX,
# add -I../hp-include to CFLAGS.
# -g is desirable in CFLAGS, but a compiler bug in HPUX version 5
# bites whenever tree.def, rtl.def or machmode.def is included
# (ie., on every source file).
# If you have a floating point accelerator, you might want -lsetjmp as well.
# CCLIBFLAGS = -Wc,-Ns2000 -Wc,-Ne700
# For CCLIBFLAGS you might want to specify the switch that
# forces only 68000 instructions to be used.

# If you are making gcc for the first time, and if you are compiling it with
# a non-gcc compiler, and if your system doesn't have a working alloca() in any
# of the standard libraries (as is true for HP/UX or Genix),
# then get alloca.c from GNU Emacs and un-comment the following line:
# ALLOCA = alloca.o
# But don't do that if compiling using GCC.
#__i386v__#ALLOCA = alloca.o

# If your system has alloca() in /lib/libPW.a, un-comment the following line:
# CLIB= -lPW

# On a pyramid, you need to uncomment the following line:
# CLIB= -lalloca

# If your system's malloc() routine fails for any reason (as it does on
# certain versions of Genix), try getting the files
# malloc.c and getpagesize.h from GNU Emacs and un-comment the following line:
# MALLOC = malloc.o

# If you are running GCC on an Apollo (SR10.x),
# go into a Berkeley environment and use this:
# CFLAGS = -g -A nansi -A cpu,3000 -A runtype,bsd4.3 -A systype,any
# CPPFLAGS = -DSHORT_ENUM_BUG
# (Says vasta@apollo.com.)


# Dependency on obstack, alloca, malloc or whatever library facilities
# are not installed in the system libraries.
LIBDEPS= $(OBSTACK) $(ALLOCA) $(MALLOC)

# How to link with both our special library facilities
# and the system's installed libraries.
LIBS = $(OBSTACK) $(ALLOCA) $(MALLOC) $(CLIB)

# Specify the directories to be searched for header files.
# Both . and srcdir are used, in that order,
# so that tm.h and config.h will be found in the compilation
# subdirectory rather than in the source directory.
INCLUDES = -I.

# Always use -I$(srcdir)/config when compiling.
.c.o:
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $<

# The i386v C preprocessor can't handle the amount of #defining that goes on
# in the gcc source.  We build a local version of the GNU cpp and use it to
# preprocess each source file to a temp file, which is then compiled.
#__i386v__#TMPDIR=TMP
#__i386v__#.c.o:
#__i386v__#	$(GCCCP) -Di386 -traditional $(CPPFLAGS) -I.. $(INCLUDES) -I/usr/include < $< > $(TMPDIR)/$<
#__i386v__#	$(CC) $(CFLAGS) -c $(TMPDIR)/$<
#__i386v__#	-rm -f $(TMPDIR)/$<

# Language-specific object files for C.
C_OBJS = c-parse.tab.o c-decl.o c-typeck.o c-convert.o

# Language-independent object files.
OBJS = toplev.o version.o tree.o print-tree.o stor-layout.o fold-const.o \
 rtl.o rtlanal.o expr.o stmt.o expmed.o explow.o optabs.o varasm.o \
 symout.o dbxout.o sdbout.o emit-rtl.o insn-emit.o \
 integrate.o jump.o cse.o loop.o flow.o stupid.o combine.o \
 regclass.o local-alloc.o global-alloc.o reload.o reload1.o caller-save.o \
 insn-peep.o final.o recog.o insn-recog.o insn-extract.o insn-output.o

# The files that "belong" in CONFIG_H are deliberately omitted
# because having them there would not be useful in actual practice.
# All they would do is cause complete recompilation every time
# one of the machine description files is edited.
# That may or may not be what one wants to do.
# If it is, rm *.o is an easy way to do it.
# CONFIG_H = config.h tm.h
CONFIG_H =
RTL_H = rtl.h rtl.def machmode.def
TREE_H = tree.h real.h tree.def machmode.def
CPLUS_TREE_H = $(TREE_H) cplus-tree.h c-tree.h

# Note that dependencies on obstack.h are not written
# because that file is not part of GCC.
# Dependencies on gvarargs.h are not written
# because all that file does, when not compiling with GCC,
# is include the system varargs.h.

all: gcc960 cc1 cpp

config.i960: md tm.h config.h aux-output.c
	-if test -r md -a -r tm.h -a -r config.h -a aux-output.c; then touch config.i960; fi

tm.h: tm-i960.h
	$(LINK) tm-i960.h tm.h

md: i960.md
	$(LINK) i960.md md

config.h: xm-i960.h
	$(LINK) xm-i960.h config.h

aux-output.c: out-i960.c
	$(LINK) out-i960.c aux-output.c

target_vers.o:
	@echo 'char *target_version_string = "' `cat MAJVERS`.`cat MINVERS`, `date` by `$(WHOAMI)`'";' > target_vers.c
	@expr `cat MINVERS` + 1 > MINVERS
	@$(CC) -c target_vers.c

gcc960: config.i960 $(TMPDIR) $(GCCCP) gcc960.o version.o $(LIBDEPS) VERSION
	make ver960.o
	$(CC) $(CFLAGS) $(LDFLAGS) -o gcc960 gcc960.o version.o ver960.o $(LIBS)

gcc: gcc.o version.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o gcc gcc.o version.o $(LIBS)

cc1: config.i960 $(TMPDIR) $(GCCCP) $(C_OBJS) $(OBJS) $(LIBDEPS) target_vers.o VERSION
	make ver960.o
	$(CC) $(CFLAGS) -o cc1 $(C_OBJS) $(OBJS) target_vers.o ver960.o $(LIBS)

# C language specific files.

c-parse.tab.o : $(srcdir)/c-parse.tab.c $(CONFIG_H) $(TREE_H) c-parse.h c-tree.h input.h
$(srcdir)/c-parse.tab.c : $(srcdir)/c-parse.y
	$(BISON) $(BISONFLAGS) $(srcdir)/c-parse.y -o $@

c-decl.o : c-decl.c $(CONFIG_H) $(TREE_H) c-tree.h c-parse.h flags.h
c-typeck.o : c-typeck.c $(CONFIG_H) $(TREE_H) c-tree.h flags.h
c-convert.o : c-convert.c $(CONFIG_H) $(TREE_H)

# Language-independent files.

gcc.o: gcc.c $(CONFIG_H)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) \
  -DSTANDARD_STARTFILE_PREFIX=\"$(libdir)/\" \
  -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc-\" -c \
  `echo $(srcdir)/gcc.c | sed 's,^\./,,'`

version.o: version.c
obstack.o: obstack.c
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $(INCLUDES) obstack.c

tree.o : tree.c $(CONFIG_H) $(TREE_H) flags.h
print-tree.o : print-tree.c $(CONFIG_H) $(TREE_H)
stor-layout.o : stor-layout.c $(CONFIG_H) $(TREE_H) $(RTL_H)
fold-const.o : fold-const.c $(CONFIG_H) $(TREE_H)
toplev.o : toplev.c $(CONFIG_H) $(TREE_H) flags.h input.h

rtl.o : rtl.c $(CONFIG_H) $(RTL_H)

rtlanal.o : rtlanal.c $(CONFIG_H) $(RTL_H)

varasm.o : varasm.c $(CONFIG_H) $(TREE_H) $(RTL_H) flags.h expr.h \
   insn-codes.h hard-reg-set.h
stmt.o : stmt.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h  \
   insn-flags.h expr.h insn-config.h regs.h hard-reg-set.h insn-codes.h
expr.o : expr.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h  \
   insn-flags.h insn-codes.h expr.h insn-config.h recog.h
expmed.o : expmed.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h  \
   insn-flags.h insn-codes.h expr.h insn-config.h recog.h
explow.o : explow.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h expr.h insn-codes.h
optabs.o : optabs.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h  \
   insn-flags.h insn-codes.h expr.h insn-config.h recog.h
symout.o : symout.c $(CONFIG_H) $(TREE_H) $(RTL_H) symseg.h gdbfiles.h
dbxout.o : dbxout.c $(CONFIG_H) $(TREE_H) $(RTL_H) flags.h
sdbout.o : sdbout.c $(CONFIG_H) $(TREE_H) $(RTL_H)

emit-rtl.o : emit-rtl.c $(CONFIG_H) $(RTL_H) regs.h insn-config.h real.h

integrate.o : integrate.c $(CONFIG_H) $(RTL_H) $(TREE_H) flags.h expr.h \
   insn-flags.h insn-codes.h 

jump.o : jump.c $(CONFIG_H) $(RTL_H) flags.h regs.h
stupid.o : stupid.c $(CONFIG_H) $(RTL_H) regs.h hard-reg-set.h

cse.o : cse.c $(CONFIG_H) $(RTL_H) regs.h hard-reg-set.h flags.h real.h
loop.o : loop.c $(CONFIG_H) $(RTL_H) insn-config.h insn-codes.h \
   regs.h hard-reg-set.h recog.h flags.h expr.h
flow.o : flow.c $(CONFIG_H) $(RTL_H) basic-block.h regs.h hard-reg-set.h
combine.o : combine.c $(CONFIG_H) $(RTL_H) flags.h  \
   insn-config.h regs.h basic-block.h recog.h
regclass.o : regclass.c $(CONFIG_H) $(RTL_H) hard-reg-set.h flags.h \
   basic-block.h regs.h insn-config.h recog.h 
local-alloc.o : local-alloc.c $(CONFIG_H) $(RTL_H) flags.h basic-block.h regs.h \
   hard-reg-set.h insn-config.h recog.h
global-alloc.o : global-alloc.c $(CONFIG_H) $(RTL_H) flags.h  \
   basic-block.h regs.h hard-reg-set.h insn-config.h

reload.o : reload.c $(CONFIG_H) $(RTL_H) flags.h \
   reload.h recog.h hard-reg-set.h insn-config.h regs.h
reload1.o : reload1.c $(CONFIG_H) $(RTL_H) flags.h  \
   reload.h regs.h hard-reg-set.h insn-config.h basic-block.h recog.h
caller-save.o : caller-save.c $(CONFIG_H) $(RTL_H) flags.h \
   reload.h regs.h hard-reg-set.h insn-config.h basic-block.h recog.h
final.o : final.c $(CONFIG_H) $(RTL_H) flags.h regs.h recog.h conditions.h \
   gdbfiles.h insn-config.h real.h output.h
recog.o : recog.c $(CONFIG_H) $(RTL_H)  \
   regs.h recog.h hard-reg-set.h insn-config.h real.h

# Normally this target is not used; but it is used if you
# define ALLOCA=alloca.o.  
alloca.o:	alloca.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c alloca.c

# Now the source files that are generated from the machine description.

.PRECIOUS: insn-config.h insn-flags.h insn-codes.h \
  insn-emit.c insn-recog.c insn-extract.c insn-output.c insn-peep.c

# The following pair of rules has this effect:
# genconfig is run only if the md has changed since genconfig was last run;
# but the file insn-config.h is touched only when its contents actually change.

# Each of the other insn-* files is handled by a similar pair of rules.

insn-config.h: stamp-config.h ;
stamp-config.h : md genconfig
	./genconfig md > tmp-insn-config.h
	$(srcdir)/move-if-change tmp-insn-config.h insn-config.h
	touch stamp-config.h

insn-flags.h: stamp-flags.h ;
stamp-flags.h : md genflags
	./genflags md > tmp-insn-flags.h
	$(srcdir)/move-if-change tmp-insn-flags.h insn-flags.h
	touch stamp-flags.h

insn-codes.h: stamp-codes.h ;
stamp-codes.h : md gencodes
	./gencodes md > tmp-insn-codes.h
	$(srcdir)/move-if-change tmp-insn-codes.h insn-codes.h
	touch stamp-codes.h

insn-emit.o : insn-emit.c $(CONFIG_H) $(RTL_H) expr.h real.h insn-codes.h
insn-emit.o : insn-config.h insn-flags.h

insn-emit.c: stamp-emit.c ;
stamp-emit.c : md genemit
	./genemit md > tmp-insn-emit.c
	$(srcdir)/move-if-change tmp-insn-emit.c insn-emit.c
	touch stamp-emit.c

insn-recog.o : insn-recog.c $(CONFIG_H) $(RTL_H) insn-config.h real.h recog.h

insn-recog.c: stamp-recog.c ;
stamp-recog.c : md genrecog
	./genrecog md > tmp-insn-recog.c
	$(srcdir)/move-if-change tmp-insn-recog.c insn-recog.c
	touch stamp-recog.c

insn-extract.o : insn-extract.c $(CONFIG_H) $(RTL_H)

insn-extract.c: stamp-extract.c ;
stamp-extract.c : md genextract
	./genextract md > tmp-insn-extract.c
	$(srcdir)/move-if-change tmp-insn-extract.c insn-extract.c
	touch stamp-extract.c

insn-peep.o : insn-peep.c $(CONFIG_H) $(RTL_H) regs.h real.h

insn-peep.c: stamp-peep.c ;
stamp-peep.c : md genpeep
	./genpeep md > tmp-insn-peep.c
	$(srcdir)/move-if-change tmp-insn-peep.c insn-peep.c
	touch stamp-peep.c

insn-output.o : insn-output.c $(CONFIG_H) $(RTL_H) regs.h real.h conditions.h
insn-output.o : hard-reg-set.h insn-config.h insn-flags.h output.h aux-output.c

insn-output.c: stamp-output.c ;
stamp-output.c : md genoutput
	./genoutput md > tmp-insn-output.c
	$(srcdir)/move-if-change tmp-insn-output.c insn-output.c
	touch stamp-output.c

# Now the programs that generate those files.
# $(CONFIG_H) is omitted from the deps of the gen*.o
# because these programs don't really depend on anything 
# about the target machine.  They do depend on config.h itself,
# since that describes the host machine.

genconfig : genconfig.o rtl.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o genconfig genconfig.o rtl.o $(LIBS)

genconfig.o : genconfig.c $(RTL_H) config.h

genflags : genflags.o rtl.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o genflags genflags.o rtl.o $(LIBS)

genflags.o : genflags.c $(RTL_H) config.h

gencodes : gencodes.o rtl.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o gencodes gencodes.o rtl.o $(LIBS)

gencodes.o : gencodes.c $(RTL_H) config.h

genemit : genemit.o rtl.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genemit genemit.o rtl.o $(LIBS)

genemit.o : genemit.c $(RTL_H) config.h

genrecog : genrecog.o rtl.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genrecog genrecog.o rtl.o $(LIBS)

genrecog.o : genrecog.c $(RTL_H) config.h

genextract : genextract.o rtl.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genextract genextract.o rtl.o $(LIBS)

genextract.o : genextract.c $(RTL_H) config.h

genpeep : genpeep.o rtl.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genpeep genpeep.o rtl.o $(LIBS)

genpeep.o : genpeep.c $(RTL_H) config.h

genoutput : genoutput.o rtl.o $(LIBDEPS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o genoutput genoutput.o rtl.o $(LIBS)

genoutput.o : genoutput.c $(RTL_H) config.h

#-----------------------------------------------------------------------------
# Make the preprocessor
#-----------------------------------------------------------------------------
cpp: config.i960 $(TMPDIR) $(GCCCP) cccp.o cexp.o version.o $(LIBDEPS) VERSION
	make ver960.o
	$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o cpp cccp.o cexp.o version.o ver960.o $(LIBS)

cexp.o: $(srcdir)/cexp.c $(CONFIG_H)
cexp.c: $(srcdir)/cexp.y
	$(BISON) -o cexp.c cexp.y

cccp.o: cccp.c $(CONFIG_H)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -DCROSS_CPP -c cccp.c

#-----------------------------------------------------------------------------
# Make a version of the preprocessor for local use;  this is necessary on the
# i386v, whose native preprocessor can't handle some these source files.
#
# Compile explicitly here:  can't use the general ".c.o" rule because it
# wants to use the very thing we're building.
#
# Make sure to blow away cccp.o, because the 80960 version mustn't use it:
# it needs to be recompiled with 'CROSS_CPP' #define'd.
#-----------------------------------------------------------------------------
./gcccp: cccp.c $(CONFIG_H) cexp.c version.c $(LIBDEPS)
	$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -o gcccp cccp.c cexp.c \
		version.c $(LIBS)
	rm cccp.o

#-----------------------------------------------------------------------------
# Make a temp directory where we can put gcccp's output.
#-----------------------------------------------------------------------------
TMP:
	mkdir TMP

#-----------------------------------------------------------------------------
# Delete the temp files made in the course of building gnulib
# Delete all objects, and all targets
#-----------------------------------------------------------------------------
clean:
	-rm -f stamp-*.[ch] tmp-insn-*
	-rm -f *.s *.s[0-9] *.co *.greg *.lreg *.combine *.flow *.cse *.jump *.rtl *.tree *.loop *.dbr *.jump2
	-rm -f core float.h hard-params
	-rm -f *.o
	-rm -f TMP/*
	-rm -f gcc960 cc1 cpp

# Like clean but also delete the links made to configure gcc.
# Also removes gnulib, since that is desirable if you are changing cpus.
cleanconfig: clean
	-rm -f tm.h aux-output.c config.h md config.status gnulib stamp-gnulib2


#-----------------------------------------------------------------------------
#		'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 gcc960_ver[]= \"gcc960 `cat VERSION`, `date`\";" > ver960.c
	echo "char cc1960_ver[]= \"cc1.960 `cat VERSION`, `date`\";" >>ver960.c
	echo "char cpp960_ver[]= \"cpp.960 `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 redefined at invocation
#
G960BASE=../../../$(HOST)

# Copy the files into directories where they will be run.
#
install-cc1:
	make cc1 OPT=
	strip cc1
	mv -f cc1 $(G960BASE)/lib/cc1.960

install-cpp:
	make cpp OPT=
	strip cpp
	mv -f cpp $(G960BASE)/lib/cpp.960

install-gcc:
	make gcc960 OPT=
	strip gcc960
	mv -f gcc960 $(G960BASE)/bin/gcc960

install: install-cc1 install-cpp install-gcc 

# Target to uncomment host-specific lines in this makefile.  Such lines must
# have the following string beginning in column 1: #__<hostname>__#
# Original Makefile is backed up as 'Makefile.old'.
#
# Invoke with:  make make HOST=xxx
#
make:
	-@if test $(HOST)x = x ; then \
		echo 'Specify "make make HOST=???"'; \
		exit 1; \
	fi ; \
	grep -s "^#The next line was generated by 'make make'" Makefile; \
	if test $$? = 0 ; then	\
		echo "Makefile has already been processed with 'make make'";\
		exit 1; \
	fi ; \
	mv -f Makefile Makefile.old; \
	echo "#The next line was generated by 'make make'"	 >Makefile ; \
	echo "HOST=$(HOST)"					>>Makefile ; \
	echo							>>Makefile ; \
	sed "s/^#__$(HOST)__#//" < Makefile.old			>>Makefile
