include Makefile.inc

SUBDIR=include lib config
DESCRIPTOR=$(PROJ_NAME).pc

.PHONY: all clean install remoteinstall $(SUBDIR)

all: $(SUBDIR)

$(PROJ_NAME).pc: $(PROJ_NAME).pc.in Makefile.inc
	-rm -f $@
	@sed $< \
		-e "s%@PROJ_NAME@%$(PROJ_NAME)%g" \
		-e "s%@SHLIB_MAJOR@%$(SHLIB_MAJOR)%g" \
		-e "s%@SHLIB_MINOR@%$(SHLIB_MINOR)%g" \
		-e "s%@DESCRIPTION@%$(DESCRIPTION)%g" \
		-e "s%@LIBNAME@%$(LIBNAME)%g" \
		-e "s%@REQUIRES@%$(REQUIRES)%g" \
		-e "s%@prefix@%$(prefix)%g" \
		-e "s%@exec_prefix@%$(exec_prefix)%g" \
		> $@

$(SUBDIR):
	@echo "===>" $@
	$(MAKE) -C $@ $(MAKECMDGOALS)
	@echo "<===" $@

install: $(SUBDIR) $(DESCRIPTOR)
	@[ -d $(INSTALLDIR)/$(pkgconfigdir) ] || install -d $(INSTALLDIR)/$(pkgconfigdir)
	@set -e ;\
	for i in $(DESCRIPTOR); do\
		install -c -m 644 $$i $(INSTALLDIR)/$(pkgconfigdir); \
	done

remoteinstall: $(SUBDIR)

clean: $(SUBDIR)
	-rm -f $(DESCRIPTOR)
