[omniORB] Full COS compilation; .h/.C too!

Alexy Khrabrov alexy.khrabrov@setup.org
Fri Aug 16 21:34:00 2002


Quoting Robert E. Gruber,
> > So the first question is, how do we really get all the COS compiled.
> 
> You figured out how to get the .mk files configured to build everything,
> but then you mentioned running into compile errors.  You
> should just be able to go to src/services/mklib and do
> 
> gnumake export
> 
> to build the COS libraries (libCOS4, libCOSBOA4, libCOSDynamic4)
> (for omniORB4, foo3 for omniORB3) and export them to lib/<arch>.  
> 
> You can then write programs that require COS stubs/skels and link against
> the appropriate COS libraries.
> 
> > Second, what is the use of cos.mk 
> 
> Include it in a dir.mk, as in
> 
> include $(BASE_OMNI_TREE)/mk/cos.mk
> 
> The comments at the top of cos.mk explain how to use the make veriables
> that are defined there:
[Saw the comments, they don't say where to include cos.mk from, hence above,
Thanks!]

I just downloaded omniORB 3.0.5 and tried to compile the full COS set by only
uncommenting the right line in src/services/mklib/libdefs.mk and commenting
out the wrong ones.  Not so easy.

The following changes had to be made:

1.  Amend DIR_IDLFLAGS and DIR_CPPFLAGS in both src/services/mklib/dir.mk
    and src/services/mklib/mkBOAlib/dir.mk as follows:

DIR_IDLFLAGS +=  -I. $(patsubst %,-I%/idl,$(IMPORT_TREES)) $(patsubst %,-I%/idl/COS,$(IMPORT_TREES))
DIR_CPPFLAGS += -D__corbaidl_h_EXTERNAL_GUARD__ -D__CosNaming_h_EXTERNAL_GUARD__ $(patsubst %,-I%/idl,$(IMPORT_TREES))

2.  During make export process, at some point ir.hh will be needed.
    Go to $TOP/idl and make it manually with omniidl, which is built by that
    point.

3.  In the file src/services/mklib/mkBOAlib/CosQuery.h,
    line 218: // NB:  typedef CORBA::_sk_InterfaceDef _sk_QLType;

refers to an undefined type and defines an unused one, so comment it out.

Please let me know if this is an oversight in the build process, as most
people just build with the default CosNotify, or there's an easier way
to do a simple clean full COS build out of the box.

In the same vein, tinkering with fixes, I now have a pure .h/.C omniORB!
(Of course, this beautiful solution applies only to context-sensitive OSes.)

Finally, I decided that once and for all, it's time to use .h and .C suffixes
in my C++ code everywhere, so here's the fix procedures I developed and tested:

1.    Rename .hh=>.h and .cc=>.C
1.1.  There are no .hh files in the distributions.  They are only referenced
      in other files.  See below.
1.2.  Rename .cc files to .C files.  The script follows:
-----cc_C:
find -name "*.cc" -exec rename \.cc \.C {} \;
=====cc_C.
NB: Linux now comes with a standard rename command as used above. 

2.    Replace references to .hh=>.h and .cc=>.C
2.1   Replace all references to .hh files to .h files.  
      The following script does that:
-----fix_hh:
#!/bin/bash

names="*.mk *.mak *.h *.C"

for kind in $names
do
	time find -name "$kind" -type f \
	-exec perl -pi -e 's/([_. ])hh(\W)/$1h$2/g' {} \;
done
=====fix_hh.

2.2   Replace all references to .cc files to .C files.
      The following script does that:
-----fix_cc:
#!/bin/bash

names="*.mk *.mak *.h *.C"

for kind in $names
do
	time find -name "$kind" -type f \
	-exec perl -pi -e 's/\.cc(\W)/.C$1/g' {} \;
done
=====fix_cc.

3.   Edit $TOP/mk/{unix,afterdir}.mk as the following patches suggest.
     I define $C suffix, but kept explicit .hh/.cc rules in case you
     want to keep omniORB distribution the way it is and only use
     the new suffixes in your new code.  Note that these files still
     contain .hh/.cc patterns, so the patches should be applied
     _after_ the replacement steps above.
     You can apply these patches in $TOP as patch -p0 < patchfile

