include ./make.conf

CCL_VERSION=$(shell grep CCL_VERSION src/lib/settings.h | awk '{print substr($$3, 2, length($$3) - 2)}')

PACKAGE_NAME=Conviva_SDK_C_$(CCL_VERSION)
DOCS_NAME=Conviva_SDK_API_Docs_$(CCL_VERSION)
PACKAGE_PATH=build/
# Quoted globs so "cd build/; zip ..." does not expand *.obj etc. in the shell
PACKAGE_EXCUDES=--exclude='*~' --exclude='*.obj' --exclude='*.ilk' --exclude='*.idb' --exclude='*.pdb' --exclude='*.dll' --exclude='*.lib'
PACKAGE_FILES=sample src CHANGES make.conf make.win makefile README.md

DIRS = src
ifneq ($(wildcard ./test/.*),)
DIRS += test
endif
ifeq ($(UNAME), Linux)
DIRS += sample
endif


BUILDDIRS = $(DIRS:%=build-%)
DEBUGDIRS = $(DIRS:%=debug-%)
CLEANDIRS = $(DIRS:%=clean-%)

all: build

build: $(BUILDDIRS)
$(BUILDDIRS):
	$(MAKE) -C $(@:build-%=%) build

debug: $(DEBUGDIRS)
$(DEBUGDIRS):
	$(MAKE) -C $(@:debug-%=%) debug

clean: $(CLEANDIRS)
	rm -rf build

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

.PHONY: subdirs $(BUILDDIRS)
.PHONY: subdirs $(DEBUGDIRS)
.PHONY: subdirs $(CLEANDIRS)
.PHONY: docs docs_clean

samples: src

docs: src build/doxygen-config
	doxygen build/doxygen-config

build/doxygen-config: doxygen-config src/lib/settings.h
	mkdir -p build
	sed 's/@CCL_VERSION@/$(CCL_VERSION)/g' doxygen-config > $@

docs_clean:
	rm -rf build/docs

# Packaging (make package, package-internal, package_docs) lives in make.package.mk
-include make.package.mk
