#
# Copyright (C) 2003 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@

PYTHON	:= @PYTHON@
SYNOPSIS:= $(PYTHON) synopsis.py

CXX	:= @CXX@
LDSHARED:= @LDSHARED@
MAKEDEP	:= $(CXX) -M
CPPFLAGS:= @CPPFLAGS@ -I $(srcdir)
CPPFLAGS+= @SYN_CPP@ -I @PYTHON_INCLUDE@
CXXFLAGS:= @CXXFLAGS@
LDFLAGS	:= @LDFLAGS@
LIBS	:= @SYN_LIBS@ @LIBS@
LIBRARY_EXT := @LIBEXT@

TARGET	:= ParserImpl$(LIBRARY_EXT)

SRC := ASG.cc Types.cc Walker.cc Builder.cc Dictionary.cc TypeIdFormatter.cc \
       Decoder.cc Lookup.cc Filter.cc Translator.cc SXRGenerator.cc ParserImpl.cc
HDR := $(patsubst $(srcdir)/%, %, $(wildcard $(srcdir)/*.hh))
OBJ	:= $(patsubst %.cc, %.o, $(SRC))
DEP	:= $(patsubst %.cc, %.d, $(SRC))

vpath %.cc $(srcdir)
vpath %.c $(srcdir)
vpath %.h $(srcdir)
vpath %.hh $(srcdir)

all: $(TARGET)

doc:

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

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

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

$(TARGET): $(OBJ)
	$(LDSHARED) $(LDFLAGS) -o $@ $^ $(LIBS)

clean :
	rm -f *~ *.o *.d *.dll *.so *core *.pyc *.pyo base_lib

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