#
# Copyright (C) 2006 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@
LEX 	:= @LEX@
YACC 	:= @YACC@ -d
MAKEDEP	:= $(CXX) -M
IDLMODULE_VERSION := 0x2630# => CORBA 2.6, front-end 3.0
CPPFLAGS:= @CPPFLAGS@ -I . 
CPPFLAGS+= -I $(srcdir)
CPPFLAGS+= -I @PYTHON_INCLUDE@ -DPYTHON_INCLUDE="<Python.h>"
CPPFLAGS+= -DIDLMODULE_VERSION="\"$(IDLMODULE_VERSION)\""
CXXFLAGS:= @CXXFLAGS@
LDFLAGS	:= @LDFLAGS@
LIBS	:= @LIBS@
LIBRARY_EXT := @LIBEXT@

YYSRC	:= idl.yy
LLSRC	:= idl.ll

SRC 	:= y.tab.cc lex.yy.cc idlerr.cc idlutil.cc idltype.cc \
           idlrepoId.cc idlscope.cc idlexpr.cc idlast.cc idlvalidate.cc \
           idldump.cc idlconfig.cc idlfixed.cc idlpython.cc #idlc.cc
OBJ	:= $(patsubst %.cc, %.o, $(SRC))
DEP	:= $(patsubst %.cc, %.d, $(SRC))

TARGET	:= _omniidl$(LIBRARY_EXT)

vpath %.yy  $(srcdir)
vpath %.ll  $(srcdir)
vpath %.hh  $(srcdir)
vpath %.cc  $(srcdir)

all: $(TARGET)

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

clean:
	rm -f $(CTOOL_SO)
	rm -rf $(OBJ) $(DEP)

y.tab.h y.tab.cc: $(YYSRC)
	@rm -f $@
	$(YACC) $<
	mv -f y.tab.c y.tab.cc

lex.yy.cc: $(LLSRC) y.tab.h
	$(LEX) -o$@ $<
	echo '#ifdef __VMS' >> $@
	echo '// Some versions of DEC C++ for OpenVMS set the module name used by the' >> $@
	echo '// librarian based on the last #line encountered.' >> $@
	echo '#line' `cat $@ | wc -l` '"lex_yy.cc"' >> $@
	echo '#endif' >> $@

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

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

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

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