#!/usr/bin/make -f
STAMPDIR=tgz2build/stamps
STAGINGDIR=tgz2build/staging

# needed, otherwise whenr ran from a command line(zbs login), make install rm -rf's /...
ZBS_STAGE_DIR=$(STAMPDIR)
BUILDCMD=./balabit-unix-build

all: binary

binary: $(STAMPDIR)/stamp-setup $(STAMPDIR)/stamp-configure $(STAMPDIR)/stamp-build $(STAMPDIR)/stamp-install

setup: $(STAMPDIR)/stamp-setup
$(STAMPDIR)/stamp-setup:
	mkdir $(STAMPDIR) || true
	chmod +x $(BUILDCMD)
	touch $@

configure: $(STAMPDIR)/stamp-configure
$(STAMPDIR)/stamp-configure: $(STAMPDIR)/stamp-setup
	$(BUILDCMD) configure --prefix=$(ZBS_PREFIX)
	touch $@

build: $(STAMPDIR)/stamp-build
$(STAMPDIR)/stamp-build: $(STAMPDIR)/stamp-configure
	$(BUILDCMD) make
	touch $@

install:  $(STAMPDIR)/stamp-install
$(STAMPDIR)/stamp-install: $(STAMPDIR)/stamp-build
	rm -rf $(ZBS_STAGE_DIR)/
	$(BUILDCMD) make install DESTDIR=$(ZBS_STAGE_DIR)/ ECHO=echo
	touch $@

clean:
	-$(BUILDCMD) make clean
	rm -rf $(STAMPDIR) || true
	rm -rf $(STAGINGDIR) || true
