
SUBDIRS = serial parallel i2c spi usbtmc tcp tcpclient tcpserver udp udpport gpib vxi11 resolvehost hwinfo serialport modbus

MKOCTFILE ?= mkoctfile
GREP ?= grep

.PHONY: clean
.PHONY: realclean
.PHONY: distclean
.PHONY: $(SUBDIRS)
.PHONY: make-pkg-add_file

all: $(SUBDIRS) make-pkg-add-file.cc

$(SUBDIRS):
	$(MAKE) -C $@

# pkg install doesnt look in subdirs of src to make pkgadd/del so we 
# make a source file that it will see
CC_SOURCES = $(wildcard */*.cc)
make-pkg-add-file.cc: $(CC_SOURCES)
	@echo "Generating pkg add/del $@ ..."
	@(      echo "// Generated file for PKG_ADD/DEL inclusion"; \
	        $(GREP) -h '// PKG_' $^) > "$@"


CLEANDIRS = $(SUBDIRS:%=clean-%)
DISTCLEANDIRS = $(SUBDIRS:%=distclean-%)

.PHONY: $(CLEANDIRS)
.PHONY: $(DISTCLEANDIRS)

$(CLEANDIRS):
	$(MAKE) -C $(@:clean-%=%) clean
	
$(DISTCLEANDIRS):
	$(MAKE) -C $(@:distclean-%=%) distclean

clean: $(CLEANDIRS)

realclean:
	-rm -f *.oct
	-rm -f make-pkg-add-file.cc

distclean: realclean $(DISTCLEANDIRS)
	-rm -rf autom4te.cache
	-rm -f common.mk oct-alt-includes.h
	-rm -f Makefile config.status config.log config.h

maintainer-clean: distclean
	-rm -f configure

# and prebuild stuff we need do
prebuild:
	$(MAKE) -C vxi11 prebuild

