Appendix A. Compiling Example Code

Table of Contents

SliderSubject
File Loader

This appendix provides makefiles that can be used as starting points for compiling the example code shown earlier. These can also be used as the basis for future projects using Tweek.

Important

When compiling on Windows, special care must be taken to manage DLL symbol importing correctly. The following preprocessor symbols must be defined when compiling all user code:

  • USE_core_stub_in_nt_dll

  • USE_core_stub_in_nt_dll_NOT_DEFINED_Subject

It is especially important to define these two symbols when compiling C++ code generated by the omniORB IDL compiler (omniidl). Failure to define these symbols will result in run-time errors involving the registration of subjects with the Tweek Subject Manager. Other problems may arise as well.

The best way to define these symbols is to use the /D option to CL.EXE so that every C++ file compiled has the symbols defined. This can be done easily using a Visual C++ project file or in a makefile.

SliderSubject

The following is a makefile that shows how to compile the code related to the SliderSubject example presented in the section called “Collaborative Slider”. It runs the IDL compiler, the C++ compiler, and the Java compiler. It assumes the use of omniidl, the JacORB compiler, and GCC in a Linux environment.

default: all

# Basic options.
srcdir		= .
CFLAGS		= $(EXTRA_CFLAGS) $(INCLUDES) $(DEFS)
CXXFLAGS		= -Wall -Werror-implicit-function-declaration \
                    -I$(VPR_BASE_DIR/include -I$(TWEEK_BASE_DIR)/include/tweek/CORBA \
                    $(EXTRA_CFLAGS) $(INCLUDES) $(DEFS)
CXX_IDL_OPTS	= -bcxx -Wbh=.h,s=.cpp -C$(srcdir)
CXX_IDL_INCLUDES	= -I$(TWEEK_BASE_DIR)/include
JAVAC_FLAGS	= -classpath $(CLASSPATH) -sourcepath $(srcdir) -d .
JAVA_IDL_OPTS	=  -d $(srcdir)
JAVA_IDL_INCLUDES	= -I$(TWEEK_BASE_DIR)/include

JAVA_ORB_JAR	= $(HOME)/OpenORB-1.2.0/lib/openorb-1.2.0.jar

TWEEK_EVENT_LIB	= $(TWEEK_BASE_DIR)/bin/TweekEvents.jar
TWEEK_NET_LIB	= $(TWEEK_BASE_DIR)/bin/TweekNet.jar
CLASSPATH	= $(TWEEK_EVENT_LIB):$(TWEEK_NET_LIB):$(JAVA_ORB_JAR)
DEFS		= -D__linux__ -D__OSVERSION__=2 -D__x86__
EXTRA_CFLAGS	= $(DEBUG_CFLAGS)
DEBUG_CFLAGS	= -g -D_DEBUG
OPTIM_CFLAGS	= -O2 -fno-strict-aliasing -D_OPT -DNDEBUG
INCLUDES		= -I$(TWEEK_BASE_DIR)/include -I$(HOME)/omni/include -I$(srcdir)

EXTRA_LFLAGS	= $(DEBUG_LFLAGS)
DEBUG_LFLAGS	= 
OPTIM_LFLAGS	= 
LINK_FLAGS	= $(EXTRA_LFLAGS)

# Libraries needed for linking.
BASIC_LIBS	= -Wl,-Bstatic $(LINKALL_ON) -L$(TWEEK_BASE_DIR)/lib -ltweek \
                    $(LINKALL_OFF) -Wl,-Bdynamic
EXTRA_LIBS	= -Wl,-Bdynamic  -L$(HOME)/omni/lib/i586_linux_2.0_glibc \
                    -lomniORB3 -lomnithread -lomniDynamic3 -lomniGK_stub   \
                    -L$(VPR_BASE_DIR)/lib -lvpr  -pthread   

# Commands to execute.
C_COMPILE	= gcc $(CFLAGS)
CXX_IDL		= $(HOME)/omni/bin/i586_linux_2.0_glibc/omniidl
CXX_COMPILE	= c++ $(CXXFLAGS)
JAVA_COMPILE	= /usr/java/jdk1.3.1_02/bin/javac $(JAVAC_FLAGS)
JAVA_IDL		= JACORB_PATH="$(TWEEK_BASE_DIR)/bin" "$(TWEEK_BASE_DIR)/bin/idl"
JAR		= /usr/java/jdk1.3.1_02/bin/jar
LINK		= c++ $(LINK_FLAGS)
LINKALL_ON	= -W,--whole-archive
LINKALL_OFF	= -W,--no-whole-archive

VPATH = $(srcdir):$(srcdir)/networktest:$(srcdir)/tweek:$(TWEEK_BASE_DIR)/include/tweek/idl

IDL_CXX_FILES	= SliderSubject.cpp SliderSubject.h
IDL_JAVA_FILES	= SliderSubject.java		\
                    Observer.java

OBJS		= SliderSubject.o SliderSubjectImpl.o	\
                    SliderSubjectApp.o
CLASSES		= networktest/NetworkTest.class		\
                    networktest/SliderObserverImpl.class	\
                    networktest/SliderSubjectHolder.class	\
                    tweek/ObserverHolder.class

NETWORK_TEST_CLASSES = networktest/*.class tweek/*.class

# -----------------------------------------------------------------------------
# Application build targets.
# -----------------------------------------------------------------------------
all:
	$(MAKE) cxx_idl
	$(MAKE) java_idl
	$(MAKE) cxx
	$(MAKE) server
	$(MAKE) java
	$(MAKE) NetworkTestBean.jar
	-$(MAKE) install

cxx_idl: $(IDL_CXX_FILES)

java_idl: $(IDL_JAVA_FILES)

cxx: $(OBJS)

java: $(CLASSES)

server: $(OBJS)
	$(LINK) -o $@ $(OBJS) $(BASIC_LIBS) $(EXTRA_LIBS)

NetworkTestBean.jar: $(CLASSES)
	$(JAR) cvfm $@ $(srcdir)/networktest.MF $(NETWORK_TEST_CLASSES)

install:
	cp NetworkTestBean.jar $(TWEEK_BASE_DIR)/bin/beans
	cp $(srcdir)/NetworkTestBean.xml $(TWEEK_BASE_DIR)/bin/beans

# Suffix rules for building object files.
.SUFFIXES: .cpp .o .java .class .idl .h

.cpp.o:
	$(CXX_COMPILE) -o $@ -c $<

.java.class:
	$(JAVA_COMPILE) $<

.idl.cpp:
	$(CXX_IDL) $(CXX_IDL_OPTS) $(CXX_IDL_INCLUDES) $<

.idl.h:
	$(CXX_IDL) $(CXX_IDL_OPTS) $(CXX_IDL_INCLUDES) $<

SliderSubject.java: SliderSubject.idl
	$(JAVA_IDL) $(JAVA_IDL_OPTS) -noskel $(JAVA_IDL_INCLUDES) $<

.idl.java:
	$(JAVA_IDL) $(JAVA_IDL_OPTS) $(JAVA_IDL_INCLUDES) $<

# -----------------------------------------------------------------------------
# Clean-up targets.
# -----------------------------------------------------------------------------
clean:
	rm -f Makedepend *.o networktest.ilk  so_locations *.?db	\
          core* $(addprefix $(srcdir)/, $(IDL_CXX_FILES))		\
          $(addprefix $(srcdir)/networktest/, $(IDL_JAVA_FILES))
	rm -rf ii_files $(srcdir)/tweek

clobber:
	@$(MAKE) clean
	rm -f server