ifeq ($(MAKELEVEL),0)
$(error Sorry, this makefile is not intended to be \
used directly. Please use the makefile in the toplevel \
directory of the PUMA source tree instead)
endif

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

AGXX    ?= $(subst ac++,ag++,$(AC))

include $(ROOT)/vars.mk

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

all: weave compile

weave: dirs config step1 step2

compile: dirs step3

dirs:
	@mkdir -p $(OBJDIR)
	@mkdir -p $(INCDIR)
	@mkdir -p $(STEP1)/src
	@mkdir -p $(STEP1)/dep
	@mkdir -p $(STEP1)/aspects
	@mkdir -p $(STEP1)/inc/Puma
	@mkdir -p $(STEP2)/src
	@mkdir -p $(STEP2)/dep
	@mkdir -p $(STEP2)/inc/Puma

config:
	@echo "Creating config file..."
	@mkdir -p $(dir $(CONFIG))
	@$(AGXX) --gen_config --c_compiler $(CXX) -o $(CONFIG)

step1: 
	@echo "Generating..."
	@$(MAKE) -f generate.mk

step2: 
	@echo "Weaving..."
	@$(MAKE) -f weave.mk -j $(MINUSJ)

step3: 
	@echo "Compiling..."
	@$(MAKE) -f compile.mk -j $(MINUSJ)

clean:
	@echo "Making sources clean..."
	@rm -rf $(GENDIR)

distclean: 
	@echo "Removing library, headers, and other generated files..."
	@rm -rf $(LIBDIR) $(INCDIR) $(ROOT)/gen-*

install:
	# nothing to do for install

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

.PHONY: all clean dirs weave compile
