# ----------------------------------------------------------------------
#     If you don't have the environment var set, uncomment this
#
# ----------------------------------------------------------------------
# Things to change for other OS/Machinery are marked with
# ... ---- look here ----

#You can't use bison!!
YFLAGS=-dv

# ... ---- look here ----
# ------------------------------------------------------------------------
#	  Change these defines according to your installation
# ------------------------------------------------------------------------
OS=UNIX
EXT=

# MOTOROLA or INTEL currently
MACHINERY=MOTOROLA

CC=gcc
LD=gcc
YACC=yacc # ! bison
STRIP=echo # strip

SRC65=lib/src
INCLUDE=

CFLAGS=-c $(INCLUDE) -D$(OS) -D$(MACHINERY) -DSUN
LFLAGS= 
LIBS=
SLOW=
.c.i:
	$(CPP) $(IFLAGS) -o $*.i $*.c

# ------------------------------------------------------------------------
#	       Until here!  Keeping looking for more...
# ------------------------------------------------------------------------
PRGS=nasm65$(EXT) nlink65$(EXT) nlib65$(EXT)
SUPPORT=xtrctbin$(EXT) chkffff$(EXT) demac65$(EXT) disasm65$(EXT) crlf155$(EXT) nasm$(EXT)

ADEPS=main65.o  asm65.o ops.o  exprasm.o helper.o input.o  segment.o  \
      error.o   debug.o if.o   symbols.o object.o macro.o  process.o  \
      lexer.o   expr.o  imm.o  immasm.o  labels.o ndebug.o errorasm.o \
      sym_asm.o stats.o hash.o float.o   io.o     fix.o    version0.o \
      p_debug.o

LDEPS=link65.o worker.o err_link.o lsymbols.o sym_link.o imm.o        \
      lexpr.o  error.o  exprlink.o lsegment.o debug.o    helper.o     \
      lload.o  lreloc.o stats.o    load.o     hash.o     fix.o        \
      link.o   libfix.o libflip.o version0.o  lp_debug.o
      
DDEPS=disasm.o version0.o helper.o dload.o error.o stats.o debug.o

IDEPS=lib65.o libwork.o error.o debug.o helper.o errorlib.o stats.o   \
      version0.o libfix.o libflip.o

DEPSI=main65.i	asm65.i ops.i  exprasm.i helper.i input.i  segment.i  \
      error.i	debug.i if.i   symbols.i object.i macro.i  process.i  \
      lexer.i	expr.i	imm.i  immasm.i  labels.i ndebug.i errorasm.i \
      sym_asm.i stats.i hash.i float.i	 io.i			      \
      link65.i	worker.i   err_link.i  lsymbols.i sym_link.i	      \
      lexpr.i	exprlink.i segment.i   lload.i	  lreloc.i	      \
      lib65.i	libwork.i  errorlib.i  load.i libfix.i libflip.i

