#
# MICO --- a free CORBA implementation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Send comments and/or bug reports to:
#                mico@informatik.uni-frankfurt.de
#

include ../MakeVars

LDFLAGS  := -L. -L../ir -L../idl -L../orb -L../coss $(LDFLAGS)
LDLIBS   := -lidl -lmicocoss$(VERSION) -lmicoir$(VERSION) -lmico$(VERSION) $(CONFLIBS)
CXXFLAGS := -DCPP=\"mico-cpp\" -I../include -I../idl $(CXXFLAGS) $(EHFLAGS)

ifeq ($(HAVE_EXCEPTIONS), yes)
NOPICFLAGS := $(NOPICFLAGS) $(EHOPTFLAGS)
else
NOPICFLAGS := $(NOPICFLAGS) $(NOEHFLAGS)
endif
ifeq ($(HAVE_SHARED_EXCEPTS), yes)
PICFLAGS := $(PICFLAGS) $(EHOPTFLAGS)
else
PICFLAGS := $(PICFLAGS) $(NOEHFLAGS)
endif

STATIC_OBJS=CCM.o CCMContainer.o
SHARED_OBJS=$(STATIC_OBJS:.o=.pic.o)

# normal rules

ifeq ($(USE_CCM), yes)
all: prg
lib:
ifeq ($(HAVE_SHARED), yes)
ifeq ($(HAVE_STATIC), yes)
prg: .depend libmicoccm$(VERSION).$(SOEXT) libmicoccm$(VERSION).a mico-ccm
else
prg: .depend libmicoccm$(VERSION).$(SOEXT) mico-ccm
endif
else
prg: .depend libmicoccm$(VERSION).a mico-ccm
endif
else
all:
lib:
prg:
endif

mico-ccm: ../idl/libidl.a ../orb/$(LIBMICO) ../ir/$(LIBMICOIR) mico-ccm.o
	$(CXX) -o $@ $(LDFLAGS) mico-ccm.o -L. -lmicoccm$(VERSION) $(LDLIBS)
	$(POSTLD) $@

libmicoccm$(VERSION).$(SOEXT): $(SHARED_OBJS)
	$(RM) $@
ifeq ($(HAVE_REPO), yes)
	-$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(SHARED_OBJS) $(LDFLAGS) $(LDLIBS)
endif
	$(LDSO) -o libmicoccm$(VERSION) $(SHARED_OBJS)
	$(IDIRCMD) ../libs
	cd ../libs; $(RM) $@; $(LN) ../ccm/$@ .

libmicoccm$(VERSION).a: $(STATIC_OBJS)
ifeq ($(HAVE_REPO), yes)
	-$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(STATIC_OBJS) $(LDFLAGS) $(LDLIBS)
endif
	$(AR) $(ARFLAGS) $@ $(STATIC_OBJS)
	$(RANLIB) $@
	$(IDIRCMD) ../libs
	cd ../libs; $(RM) $@; $(LN) ../ir/$@ .

# cleaning

clean:
	-$(RM) mico-ccm libmicoccm*
	-$(RM) *.o *.o0 *.a *~ *.rpo *.objid
	-$(RM) .depend TAGS core nohup.out

install: all
ifeq ($(USE_CCM), yes)
	$(IDIRCMD) $(INSTDIR)/bin
	$(IBINCMD) mico-ccm $(INSTDIR)/bin
ifeq ($(HAVE_STATIC), yes)
	$(ILIBCMD) libmicoccm$(VERSION).a $(INSTDIR)/lib
endif
ifeq ($(HAVE_SHARED), yes)
	$(ILIBCMD) libmicoccm$(VERSION).$(SOEXT) $(INSTDIR)/lib
endif
endif

install-cd: install


# dependencies

ifeq (.depend, $(wildcard .depend))
include .depend
endif

generate:
	$(IDL) --name CCM --windows-dll --any ../include/mico/CCM.idl
	mv CCM.h ../include/mico/CCM.h

.depend :
	echo '# Module dependencies' > .depend
	$(MKDEPEND) $(CPPFLAGS) $(CXXFLAGS) *.cc >> .depend

