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_after_weave

weave: step2

# Separate *_after_weave targets needed for enforcing a correct step2<-step3
# dependency in a *complete* build, but allowing for a detached compile/step3
# build for users who know what they are doing.
compile_after_weave: step3_after_weave
compile: step3

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

config:
ifneq ($(ASPECTS),)
	@echo "Generating ac++ config file..."
	@mkdir -p $(dir $(CONFIG))
	@$(AGXX) --gen_config --c_compiler $(CXX) -o $(CONFIG)
	@perl -i -pe "s/^-I [\"]?\.[\"]?$$//g" $(CONFIG) 
endif

step1: config dirs
	@+$(MAKE) -f generate.mk

step2: step1
	@+$(MAKE) -f weave.mk

step3_after_weave: dirs step2
	@+$(MAKE) -f compile.mk
step3: dirs
	@+$(MAKE) -f compile.mk

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
