# If you want to use a copy of the shhopt option processing library already
# on your system, delete the shhopt.h file from the
# hwclock source directory and modify the following variables if shhopt
# is not in your default include and link search paths.  Leave everything
# as-is to use the copy of shhopt shipped with hwclock.
SHHOPT_LINK_PATH = .
SHHOPT_HEADER_PATH = .
SHHOPT_DEPENDENCY = libshhopt.a
# To use existing system copy of shhopt library:
#SHHOPT_LINK_PATH = 
#SHHOPT_HEADER_PATH = 
#SHHOPT_DEPENDENCY = 

CC = gcc

CFLAGS = -Wall -Wwrite-strings -Wstrict-prototypes -Winline \
	 -Wno-uninitialized -Wmissing-declarations \
	 -O6 -I$(SHHOPT_HEADER_PATH) $(CADD)

LDFLAGS+= -Wl,-warn-common 

hwclock: hwclock.o clock_functions.o clock_access.o rtc.o directio.o kd.o \
	 util.o utmp.o adjtime.o adjust.o \
            $(SHHOPT_DEPENDENCY)
	$(CC) $(LDFLAGS) -o $@ $^ -L$(SHHOPT_LINK_PATH) -lshhopt

hwclock.o: hwclock.c hwclock.h adjtime.h util.h directio.h clock_access.h \
	   adjust.h clock_functions.h

clock_functions.o: clock_functions.h hwclock.h adjtime.h

clock_access.o: clock_access.c hwclock.h directio.h util.h

rtc.o: rtc.c hwclock.h

# asm/io.h defines extern functions without a prototype, so 
# -Wmissing-declarations doesn't work on directio.c.
directio.o: directio.c directio.h hwclock.h
	$(CC) -c directio.c \
	  -Wall -Wwrite-strings -Wstrict-prototypes -Winline \
	  -Wno-uninitialized \
	  -O6 $(CADD)

kd.o: kd.c hwclock.h

util.o: util.c util.h hwclock.h

utmp.o: utmp.c hwclock.h

adjtime.o: adjtime.h util.h

adjust.o: adjust.h hwclock.h

#Note that we build libshhopt for convenience here.  It would be more
#appropriate to use a copy of the library already installed (e.g. in 
#/usr/lib).  The authoritative libshhopt comes from:
#  (ftp://sunsite.unc.edu/pub/Linux/libs/shhopt-X.Y).

libshhopt.a: shhopt.o
	ar rc libshhopt.a shhopt.o
	ranlib libshhopt.a || true

shhopt.o: shhopt.c
	$(CC) -c -s -Wall -O2 -I. shhopt.c -o shhopt.o

# clean removes everything that can be rebuilt, including pre-built files
# that are shipped with the package.
clean: cleandist
	rm --force hwclock

# cleandist is for cleaning up prior to packaging for distribution.
cleandist: 
	rm --force *.o *.a *.i *.s