#
# MICO --- a free CORBA implementation
# Copyright (C) 1997 Kay Roemer & Arno Puder
#
# 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

CXXFLAGS := -I../include $(CXXFLAGS)

UNI_SRCS = uni_base64.cc uni_unicode.cc uni_fromuni.cc uni_touni.cc

ifeq ($(HAVE_FINAL), yes)
SRCS = orb_all.cc except2.cc poa.cc poa_impl.cc $(UNI_SRCS)
STATIC_OBJS = $(SRCS:.cc=.o)
ALL_STATIC_OBJS = $(STATIC_OBJS) ../ir/ir_all.o ../imr/imr_all.o
else
SRCS = dii.cc typecode.cc any.cc codec.cc buffer.cc context.cc \
  except.cc except2.cc dispatch.cc string.cc object.cc address.cc ior.cc \
  orb.cc boa.cc dsi.cc transport.cc iop.cc util.cc basic_seq.cc CORBA-c.cc \
  ssl.cc fixed.cc intercept.cc dynany.cc codeset.cc queue.cc static.cc \
  current.cc policy.cc policy_impl.cc poa.cc poa_impl.cc service_info.cc \
  os-unix.cc $(UNI_SRCS)
STATIC_OBJS = $(SRCS:.cc=.o)
ALL_STATIC_OBJS = $(STATIC_OBJS) ../ir/ir_impl.o ../ir/ir1.o ../ir/ir2.o \
  ../imr/imr_impl.o ../imr/imr.o
endif

SHARED_OBJS = $(STATIC_OBJS:.o=.pic.o)
ALL_SHARED_OBJS = $(ALL_STATIC_OBJS:.o=.pic.o)
REG_FILES = ../admin/code_set_registry.txt ../admin/mico_code_set_registry.txt

all: lib prg

ifeq ($(HAVE_SHARED), yes)
ifeq ($(HAVE_STATIC), yes)
lib: .depend $(STATIC_OBJS) $(SHARED_OBJS)
prg: .depend libmico$(VERSION).$(SOEXT) libmico$(VERSION).a
else
lib: .depend $(SHARED_OBJS)
prg: .depend libmico$(VERSION).$(SOEXT)
endif
else
lib: .depend $(STATIC_OBJS)
prg: .depend libmico$(VERSION).a
endif

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

except2.pic.o: except2.cc
	$(CXX) $(PICFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(EHOPTFLAGS) -c $< -o $@

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

poa.pic.o: poa.cc
	$(CXX) $(PICFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(EHOPTFLAGS) -c $< -o $@

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

poa_impl.pic.o: poa_impl.cc
	$(CXX) $(PICFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(EHOPTFLAGS) -c $< -o $@

codeset.cc: ../include/mico/code_set_registry.h

REG_FILES = ../admin/code_set_registry.txt ../admin/mico_code_set_registry.txt

../include/mico/code_set_registry.h: $(REG_FILES)
	../admin/mkcsreg $(REG_FILES) > $@

# shared

ifeq ($(HAVE_SHARED), yes)
libmico$(VERSION).$(SOEXT): $(ALL_SHARED_OBJS)
ifeq ($(HAVE_REPO), yes)
	-$(CXX) $(CXXFLAGS) $(ALL_SHARED_OBJS) $(LDFLAGS) $(CONFLIBS)
endif
	rm -f $@
	$(LDSO) -o libmico$(VERSION) $(ALL_SHARED_OBJS)
	$(IDIRCMD) ../libs
	cd ../libs; rm -f $@; ln -f -s ../orb/$@ .
endif

# static

libmico$(VERSION).a: $(ALL_STATIC_OBJS)
ifeq ($(HAVE_REPO), yes)
	-$(CXX) $(CXXFLAGS) $(ALL_STATIC_OBJS) $(LDFLAGS) $(CONFLIBS)
endif
	$(AR) $(ARFLAGS) $@ $(ALL_STATIC_OBJS)
	$(RANLIB) $@
	$(IDIRCMD) ../libs
	cd ../libs; rm -f $@; ln -f -s ../orb/$@ .


generate:
	../admin/mkcsreg $(REG_FILES) > ../include/mico/code_set_registry.h
	$(IDL) --name current --pseudo ../include/mico/current.idl
	patch < current.cc.diffs
	rm -f current.*.orig
	mv current.h ../include/mico/current.h
	$(IDL) --name policy --relative-paths -I../include --pseudo \
		../include/mico/policy.idl
	patch < policy.cc.diffs
	rm -f policy.*.orig
	mv policy.h ../include/mico/policy.h
	$(IDL) --name poa --relative-paths -I../include --pseudo \
		../include/mico/poa.idl
	patch < poa.cc.diffs
	rm -f poa.*.orig
	mv poa.h ../include/mico/poa.h
	$(IDL) --name service_info --pseudo ../include/mico/service_info.idl
	patch < service_info.cc.diffs
	rm -f service_info.*.orig
	mv service_info.h ../include/mico/service_info.h

diffs:
	mkdir orig
	cd orig; $(IDL) --name current --pseudo ../../include/mico/current.idl
	rm current.cc.diffs
	diff -c orig/current.cc current.cc > current.cc.diffs || true
	cd ../include/mico; diff -c ../../orb/orig/current.h current.h \
	  >> ../../orb/current.cc.diffs || true
	rm -rf orig
	mkdir orig
	cd orig; $(IDL) --name policy --relative-paths -I../../include \
	  --pseudo ../../include/mico/policy.idl
	rm policy.cc.diffs
	diff -c orig/policy.cc policy.cc > policy.cc.diffs || true
	cd ../include/mico; diff -c ../../orb/orig/policy.h policy.h \
	  >> ../../orb/policy.cc.diffs || true
	rm -rf orig
	mkdir orig
	cd orig; $(IDL) --name poa --relative-paths -I../../include \
	  --pseudo ../../include/mico/poa.idl
	rm poa.cc.diffs
	diff -c orig/poa.cc poa.cc > poa.cc.diffs || true
	cd ../include/mico; diff -c ../../orb/orig/poa.h poa.h \
	  >> ../../orb/poa.cc.diffs || true
	rm -rf orig
	mkdir orig
	cd orig; $(IDL) --name service_info --pseudo \
	  ../../include/mico/service_info.idl
	rm service_info.cc.diffs
	diff -c orig/service_info.cc service_info.cc \
	      > service_info.cc.diffs || true
	cd ../include/mico; diff -c ../../orb/orig/service_info.h \
	  service_info.h >> ../../orb/service_info.cc.diffs || true
	rm -rf orig

clean:
	rm -f *.rpo *.a *.o *.o0 *~ *.$(SOEXT) .depend

install:
	$(IDIRCMD) $(INSTDIR)/lib
ifeq ($(HAVE_STATIC), yes)
	$(ILIBCMD) libmico$(VERSION).a $(INSTDIR)/lib
endif
ifeq ($(HAVE_SHARED), yes)
	$(ILIBCMD) libmico$(VERSION).$(SOEXT) $(INSTDIR)/lib
endif

install-cd: install

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

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

