#
# Copyright (C) 2005 Stefan Seefeld
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#

SHELL	:= /bin/sh

srcdir	:= @srcdir@
builddir:= @builddir@

CXX	:= @CXX@
MAKEDEP	:= $(CXX) -M
CPPFLAGS:= @CPPFLAGS@
CPPFLAGS+= -I $(builddir)/../../src/ -I $(srcdir)/../../src/ 
CXXFLAGS:= @CXXFLAGS@
LDFLAGS	:= @LDFLAGS@
LIBS	:= -L$(builddir)/../../src/lib -lSynopsis @LIBS@

TESTS	:= Lexer Encoding Parser ConstEvaluator SymbolLookup TypeAnalysis

SRC 	:= $(patsubst %, src/%.cc, $(TESTS))
OBJ	:= $(patsubst %.cc, %.o, $(SRC))
DEP	:= $(patsubst %.cc, %.d, $(SRC))

TARGETS	:= $(patsubst src/%.cc, bin/%, $(SRC))

vpath %.cc $(srcdir)

all: $(TARGETS)

$(TESTS): %: bin/%

$(TARGETS): bin/%: src/%.o
	$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)

%.d: %.cc
	@echo generating dependencies for $(@D)/$(<F)
	$(SHELL) -ec '$(MAKEDEP) $(CPPFLAGS) $< | sed "s,$(*F)\\.o[ :]*,$*\\.d $*\\.o : ,g" > $@'

%.o: %.cc
	@echo compiling $(@D)/$(@F)
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<

Makefile: $(srcdir)/Makefile.in
	(cd .. && ./config.status --file OpenCxx/Makefile)

clean :
	rm -f bin/* src/*.o src/*.d

ifeq (,$(filter $(MAKECMDGOALS), depend clean distclean))
-include $(DEP)
endif
