# Makefile for GNU binary-file utilities
# Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.

# This file is part of GNU binutils.

# This program 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 2 of the License, or
# (at your option) any later version.
# 
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

srcdir = .

prefix = /usr/local

program_transform_name =
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
libdir = $(exec_prefix)/lib
tooldir = $(exec_prefix)/$(target_alias)

datadir = $(prefix)/lib
mandir = $(prefix)/man
man1dir = $(mandir)/man1
man2dir = $(mandir)/man2
man3dir = $(mandir)/man3
man4dir = $(mandir)/man4
man5dir = $(mandir)/man5
man6dir = $(mandir)/man6
man7dir = $(mandir)/man7
man8dir = $(mandir)/man8
man9dir = $(mandir)/man9
infodir = $(prefix)/info
includedir = $(prefix)/include
docdir = $(datadir)/doc

SHELL = /bin/sh

INSTALL = `cd $(srcdir)/..;pwd`/install.sh -c
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) 
INSTALL_XFORM = $(INSTALL) -t='$(program_transform_name)'
INSTALL_XFORM1 = $(INSTALL_XFORM) -b=.1

AR = ar
AR_FLAGS = qv
CFLAGS = -g
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi
RANLIB = ranlib
BISONFLAGS = -d
TEXI2ROFF=texi2roff
MAKEOVERRIDES=
CC_FOR_BUILD = $(CC)
NM_FOR_TARGET = nm
NM = $(NM_FOR_TARGET)
SYMLINK = ln -s

# Comment these out if using lex.
# Distribution version

# Distribution name

# Where to find texinfo.tex to format docn with TeX
TEXIDIR = $(srcdir)/../texinfo

#CC=gcc -Wall
CC=cc

# These should all be the same program too.
RUN_PROG=run
SIM_LIB=libsim.a
ADDL_LIBS=

PROGS = $(RUN_PROG)
LIBS= $(SIM_LIB)

DISTSTUFF = $(PROGS) $(LIBS)

BASEDIR = $(srcdir)/../..
BFDDIR = $(BASEDIR)/bfd
INCDIR	= $(BASEDIR)/include
GDBDIR = $(BASEDIR)/gdb
INCLUDES = -I. -I$(srcdir) -I../../bfd -I$(BFDDIR) -I$(INCDIR) -I$(GDBDIR)

#### host and target dependant Makefile fragments come in here.
###

ALL_CFLAGS = $(INCLUDES) $(HDEFINES) $(TDEFINES) $(CFLAGS)

.c.o:
	$(CC) -c $(ALL_CFLAGS) $<

#
## Random definitions
# Hopefully all these may be flushed once we get configuration down pat.

# alloca only needed for systems which don't have it and when cc != gcc.
# ALLOCA = alloca.o

# nm tries to malloc enough space for the string table.  The old GNU malloc
# rounds this up to a power of two (e.g. 5M becomes 8M), and so it might 
# fail unnecessarily.  I've also seen some Unix malloc's fail, even when
# there is enough memory.  So use the new GNU malloc.
# MALLOC = gmalloc.o
# Use this if the system malloc is good enough.
MALLOC =

# Use the GNU getopt unless you have problems with it.
# The IRIS version could probably benefit from being assembled with
# libmalloc rather than the ordinary malloc.
LIBIBERTY = ../../libiberty/libiberty.a

BFD = ../../bfd/libbfd.a
OPCODES = ../../opcodes/libopcodes.a

RUNTEST = runtest
RUNTESTFLAGS = 
FLAGS_TO_PASS = \
	"CC=$(CC)" \
	"CFLAGS=$(CFLAGS)" \
	"RUNTEST=$(RUNTEST)" \
	"RUNTESTFLAGS=$(RUNTESTFLAGS)"

#
## The rules

all: $(LIBS) $(PROGS)


$(RUN_PROG): $(LIBS) run.o $(BFD)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $(RUN_PROG) run.o $(SIM_LIB) $(BFD) $(LIBIBERTY)

$(SIM_LIB): case.o interp.o
	rm -f $(SIM_LIB)
	$(AR) $(AR_FLAGS) $(SIM_LIB) case.o interp.o
	$(RANLIB) $(SIM_LIB)

case.c: gencode
	./gencode -c >case.c                     ; \
	if [ -x /usr/latest/bin/indent ] ; then    \
		/usr/latest/bin/indent case.c    ; \
	fi

optable:gencode
	./gencode >optable
	./gencode -a >$(srcdir)/../../opcodes/w65-opc.h
	
gencode:gencode.c
	$(CC) -o gencode $<

case.o:case.c
run.o:run.c
interp.o:interp.c


######################################################################

mostlyclean:
	-rm -f *.o *~ \#* core binutils.?? binutils.??? case.c

clean: mostlyclean
	-rm -f $(PROGS) *.o *.a

distclean:
	-rm -f Makefile config.status sysdep.h *.o *~ \#* core y.* \
		binutils.?? binutils.??s binutils.aux binutils.log binutils.toc gencode run
	-rm -f $(PROGS) underscore.c

realclean: clean distclean
	-rm -f $(DISTSTUFF) TAGS

etags tags: TAGS

TAGS: force
	etags $(INCDIR)/*.h $(srcdir)/*.[hc] 

install: all 
	for i in $(PROGS) ; do \
	  $(INSTALL_XFORM) $$i $(bindir)/`echo $$i | sed -e 's/.new//'` ; \
	done

install-info:

clean-info:
	-rm -rf *.info*

# Making a dist:
# cvs rtag binutils-x-yy ld+utils
# cvs co -r binutils-x-yy ld+utils
# Sanitize
# cd {HERE}; make dist [-f Makefile.in]

dist: $(DIST_NAME).tar.z

diststuff: $(DISTSTUFF)

$(DIST_NAME).tar.z:
	cd ../..; rm -f $(DIST_NAME); ln -s devo $(DIST_NAME)
	make diststuff -f Makefile.in
	cd ../ld; make diststuff -f Makefile.in
	cd ../gprof; make diststuff -f Makefile.in
	cd ../texinfo; mv texinfo.tex ..; rm -rf *; mv ../texinfo.tex .
	# Take out texinfo from configurable dirs
	mv ../configure.in tmp; \
	  sed -e '/^host_tools=/s/texinfo //' <tmp >../configure.in; rm tmp
	cd ..; chmod og=u `find . -print`
	cd ../..; tar chf - $(DIST_NAME) | gzip >$(DIST_NAME).tar.z
	rm -rf ../../$(DIST_NAME)


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

# 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

Makefile: $(srcdir)/Makefile.in $(host_makefile_frag) $(target_makefile_frag)
	$(SHELL) ./config.status

### Local Variables: ***
### mode:fundamental ***
### page-delimiter: "^#" ***
### End: ***
### end of file