#
# 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@

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

CC	:= @CC@
CXX	:= @CXX@
LDSHARED:= @LDSHARED@
MAKEDEP	:= $(CXX) -M
CPPFLAGS:= @CPPFLAGS@ -I $(srcdir)
CPPFLAGS+= @SYN_CPP@ -I/usr/local/include -I @PYTHON_INCLUDE@
CFLAGS	:= @CFLAGS@
CXXFLAGS:= @CXXFLAGS@
LDFLAGS	:= @LDFLAGS@
LIBS	:= @SYN_LIBS@ @LIBS@
LIBRARY_EXT := @LIBEXT@

HDR	:= $(patsubst $(srcdir)/%, %, $(wildcard $(srcdir)/*.h))
SRC	:= mem.c nhash.c assert.c macro.c eval.c lexer.c cpp.c 
SRC	+= comments.cc ucpp.cc ParserImpl.cc
OBJ	:= $(patsubst %, %.o, $(basename $(SRC)))
DEP	:= $(patsubst %.o, %.d, $(OBJ))

TARGET	:= ParserImpl$(LIBRARY_EXT)

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

all: $(TARGET)

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

%.d: %.c
	@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 $@ $<

%.o : %.c
	@echo compiling $(@F)
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

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

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

clean :
	rm -f *~ *.o $(TARGET) *.d *.pyc *.pyo base_lib

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