#
# Makefile for modm0dev; see "COPYING" for distribution conditions.
#

CC	= gcc
CFLAGS	= -mshort -Wall -I. $(DEFINES) $(OPTIM)
DEFINES	=
OPTIM	= -O2 -fomit-frame-pointer

DRIVER	= modm0dev.ttp
DRIVER2	= modm0dev.syslog
STTY	= stty.ttp
FMANP	= modm0dev.asc

OBJ1	= modm0dev.o  modm0asm.o
OBJ2	= modm0dev.o2 modm0asm.o syslog.o
BINS	= $(DRIVER) $(DRIVER2) $(STTY)

ARCHDIR = /h/Archives

SOURCES	= atarierr.h filesys.h		\
    modm0dev.h modm0dev.c modm0asm.s	\
    syslog.h syslog.c			\
    stty.c Makefile COPYING modm0dev.8 LISEZ.MOI

#
# The default is to build the two drivers, stty, and the manpage.
#

all: $(BINS) $(FMANP)

clean:
	rm -f *.o* *.bak $(BINS) $(FMANP)

#
# Archiving
#

archive: $(BINS) $(FMANP)
	zoo aunhP: modm0dev.zoo $(SOURCES) $(BINS) $(FMANP)
	cp -p modm0dev.zoo $(ARCHDIR)

#
# The device driver (normal version and syslog version)
#

$(DRIVER): $(OBJ1)
	$(CC) -mshort -s $(OBJ1) -o $(DRIVER)
	toglclr -fload -super $(DRIVER)
	chmod +x $(DRIVER)

$(DRIVER2): $(OBJ2)
	$(CC) -mshort -s $(OBJ2) -o $(DRIVER2) -liio16
	toglclr -fload -super $(DRIVER2)
	chmod +x $(DRIVER2)

modm0asm.o: modm0asm.s
	$(CC) -c modm0asm.s

modm0dev.o2: modm0dev.c atarierr.h filesys.h modm0dev.h syslog.h
	$(CC) $(CFLAGS) -DUSE_SYSLOG -c modm0dev.c -o modm0dev.o2

modm0dev.o: modm0dev.c atarierr.h filesys.h modm0dev.h
syslog.o: syslog.c syslog.h

#
# A slightly enhanced stty
#

$(STTY): stty.c
	$(CC) -O stty.c -s -o $(STTY) -liio
	toglclr -fload $(STTY)
	chmod +x $(STTY)

#
# The manpage
#

$(FMANP): modm0dev.8
	cawf -man -fn modm0dev.8 > $(FMANP)