-----patch.unix.mk:
*** mk/unix.mk~orig	Thu May 30 08:20:01 2002
--- mk/unix.mk	Fri Aug 16 16:18:49 2002
***************
*** 4,9 ****
--- 4,12 ----
  
  UnixPlatform = 1
  
+ C=C
+ h=h
+ 
  #
  # Any recursively-expanded variable set here can be overridden _afterwards_ by
  # a platform-specific mk file which includes this one.
***************
*** 139,145 ****
  
  
  OMNIORB_IDL_ONLY = $(BASE_OMNI_TREE)/$(BINDIR)/omniidl -bcxx
! OMNIORB_IDL_ANY_FLAGS = -Wba
  OMNIORB_IDL = $(OMNIORB_IDL_ONLY) $(OMNIORB_IDL_ANY_FLAGS)
  OMNIORB_CPPFLAGS = -D__OMNIORB$(OMNIORB_MAJOR_VERSION)__ -I$(CORBA_STUB_DIR) $(OMNITHREAD_CPPFLAGS)
  OMNIORB_IDL_OUTPUTDIR_PATTERN = -C%
--- 142,148 ----
  
  
  OMNIORB_IDL_ONLY = $(BASE_OMNI_TREE)/$(BINDIR)/omniidl -bcxx
! OMNIORB_IDL_ANY_FLAGS = -Wba -Wbh=.$h -Wbs=SK.$C -Wbd=DynSK.$C
  OMNIORB_IDL = $(OMNIORB_IDL_ONLY) $(OMNIORB_IDL_ANY_FLAGS)
  OMNIORB_CPPFLAGS = -D__OMNIORB$(OMNIORB_MAJOR_VERSION)__ -I$(CORBA_STUB_DIR) $(OMNITHREAD_CPPFLAGS)
  OMNIORB_IDL_OUTPUTDIR_PATTERN = -C%
***************
*** 155,174 ****
  OMNIORB_STATIC_STUB_OBJS = \
  	$(CORBA_INTERFACES:%=$(CORBA_STUB_DIR)/%SK.o)
  OMNIORB_STATIC_STUB_SRCS = \
! 	$(CORBA_INTERFACES:%=$(CORBA_STUB_DIR)/%SK.cc)
  OMNIORB_DYN_STUB_OBJS = \
  	$(CORBA_INTERFACES:%=$(CORBA_STUB_DIR)/%DynSK.o)
  OMNIORB_DYN_STUB_SRCS = \
! 	$(CORBA_INTERFACES:%=$(CORBA_STUB_DIR)/%DynSK.cc)
  
  OMNIORB_STUB_SRCS = $(OMNIORB_STATIC_STUB_SRCS) $(OMNIORB_DYN_STUB_SRCS)
  OMNIORB_STUB_OBJS = $(OMNIORB_STATIC_STUB_OBJS) $(OMNIORB_DYN_STUB_OBJS)
  
! OMNIORB_STUB_SRC_PATTERN = $(CORBA_STUB_DIR)/%SK.cc
  OMNIORB_STUB_OBJ_PATTERN = $(CORBA_STUB_DIR)/%SK.o
! OMNIORB_DYN_STUB_SRC_PATTERN = $(CORBA_STUB_DIR)/%DynSK.cc
  OMNIORB_DYN_STUB_OBJ_PATTERN = $(CORBA_STUB_DIR)/%DynSK.o
! OMNIORB_STUB_HDR_PATTERN = $(CORBA_STUB_DIR)/%.hh
  
  
  # omniORB access control policy modules
--- 158,177 ----
  OMNIORB_STATIC_STUB_OBJS = \
  	$(CORBA_INTERFACES:%=$(CORBA_STUB_DIR)/%SK.o)
  OMNIORB_STATIC_STUB_SRCS = \
! 	$(CORBA_INTERFACES:%=$(CORBA_STUB_DIR)/%SK.$C)
  OMNIORB_DYN_STUB_OBJS = \
  	$(CORBA_INTERFACES:%=$(CORBA_STUB_DIR)/%DynSK.o)
  OMNIORB_DYN_STUB_SRCS = \
! 	$(CORBA_INTERFACES:%=$(CORBA_STUB_DIR)/%DynSK.$C)
  
  OMNIORB_STUB_SRCS = $(OMNIORB_STATIC_STUB_SRCS) $(OMNIORB_DYN_STUB_SRCS)
  OMNIORB_STUB_OBJS = $(OMNIORB_STATIC_STUB_OBJS) $(OMNIORB_DYN_STUB_OBJS)
  
