# config.mk sets make variables that describe the build environment and
# user build choices.  'configure' generates it.

default: hwclock

include config.mk

config.mk:
	perl configure

CC = gcc

## asm/io.h defines extern functions without a prototype, so 
## -Wmissing-declarations doesn't work on directio.c.

WARNINGS0 = -Wall -Wimplicit -Wwrite-strings \
	-W -Winline -Wundef \
	-Wstrict-prototypes -Wmissing-prototypes \

WARNINGS = $(WARNINGS0) -Wmissing-declarations 

CFLAGS_ALL = $(WARNINGS) -fno-common -O3 $(CFLAGS_PERSONAL) $(CFLAGS)

LDFLAGS_ALL = -Wl,-warn-common $(LDFLAGS)

hwclock: hwclock.o clock_functions.o clock_access.o rtc.o directio.o kd.o \
	 util.o utmp.o adjtime.o adjust.o shhopt.o
	$(CC) $(LDFLAGS_ALL) -o $@ $^

%.o:%.c
	$(CC) -c $(CFLAGS_ALL) -o $@ $<

directio.o: WARNINGS = $(WARNINGS0)

ifeq ($(IO_H_NAMESPACE), asm)
  HAVE_SYS_IO = 0
else
  HAVE_SYS_IO = 1
endif

config.h: config.mk
	rm -f $@
	@echo "Lots of echoes to '$@' suppressed here ..."
	@echo "/* Created by a make rule */" >>$@
	@echo >>$@
	@echo "#define HAVE_IO_H $(HAVE_IO_H)" >>$@
	@echo "#define HAVE_SYS_IO $(HAVE_SYS_IO)" >>$@

hwclock.o: shhopt.h util.h adjtime.h clock_functions.h clock_access.h \
	   rtc.h directio.h kd.h adjust.h hwclock.h

clock_functions.o: hwclock.h adjtime.h adjust.h directio.h clock_functions.h 

clock_access.o: directio.h rtc.h kd.h hwclock.h clock_access.h

rtc.o: util.h hwclock.h rtc.h

directio.o: util.h hwclock.h directio.h config.h

adjtime.o: util.h adjtime.h

adjust.o: util.h hwclock.h adjust.h

clock_access.o: clock_access.h directio.h rtc.h kd.h hwclock.h

clock_functions.o: clock_functions.h util.h hwclock.h adjtime.h \
  adjust.h directio.h utmp.h

directio.o: directio.h util.h hwclock.h

kd.o: kd.h hwclock.h util.h

rtc.o: rtc.h util.h hwclock.h

shhopt.o: util.h mallocvar.h shhopt.h

util.o: util.h hwclock.h

utmp.o: utmp.h hwclock.h

.PHONY: cleandist
distclean: clean
	rm --force config.mk

.PHONY: clean
clean:
	rm --force hwclock
	rm --force *.o *.a *.i *.s
	rm --force config.h
