SRC=	machine.c FibreRead.c FibrePrint.c globals.c bag.c alloc.c\
	garbage.c copy.c hooks.c files.c error.c mult.c\
	main.c options.c table.c nop.c init.c exec.c graph.c\
	environment.c ops.c  if.c call.c array.c record.c work.c\
	union.c iter.c forall.c generate.c gather.c reduce.c literal.c\
	util.c signal.c system.c notdone.c loopaorb.c value.c
OBJ=	machine.o FibreRead.o FibrePrint.o globals.o bag.o alloc.o\
	garbage.o copy.o hooks.o files.o error.o mult.o\
	main.o options.o table.o nop.o init.o exec.o graph.o\
	environment.o ops.o if.o call.o array.o record.o work.o\
	union.o iter.o forall.o generate.o gather.o reduce.o literal.o\
	util.o signal.o system.o notdone.o loopaorb.o value.o
GOBJ=	machine.g FibreRead.g FibrePrint.g globals.g bag.g alloc.g\
	garbage.g copy.g hooks.g files.g error.g mult.g\
	main.g options.g table.g nop.g init.g exec.g graph.g\
	environment.g ops.g if.g call.g array.g record.g work.g\
	union.g iter.g forall.g generate.g gather.g reduce.g literal.g\
	util.g signal.g system.g notdone.g loopaorb.g value.g

MSRC=	makeoptable.c
MOBJ=	makeoptable.o

OTHER= table.des $(MSRC) t.out.1

FILES= Makefile $(SRC) $(OTHER)

FLAGS= -D$(MACHINE) -D$(OS)
CC=cc
CFLAGS= -I../INCLUDES $(FLAGS)
LFLAGS= -I../INCLUDES $(FLAGS) -lm

.SUFFIXES:
.SUFFIXES: .c .o .g
.c.o:
	$(CC) $(OPTFLAGS) $(CFLAGS) -c $<
.c.g:
	 $(CC) -g $(CFLAGS) -DDebugger -DPACKAGES -c $< -o ?$*.o ; mv ?$*.o $*.g

LIB=libtwine.a

#------------------------------------------------------------
all: libtwine.a libGtwine.a libOtwine.a 

#------------------------------------------------------------
# Make the loader library
$(LIB): $(OBJ) asm.o
	/bin/rm -f $(LIB)
	ar r $(LIB) $(OBJ) asm.o
	-ranlib $(LIB)

# ------------------------------------------------------------
makeoptable: $(MOBJ)
	$(CC) -o makeoptable $(MOBJ)

table.c: table.des makeoptable
	makeoptable "Op" "" "NotDone" < table.des > table.c

#------------------------------------------------------------
libGtwine.a: $(GOBJ) asm.o
	/bin/rm -f libGtwine.a
	ar r libGtwine.a $(GOBJ) asm.o
	-ranlib libGtwine.a


# ------------------------------------------------------------
libOtwine.a: monolith.o asm.o
	/bin/rm -f libOtwine.a
	ar r libOtwine.a monolith.o asm.o
	-ranlib libOtwine.a

monolith.o: monolith.c
	$(CC) -O $(CFLAGS) -DMONOLITH -c monolith.c

monolith.c: $(SRC)
	cat $(SRC) > monolith.c

# ------------------------------------------------------------
asm.o: asm.s
	$(CC) -c asm.s

asm.s: machine.c
	-@if ( cc -E -I../INCLUDES -D$(MACHINE) -D$(OS) -Dasm machine.c | \
	grep NoAsm > /dev/null) then\
	  echo '#define ASM(x) x' > asm.ts; \
	  cc -E -I../INCLUDES -D$(MACHINE) -Dasm=ASM machine.c | \
	    egrep ASM >> asm.ts; \
	  /lib/cpp asm.ts | egrep -v "^#" | sed 's/"//;s/"$$//' > asm.s; \
	elif ( test "$(OS)" = "SYSV" ) then \
	  echo '/* No assembly code needed */' > asm.s; \
	  echo '	.ent	DUMMY 0' >> asm.s; \
	  echo 'DUMMY:' >> asm.s; \
	  echo '	.end	DUMMY' >> asm.s; \
        else \
          echo '' > asm.s; \
	fi
# ------------------------------------------------------------
lint: $(SRC)
	@lint $(LFLAGS) $(SRC) \
		../DEFAULT/llib-ltwinedef.ln ../TBUG/llib-ltbug.ln  \
		| egrep -v "conversion of function pointer" > lint.out

clean:
	-@ls $(FILES) > KeepList
	-@/bin/rm `ls | fgrep -v -x -f KeepList`

install:
	-@if ( test "$(REL)" != "" ) then \
	cp libtwine.a $(REL)/lib; \
	if ( test -x /usr/bin/ranlib ) then ranlib $(REL)/lib/libtwine.a; fi;\
	cp libOtwine.a $(REL)/lib; \
	if ( test -x /usr/bin/ranlib ) then ranlib $(REL)/lib/libOtwine.a; fi;\
	cp libGtwine.a $(REL)/lib; \
	if ( test -x /usr/bin/ranlib ) then ranlib $(REL)/lib/libGtwine.a; fi;\
	chmod 777 $(REL)/lib/*.a; \
        cp t.out.1 $(REL)/man; \
	chmod 777 $(REL)/man/t.out.1; \
	else echo No release directory; fi
#
