#
#if this file gets include, SUBDIR must be defined
#
SHELL=@SHELL@

CC=@CC@
LD=@LD@
CFLAGS=@CFLAGS@ -I..
OBJEXT=@OBJEXT@

ifeq '$(SOURCES)' ''
SOURCES=$(wildcard *.c)
endif
HEADERS=$(wildcard *.h)
OBJECTS=$(patsubst  %.c, %.$(OBJEXT), $(SOURCES))

.PHONY: all
all: ../$(SUBDIR).$(OBJEXT)

../$(SUBDIR).$(OBJEXT): $(OBJECTS)
	$(LD) -r -o $@ $(OBJECTS)

#GNU make will automatically call the rule for the include
#It will print a non-fatal error message, though but do not
#worry about it.
#If your make cannot do this and you cannot use GNU make,
#change this from 'include' to 'sinclude' and run
# make depend
#before compiling.
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
include .dependencies
endif
endif

.PHONY: depend
depend:
	$(CC) $(CFLAGS) -MM $(SOURCES) >.dependencies

.dependencies: $(SOURCES) $(HEADERS)
	$(CC) $(CFLAGS) -MM $(SOURCES) >$@

.PHONY: clean
clean:
	-rm -f *.$(OBJEXT) ../$(SUBDIR).$(OBJEXT)

.PHONY: dist-clean
distclean: clean
	-rm -f .dependencies