! OMNIORB_STUB_SRC_PATTERN = $(CORBA_STUB_DIR)/%SK.$C
  OMNIORB_STUB_OBJ_PATTERN = $(CORBA_STUB_DIR)/%SK.o
! OMNIORB_DYN_STUB_SRC_PATTERN = $(CORBA_STUB_DIR)/%DynSK.$C
  OMNIORB_DYN_STUB_OBJ_PATTERN = $(CORBA_STUB_DIR)/%DynSK.o
! OMNIORB_STUB_HDR_PATTERN = $(CORBA_STUB_DIR)/%.$h
  
  
  # omniORB access control policy modules
***************
*** 301,310 ****
  # The pattern rules below ensured that the right compiler flags are used
  # to compile the source for the library.
  
! static/%.o: %.cc
  	$(CXX) -c $(CXXFLAGS) -o $@ $<
  
! shared/%.o: %.cc
  	$(CXX) -c $(SHAREDLIB_CPPFLAGS) $(CXXFLAGS)  -o $@ $<
  
  static/%.o: %.c
--- 304,319 ----
  # The pattern rules below ensured that the right compiler flags are used
  # to compile the source for the library.
  
! static/%.o: %.$C
! 	$(CXX) -c $(CXXFLAGS) -o $@ $<
! 
! shared/%.o: %.$C
! 	$(CXX) -c $(SHAREDLIB_CPPFLAGS) $(CXXFLAGS)  -o $@ $<
! 
! static/%.o: %.C
  	$(CXX) -c $(CXXFLAGS) -o $@ $<
  
! shared/%.o: %.C
  	$(CXX) -c $(SHAREDLIB_CPPFLAGS) $(CXXFLAGS)  -o $@ $<
  
  static/%.o: %.c
***************
*** 322,328 ****
  %.o: %.c
  	$(CC) -c $(CFLAGS) -o $@ $<
  
! %.o: %.cc
  	$(CXX) -c $(CXXFLAGS) -o $@ $<
  
  
--- 331,337 ----
  %.o: %.c
  	$(CC) -c $(CFLAGS) -o $@ $<
  
! %.o: %.$C
  	$(CXX) -c $(CXXFLAGS) -o $@ $<
  
=====patch.unix.mk.
-----patch.afterdir.mk:
*** mk/afterdir.mk~orig	Fri Aug 18 08:10:18 2000
--- mk/afterdir.mk	Fri Aug 16 14:25:25 2002
***************
*** 2,7 ****
--- 2,8 ----
  # afterdir.mk - standard make stuff to go after dir.mk
  #
  
+ C=C
  
  #############################################################################
  #
***************
*** 153,161 ****
  %.d: %.c $(GENERATED_C_HDRS)
  	@echo "$<" >> cdepend.tmp
  
! %.d: %.cc $(GENERATED_CXX_HDRS)
  	@echo "$<" >> cxxdepend.tmp
  
  %.d: %.s $(GENERATED_AS_HDRS)
  	@echo "$<" >> asdepend.tmp
  
--- 154,166 ----
  %.d: %.c $(GENERATED_C_HDRS)
  	@echo "$<" >> cdepend.tmp
  
! %.d: %.$C $(GENERATED_CXX_HDRS)
  	@echo "$<" >> cxxdepend.tmp
  
+ %.d: %.C $(GENERATED_CXX_HDRS)
+ 	@echo "$<" >> cxxdepend.tmp
+ 
+ 
  %.d: %.s $(GENERATED_AS_HDRS)
  	@echo "$<" >> asdepend.tmp
  
***************
*** 201,207 ****
  endif
  
  ifdef CXXSRCS
! -include $(CXXSRCS:.cc=.d)
  endif
  
  ifdef ASSRCS
--- 206,214 ----
  endif
  
  ifdef CXXSRCS
! CXXSRCS_C  = $(filter %.C,  CXXSRCS)
! CXXSRCS_cc = $(filter %.C, CXXSRCS)
! -include $(CXXSRCS_C:.C=.d) $(CXXSRCS_cc:.cc=.d)
  endif
  
  ifdef ASSRCS
=====patch.afterdir.mk.

Let me know if this works for you, or other improvements in this scheme.
Ideally, this should be easily customizable in one place.

Cheers,
Alexy