include buildconf.mk

# Fast default: libraries, vdevd, fs, example — no hwdb regeneration (can take minutes).
# Full tree including hwdb: `make all`. If hwdb/hwdb.squashfs exists, it is copied into
# $(BUILD) (fast). Otherwise the database is regenerated from *.hwdb (slow; packaging).

.PHONY: build all install uninstall clean
build:
	$(MAKE) -C libvdev PREFIX=
	$(MAKE) -C vdevd PREFIX=
	$(MAKE) -C fs PREFIX=
	$(MAKE) -C example PREFIX=
	$(MAKE) -C tools/vdevadm PREFIX=

all: build
	@if [ -f hwdb/hwdb.squashfs ]; then $(MAKE) -C hwdb PREFIX=; \
	else $(MAKE) -C hwdb all-full PREFIX=; fi

# Pass DESTDIR/PREFIX explicitly — recursive makes do not inherit dh's DESTDIR=debian/tmp.
install:
	$(MAKE) -C vdevd install PREFIX=
	$(MAKE) -C fs install PREFIX=
	$(MAKE) -C hwdb install PREFIX=
	$(MAKE) -C example install PREFIX=
	$(MAKE) -C tools/vdevadm install PREFIX=

	# Installing documentation
	mkdir -p $(DESTDIR)/usr/share/doc
	mkdir -p $(DESTDIR)/usr/share/man
	mkdir -p $(DESTDIR)/usr/share/man/man8
	cp -r share/doc/ $(DESTDIR)/usr/share/doc
	cp -r share/man/man8/ $(DESTDIR)/usr/share/man/man8

uninstall:
	$(MAKE) -C vdevd uninstall
	$(MAKE) -C fs uninstall
	$(MAKE) -C example uninstall
	$(MAKE) -C hwdb uninstall
	$(MAKE) -C tools/vdevadm uninstall

	# Uninstalling documentation
	rm -rf $(DESTDIR)/usr/share/doc/vdevd
	rm -rf $(DESTDIR)/usr/share/man/man8/vdevd.8.gz
	rm -rf $(DESTDIR)/usr/share/man/man8/vdevd-actions.8.gz

clean:
	$(MAKE) -C $(UNIJSON_ROOT) clean
	rm -rf $(BUILD)
	# Clean JSON examples build directories
	rm -rf $(UNIJSON_ROOT)/examples/simple/build
	rm -rf $(UNIJSON_ROOT)/examples/nested/build