ASCII=*.c *.h *.y *.sun *.tlk demo/*.[hsl]* doc/* $(SRC65)/*.s65 header/*
      
TABASCII=makefile.nix demo/makefile $(SRC65)/makefile.nix

all:		$(PRGS) support

it:		nasm65$(EXT) nlink65$(EXT)

#install:	$(PRGS) support
#	ln -s $(PRGS) $(SUPPORT) $(BINDIR)

GSOURCES=*.h *.c *.tlk *.s *.sun *.y make* MEMO


backup:
	find v.0 kludge support doc lib header demo -print | zoo aunhI $(ARCDIR)/nasm20s
	find $(GSOURCES) -print | zoo aunhI $(ARCDIR)/nasm20s

restore:
	zoo x//O $(ARCDIR)/nasm65

clean:
	rm *.o *.i *~ #*# demo/*~ lib/src/*~

to_us:		crlf155$(EXT)
	crlf155 -s -z -u $(ASCII)
	crlf155 -s -z $(TABASCII)

untabify:	crlf155$(EXT)
	crlf155 -s -n -u -z $(ASCII)

support:	$(SUPPORT)

cpp:	$(DEPSI) xtrctbin.i chkffff.i de_mac.i disasm.i crlf155.i

# ... ---- look here ----
### ******************** CHANGE THESE ***********************
portable$(EXT):	portable.o
	$(LD) $(LFLAGS) $(INIT) -o portable$(EXT) portable.o $(LIBS) 

NXDEPS=nasm.o error.o helper.o debug.o stats.o
nasm$(EXT):	$(NXDEPS)
	$(LD) $(LFLAGS) $(INIT) -o nasm$(EXT) $(NXDEPS) $(LIBS)
	$(STRIP) nasm$(EXT)
	
nasm65$(EXT):	$(ADEPS)
	$(LD) $(LFLAGS) $(INIT) -o nasm65$(EXT) $(ADEPS) $(LIBS)
	$(STRIP) nasm65$(EXT)

nlink65$(EXT):	$(LDEPS)
	$(LD) $(LFLAGS) $(INIT) -o nlink65$(EXT) $(LDEPS) $(LIBS)
	$(STRIP) nlink65$(EXT)

nlib65$(EXT):	$(IDEPS)
	$(LD) $(LFLAGS) $(INIT) -o nlib65$(EXT) $(IDEPS) $(LIBS)
	$(STRIP) nlib65$(EXT)

disasm65$(EXT):	$(DDEPS)
	$(LD) $(LFLAGS) $(INIT) -o disasm65$(EXT) $(DDEPS) $(LIBS) 
	$(STRIP) disasm65$(EXT)


demac65$(EXT):	de_mac.o
	$(LD) $(LFLAGS) $(INIT) -o demac65$(EXT) de_mac.o $(LIBS)
	$(STRIP) demac65$(EXT)

crlf155$(EXT):	crlf155.o
	$(LD) $(LFLAGS) $(INIT) -o crlf155$(EXT) crlf155.o $(LIBS)
	$(STRIP) crlf155$(EXT)

xtrctbin$(EXT):	xtrctbin.o
	$(LD) $(LFLAGS) $(INIT) -o xtrctbin$(EXT) xtrctbin.o $(LIBS)
	$(STRIP) xtrctbin$(EXT)

chkffff$(EXT):	chkffff.o
	$(LD) $(LFLAGS) $(INIT) -o chkffff$(EXT) chkffff.o $(LIBS)
	$(STRIP) chkffff$(EXT)
# ******************* LOOK BELOW FOR MORE *************************

main65.o:	main65.c defines.h nmalloc.h buffer.h debug.h
	$(CC) $(SLOW) $(CFLAGS) $(DEBUG) $(YACCDEBUG) main65.c

debug.o:	debug.c defines.h
	$(CC) $(SLOW) $(CFLAGS) $(DEBUG) debug.c

err_link.o:	err_link.c defines.h
	$(CC) $(SLOW) $(CFLAGS) err_link.c

error.o:	error.c defines.h
	$(CC) $(SLOW) $(CFLAGS) error.c

errorasm.o:	errorasm.c defines.h structs.h y.tab.h buffer.h ops.h
	$(CC) $(SLOW) $(CFLAGS) errorasm.c

errorlib.o:	errorlib.c err_link.o
	$(CC) $(SLOW) $(CFLAGS) errorlib.c

expr.o: 	expr.c defines.h op.h debug.h labels.h structs.h nmalloc.h \
		code.h exprfast.h
	$(CC) $(CFLAGS) expr.c

exprasm.o:	exprasm.c defines.h debug.h labels.h structs.h code.h \
		nmalloc.h exprfast.h op.h
	$(CC) $(CFLAGS) exprasm.c

exprlink.o:	exprlink.c defines.h debug.h structs.h
	$(CC) $(CFLAGS) exprlink.c

fix.o:		fix.c defines.h debug.h structs.h nmalloc.h code.h fix.h \
		labels.h seg.h
	$(CC) $(CFLAGS) fix.c

float.o:	float.c defines.h
	$(CC) $(SLOW) $(CFLAGS) float.c

# ... ---- look here ----
##### uncomment this if you can't use MAS ####
hash.o:	hash.c defines.h
	$(CC) $(CFLAGS) hash.c
##### and comment this out
#hash.o: xhash.s
#	$(ASM) $(AFLAGS) -o hash.o xhash.s
#####

helper.o:	helper.c defines.h debug.h stats.h
	$(CC) $(CFLAGS) helper.c

if.o:		if.c defines.h labels.h y.tab.h debug.h buffer.h 
	$(CC) $(CFLAGS) if.c

imm.o:		imm.c defines.h debug.h structs.h imm.h nmalloc.h
	$(CC) $(CFLAGS) imm.c

immasm.o:	immasm.c defines.h debug.h imm.h op.h
	$(CC) $(CFLAGS) immasm.c

input.o:	input.c defines.h structs.h debug.h nmalloc.h buffer.h
	$(CC) $(CFLAGS) input.c

io.o:		io.c defines.h structs.h debug.h nmalloc.h buffer.h
	$(CC) $(SLOW) $(CFLAGS) io.c

labels.o:	labels.c defines.h debug.h labels.h structs.h code.h fix.h \
		exprfast.h
	$(CC) $(CFLAGS) labels.c

lexer.o:	lexer.c md_suck.c defines.h y.tab.h structs.h debug.h code.h \
		nmalloc.h code.h inputfst.h 
	$(CC) $(CFLAGS) lexer.c

lexpr.o:	lexpr.c expr.o defines.h
	$(CC) $(CFLAGS) lexpr.c

p_debug.o:	p_debug.c defines.h debug.h structs.h
	$(CC) $(CFLAGS) p_debug.c

lp_debug.o:	p_debug.o defines.h
	$(CC) $(CFLAGS) lp_debug.c

lib65.o:	lib65.c defines.h debug.h structs.h object.h lib.h nmalloc.h 
	$(CC) $(CFLAGS) lib65.c

libwork.o:	libwork.c defines.h debug.h code.h nmalloc.h structs.h	  \
		object.h lib.h
	$(CC) $(CFLAGS) libwork.c

link.o: 	link.c defines.h debug.h nmalloc.h labels.h structs.h \
		object.h seg.h imm.h process.h exprfast.h 
	$(CC) $(CFLAGS) link.c

link65.o:	link65.c defines.h structs.h debug.h nmalloc.h code.h 
	$(CC) $(CFLAGS) link65.c

lload.o:	lload.c defines.h debug.h nmalloc.h labels.h structs.h \
		object.h code.h lib.h 
	$(CC) $(CFLAGS) lload.c

dload.o:	dload.c load.o
	$(CC) $(CFLAGS) dload.c

load.o: 	load.c defines.h debug.h nmalloc.h structs.h object.h code.h 
	$(CC) $(CFLAGS) load.c

lreloc.o:	lreloc.c defines.h debug.h seg.h structs.h labels.h imm.h  \
		process.h 
	$(CC) $(CFLAGS) lreloc.c

lsymbols.o:	lsymbols.c symbols.o
	$(CC) $(CFLAGS) lsymbols.c

macro.o:	macro.c y.tab.h defines.h labels.h structs.h debug.h \
		nmalloc.h buffer.h inputfst.h code.h
	$(CC) $(CFLAGS) macro.c

ndebug.o:	ndebug.c y.tab.h defines.h structs.h
	$(CC) $(SLOW) $(CFLAGS) ndebug.c

object.o:	object.c defines.h labels.h structs.h seg.h object.h debug.h  \
		code.h imm.h 
	$(CC) $(SLOW) $(CFLAGS) object.c

ops.o:		ops.c defines.h ops.h
	$(CC) $(SLOW) $(CFLAGS) ops.c

process.o:	process.c defines.h structs.h labels.h seg.h op.h   \
		nmalloc.h object.h fix.h process.h code.h debug.h
	$(CC) $(CFLAGS) process.c

lsegment.o:	segment.o lsegment.c
	$(CC) $(CFLAGS) lsegment.c

segment.o:	segment.c defines.h debug.h nmalloc.h structs.h code.h seg.h
	$(CC) $(CFLAGS) segment.c

stats.o:	stats.c defines.h structs.h imm.h seg.h nmalloc.h
	$(CC) $(SLOW) $(CFLAGS) stats.c

sym_asm.o:	sym_asm.c defines.h debug.h labels.h structs.h exprfast.h 
	$(CC) $(CFLAGS) sym_asm.c

sym_link.o:	sym_link.c defines.h debug.h labels.h structs.h 
	$(CC) $(CFLAGS) sym_link.c

symbols.o:	symbols.c defines.h debug.h labels.h structs.h nmalloc.h 
	$(CC) $(CFLAGS) symbols.c

version0.o:	version0.c structs.h object.h defines.h
	$(CC) $(SLOW) $(CFLAGS) version0.c

worker.o:	worker.c defines.h debug.h nmalloc.h structs.h object.h \
		process.h 
	$(CC) $(CFLAGS) worker.c

asm65.c:	asm65.y
	yacc $(YFLAGS) asm65.y
	mv y.tab.c asm65.c

asm65.o:	asm65.c defines.h labels.h structs.h code.h buffer.h \
		exprfast.h op.h
	$(CC) $(CFLAGS) asm65.c

defines.h:	localdef.h
	touch defines.h

localdef.h:	portable$(EXT)
	portable$(EXT) x

