PROGRAM=	gizmontp
#
# makefile for gizmontp - an NTP server for the gizmo board
#
COMPILER= cc
COPTS= -O
BINDIR=	/usr/local
INSTALL=install
DEFS=
DEFS_LOCAL=
#
# This can be compiled with gcc.  If so, change the CC= line and
# make sure -DNO_SIGNED_CHAR_DECL isn't declared in the GIZMODEFS line
#
#
#
CC=	cc
GIZMODEFS= -DGIZMO -DNODETACH -DNOKMEM -DADJTIME_IS_ACCURATE \
	   -DREFCLOCK -DNO_SIGNED_CHAR_DECL

#
# Clock driver definitions.  One or more of -DLOCAL, -DCHU, -DPST
#
REFFLAGS= $(GIZMODEFS) -DLOCAL -DCHU

#
# CCFLAGS are what is needed to compile for a 68000 with no floating point
# LDFLAGS are what is needed to compile the program text starting at 0x20000
# CFFLAGS are used to compile the configuration program (gizconf).  This
#	is compiled on the host computer.
#
CCFLAGS=	-m68010 -fsoft -O
LDFLAGS=	-Ttext 20000

#
# Where the gizmo monitor source is to be found
#
GIZMOMON=	../../gizmo

#
NTPLIB=		../lib/libntp.a
#
STDINCL=	-I../include
GIZINCL=	-I./include -I.
INCL=		$(STDINCL) $(GIZINCL)
CFLAGS=		$(CCFLAGS) $(GIZMODEFS) $(INCL)
LIBFLAGS=	$(CCFLAGS) -DBIG_ENDIAN $(INCL)
LIB=		libgizmontp.a
LINTLIB=	llib-llibgizmontp.ln
CLIB=		$(GIZMOMON)/dmon/libc10.a
MAKE=		make
LIBNTP=		../lib/libntp.a
#
SOURCE=	../xntpd/ntp_control.c ../xntpd/ntp_io.c \
	../xntpd/ntp_leap.c ../xntpd/ntp_loopfilter.c \
	../xntpd/ntp_monitor.c ../xntpd/ntp_peer.c \
	../xntpd/ntp_proto.c ../xntpd/ntp_refclock.c \
	../xntpd/ntp_request.c ../xntpd/ntp_restrict.c \
	../xntpd/ntp_timer.c ../xntpd/ntp_unixclock.c \
	../xntpd/ntpd.c ../xntpd/refclock_chu.c \
	../xntpd/refclock_local.c gizclock_conf.c \
	gizmo_conf_data.c gizmo_config.c gizmo_syslog.c \
	gizmo_util.c gizconf.c

OBJS=	gizclock_conf.o gizmo_conf_data.o gizmo_config.o gizmo_syslog.o \
	gizmo_util.o ntp_control.o ntp_io.o ntp_leap.o ntp_loopfilter.o \
	ntp_monitor.o ntp_peer.o ntp_proto.o ntp_refclock.o ntp_request.o \
	ntp_restrict.o ntp_timer.o ntp_unixclock.o ntpd.o refclock_chu.o \
	refclock_local.o

COBJS=	gizconf.o

all:	$(PROGRAM) gizconf

$(PROGRAM): $(LIB) $(OBJS) version.o
	$(CC) $(CCFLAGS) $(LDFLAGS) -o $@ $(OBJS) version.o $(LIB) $(CLIB)

gizconf: $(COBJS) $(LIBNTP)
	$(CC) $(COPTS) -o $@ $(COBJS) $(LIBNTP)

install:	$(PROGRAM) gizconf
	$(INSTALL) -c -m 0755 $(PROGRAM) $(CONFDIR)
	$(INSTALL) -c -m 0755 gizconf $(CONFDIR)

tags:
	ctags *.c *.h

depend:
	mkdep $(CFLAGS) $(SOURCE) $(LIBSRC)

clean:
	rm -f $(PROGRAM) gizconf $(LIB) $(LINTLIB) *.o *.out
	rm -f tags make.log Makefile.bak include/*.h lint.errs

distclean:	clean
	rm -f *.orig *.rej Makefile

links:
	ln -s $(GIZMOMON)/tcpip/h ./include/sys
	ln -s $(GIZMOMON)/tcpip/netinet ./include/netinet
	ln -s $(GIZMOMON)/tcpip/net ./include/net
	ln -s $(GIZMOMON)/tcpip/machine ./include/machine

lint:	$(LINTLIB)
	lint $(DEFS) $(DEFS_LOCAL) $(INCL) $(LINTLIB) $(SOURCE)

$(LIB):
	$(MAKE) -f Makefile.lib $(MFLAGS)

$(LINTLIB):
	$(MAKE) -f Makefile.lib $(MFLAGS) $(LINTLIB)

#
# Explicit make rule for the configuration program
#
gizconf.o:	gizconf.c
	$(COMPILER) $(COPTS) $(DEFS) $(DEFS_LOCAL) $(STDINCL) -c gizconf.c

#
# Explicit make rules for everything compiled from the xntpd directory
#

ntp_control.o: ../xntpd/ntp_control.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_control.c

ntp_io.o: ../xntpd/ntp_io.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_io.c

ntp_leap.o: ../xntpd/ntp_leap.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_leap.c

ntp_loopfilter.o: ../xntpd/ntp_loopfilter.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_loopfilter.c

ntp_monitor.o:	../xntpd/ntp_monitor.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_monitor.c

ntp_peer.o:	../xntpd/ntp_peer.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_peer.c

ntp_proto.o:	../xntpd/ntp_proto.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_proto.c

ntp_refclock.o:	../xntpd/ntp_refclock.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_refclock.c

ntp_request.o:	../xntpd/ntp_request.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_request.c

ntp_restrict.o:	../xntpd/ntp_restrict.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_restrict.c

ntp_timer.o:	../xntpd/ntp_timer.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_timer.c

ntp_unixclock.o:	../xntpd/ntp_unixclock.c
	$(CC) $(CFLAGS) -c ../xntpd/ntp_unixclock.c

ntpd.o:	../xntpd/ntpd.c
	$(CC) $(CFLAGS) -c ../xntpd/ntpd.c

#
# These guys require knowledge of our clock configuration
#
gizclock_conf.o:	gizclock_conf.c
	$(CC) $(COPTS) $(REFFLAGS) $(INCL) -c gizclock_conf.c

refclock_chu.o:		../xntpd/refclock_chu.c
	$(CC) $(COPTS) $(REFFLAGS) $(INCL) -c ../xntpd/refclock_chu.c

refclock_local.o:	../xntpd/refclock_local.c
	$(CC) $(COPTS) $(REFFLAGS) $(INCL) -c ../xntpd/refclock_local.c
