CC=@CC@
INSTALL=@INSTALL@

SOURCES=nvclock.c
SUBDIRS=backend nvcontrol gtk qt
HAVE_NVCONTROL=@HAVE_NVCONTROL@
libbackend=./backend/libbackend.a
libnvcontrol=./nvcontrol/libnvcontrol.a

prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@

ifeq ($(HAVE_NVCONTROL), yes)
    DEPS=$(libbackend) $(libnvcontrol)
    INCLUDES=@X11_CFLAGS@ -I./backend -I./nvcontrol -I..
    LIBS=@X11_LIBS@ -L./backend -lbackend -L./nvcontrol -lnvcontrol
else
    DEPS=$(libbackend)
    INCLUDES=-I./backend -I./nvcontrol -I..
    LIBS=-L./backend -lbackend
endif


.PHONY: all-recursive clean clean-app clean-recursive \
	distclean install install-app install-recursive


all: all-recursive nvclock


nvclock: $(DEPS) $(LIB) nvclock.c
	$(CC) -o nvclock $(SOURCES) $(INCLUDES) $(LIBS)


clean: clean-recursive clean-app
clean-app:
	rm -f nvclock *.exe


distclean: distclean-recursive clean-app
	rm -f Makefile


install: install-recursive install-app
install-app:
	mkdir -p $(bindir)
	$(INSTALL) -c nvclock $(bindir)/nvclock


uninstall: uninstall-recursive uninstall-app
uninstall-app:
	rm -f $(bindir)/nvclock


# Walk through the sub directories and do what is requested
all-recursive clean-recursive distclean-recursive install-recursive uninstall-recursive:
	@set fnord; target=`echo $@ | sed s/-recursive//`; \
	list='$(SUBDIRS)'; for subdir in $$list; do \
	    $(MAKE) -C $$subdir $$target ; \
	done;

