#-------------------------------------------------
# variables 
#-------------------------------------------------

include files.mk

ROOT    ?= $(shell pwd)
TARGET  ?= linux-release
AC      ?= ac++
PREFIX  ?= /usr/local 

include vars.mk

LIBDIR  := $(ROOT)/lib/$(TARGET)
GENDIR  := $(ROOT)/gen-$(RELEASE)

INCDIR  := $(ROOT)/include
OBJDIR  := $(GENDIR)/obj-$(_TARGET)
STEP1   := $(GENDIR)/step1
STEP2   := $(GENDIR)/step2

CONFIG  := $(GENDIR)/puma.cfg

# exported variables
export GENDIR INCDIR LIBDIR OBJDIR STEP1 STEP2
export ROOT TARGET AC DONTWEAVE CONFIG
export ORASOURCES LEMSOURCES SOURCES ASPECTS 

# suppress reporting directory changes
MAKE := $(MAKE) --no-print-directory

#-------------------------------------------------
# rules
#-------------------------------------------------

all: showinfo src

weave: showinfo src

compile: showinfo src

showinfo:
	@echo 
	@echo "---"
	@echo "Making PUMA for TARGET=$(TARGET)"
	@echo "---"
	@echo 

tools:
	@echo "Making tools..."
	@cd $(ROOT)/tools && $(MAKE)

src: tools
	@echo "Making library..."
	@cd $(ROOT)/src && $(MAKE) $(MAKECMDGOALS)

examples: src
	@echo "Making examples..."
	@cd $(ROOT)/examples && $(MAKE)

doxygen:
	@echo "Making Puma documentation with doxygen..."
	@doxygen doc/doxygen.conf && echo "=> see doc/doxygen/html/index.html"

install: config src
	@echo "Installing library and headers..."
	@cp -pv $(CONFIG) /etc/puma.config
	@cp -pv $(LIBDIR)/libPuma.* $(PREFIX)/lib
	@mkdir -p $(PREFIX)/include/Puma
	@cp -pv $(INCDIR)/Puma/*.*h $(PREFIX)/include/Puma

uninstall: 
	@echo "Uninstalling library and headers..."
	@rm -fv /etc/puma.config
	@rm -fv $(PREFIX)/lib/libPuma.*
	@rm -rfv $(PREFIX)/include/Puma

clean: tools-clean
	@cd $(ROOT)/src && $(MAKE) clean

tools-clean:
	@echo "Making tools clean..."
	@cd $(ROOT)/tools && $(MAKE) -s clean

examples-clean:
	@echo "Making examples clean..."
	@cd $(ROOT)/examples && $(MAKE) -s clean

cleanall: distclean

distclean: clean examples-clean
	@cd $(ROOT)/src && $(MAKE) distclean

libclean:
	@echo "Removing library and object files..."
	@rm -f $(LIBDIR)/libPuma.*
	@rm -rf $(OBJDIR)
	@rm -rf $(STEP2)/dep

#-------------------------------------------------
# targets
#-------------------------------------------------

.PHONY: all tools src install examples distclean cleanall \
clean tools-clean examples-clean libclean weave compile uninstall
