MakeFile

From Apache OpenOffice Wiki
Revision as of 10:45, 13 April 2009 by SergeMoutou (Talk | contribs)

Jump to: navigation, search

Makefile structure

We will artificially divide the makefile in four parts :

  • the setting part
  • the compilation part
  • the execute part
  • the clean part

All makefiles provided with SDK have this structure. We can find very different compilation parts with each example provided. In this chapter we only discuss the setting part. If you have a look on the <OOSDK> directory you will see a « settings » directory. You have to use this directory if you want OS independent makefile. In general this is done with something like :

COMPONENT_NAME=ProfUnoLifetime
DKREGISTRYNAME=/usr/lib/openoffice/program/types.rdb
PRJ=../../../..
SETTINGS=$(PRJ)/settings

include $(SETTINGS)/settings.mk
include $(SETTINGS)/std.mk
include $(SETTINGS)/dk.mk

# Define non-platform/compiler specific settings
COMPONENT_NAME=ProfUnoLifetime
OUT_COMP_INC=$(OUT_INC)/$(COMPONENT_NAME)
OUT_COMP_GEN=$(OUT_MISC)/$(COMPONENT_NAME)
OUT_COMP_OBJ=$(OUT_OBJ)/$(COMPONENT_NAME)

CXXFILES = ProfUnoLifetime.cxx

OBJFILES = $(patsubst %.cxx,$(OUT_COMP_OBJ)/%.$(OBJ_EXT),$(CXXFILES))

The third line is directory-dependent : where your makefile lie and how do you reach the setting directory will change this line and the following, pointing toward the « settings » directory. Of course an other way is to use an absolute URL but portability is worse. The goal of other lines is to prepare compilation. We have let in red macros that seem not to be defined at first glance. But if you have a look to std.mk you will find the lacking definitions even if this files introduce other undefined macros which are in fact defined in settings.mk

Lifetime example: compilation part

The lifetime example is introduced in (page ). The file used to create this example is find in « <OOSDK>/examples/DevelopersGuide/ProfUNO/Lifetime ». The Lifetime directory contains a complicated makefile able of creating either a Java or a C++ example. We focus only on C++ code.

A shorter Makefile

We want to start from a shorter Makefile example than those given with SDK. For example the LifeTime example can be correctly compiled under Linux with this makefile :

# very simple makefile
CXXFILE = Test_Process.cxx
OBJFILE = Test_Process.o
OUTBIN = Test_Process
OUT_COMP_INC = ../../../../LINUXexample.out/inc/ProfUnoLifetime
OUT_COMP_OBJ = ../../../../LINUXexample.out/obj/ProfUnoLifetime
OUT_COMP_BIN = ../../../../LINUXexample.out/bin
CC_FLAGS = -c -O -fpic -fno-rtti
CC_DEFINES = -DUNX -DGCC -DLINUX -DCPPU_ENV=gcc3
PS = /
TYPES := \
	com.sun.star.uno.XNamingService \
	com.sun.star.uno.XComponentContext \
	com.sun.star.uno.XWeak \
	com.sun.star.uno.XAggregation \
	com.sun.star.lang.XMain \
	com.sun.star.lang.XMultiServiceFactory \
	com.sun.star.lang.XSingleComponentFactory \
	com.sun.star.lang.XTypeProvider \
	com.sun.star.lang.XComponent \
	com.sun.star.registry.XSimpleRegistry \
	com.sun.star.registry.XImplementationRegistration \
	com.sun.star.bridge.XBridgeFactory \
	com.sun.star.bridge.XUnoUrlResolver \
	com.sun.star.drawing.XDrawPage \
	com.sun.star.container.XHierarchicalNameAccess

TYPESLIST = $(foreach t,$(TYPES),-T$(t))
GENHPPFILES = $(foreach t,$(TYPES),$(OUT_COMP_INC)/$(subst .,/,$(t)).hpp)

ALL : \
    ProUNOLifetimeExamples

$(GENHPPFILES) :  $(subst /,$(PS),$(@D))
	mkdir -p $(OUT_COMP_INC)/$(subst /,$(PS),$(@D))
	cppumaker -Gc -BUCR -O$(OUT_COMP_INC) $(TYPESLIST) "/usr/lib/openoffice/program/types.rdb"

$(OUT_COMP_OBJ)/$(OBJFILE) : $(CXXFILE) $(GENHPPFILES)
	mkdir -p $(OUT_COMP_OBJ)/$(subst /,$(PS),$(@D))
	gcc $(CC_FLAGS) $(CC_INCLUDES) -I. \
	-I/usr/include -I../../../../LINUXexample.out/inc/examples \
	-I../../../../include -I../../../../LINUXexample.out/inc/ProfUnoLifetime $(CC_DEFINES) \
	-o$(OUT_COMP_OBJ)/$(OBJFILE) $(CXXFILE)

$(OUT_COMP_BIN)/$(OUTBIN) : $(OUT_COMP_OBJ)/$(OBJFILE)
	mkdir -p $(OUT_COMP_BIN)
	gcc -Wl -export-dynamic -L../../../../LINUXexample.out/lib -L../../../../linux/lib \
	-L/usr/lib/openoffice/program -o$(OUT_COMP_BIN)/$(OUTBIN) \
	$(OUT_COMP_OBJ)/$(OBJFILE) -lcppuhelpergcc3 -lcppu -lsalhelpergcc3 -lsal -lstlport_gcc

ProUNOLifetimeExamples : $(OUT_COMP_BIN)/$(OUTBIN)
	@echo --------------------------------------------------------------------------------
	@echo Please use one of the following commands to execute the examples!
	@echo
	@echo make ProfUnoLifetime.run
	@echo --------------------------------------------------------------------------------

ProfUnoLifetime.run : $(OUT_COMP_BIN)/$(OUTBIN)
	cd $(OUT_COMP_BIN) && $(OUTBIN)

This makefile is OS dependant. It only works under Linux. The makefiles provided with SDK are OS independent and then use more macros. We want now gives some details for each part of a makefile.

Header file generation

The Lifetime example

We begin with this example because it's the simplest example. First Figure 1.1 demonstrates how to generate the required hdl and hpp files starting from a rdb file and idl files. You will probably easier understand the makefile if you know how works the cppumaker command. As an example we give :

$ cppumaker -Gc -BUCR some.idl <OOo>/program/types.rdb -OSomeWhere 

The cppumaker documentation states

  • -O<path> path describes the root directory for the generated output. The output directory tree is generated under this directory.
  • -T<name> name specifies a type or a list of types. The output for this [t1;...] type is generated. If no '-T' option is specified, then output for all types is generated.
  • -B<name> name specifies the base node.
  • -Gc generate only target files whose content will be changed.

A question comes at first : how we know what hpp files are needed ? For the time being I can't answer this question in a general manner, but I hope to have partially answered in previous chapters. The corresponding makefile part which generates all of the hpp files is shown below :

COMPONENT_NAME=ProfUnoLifetime
DKREGISTRYNAME=/usr/lib/openoffice/program/types.rdb
PRJ=../../../..
SETTINGS=$(PRJ)/settings
OUT_INC=$(PRJ)/LINUXexample.out/inc
OUT_COMP_INC=$(OUT_INC)/$(COMPONENT_NAME)
TYPES := \
	com.sun.star.uno.XNamingService \
	com.sun.star.uno.XComponentContext \
	com.sun.star.uno.XWeak \
	com.sun.star.uno.XAggregation \
	com.sun.star.lang.XMain \
	com.sun.star.lang.XMultiServiceFactory \
	com.sun.star.lang.XSingleComponentFactory \
	com.sun.star.lang.XTypeProvider \
	com.sun.star.lang.XComponent \
	com.sun.star.registry.XSimpleRegistry \
	com.sun.star.registry.XImplementationRegistration \
	com.sun.star.bridge.XBridgeFactory \
	com.sun.star.bridge.XUnoUrlResolver \
	com.sun.star.container.XHierarchicalNameAccess

TYPESLIST = $(foreach t,$(TYPES),-T$(t))
GENHPPFILES = $(foreach t,$(TYPES),$(OUT_COMP_INC)/$(subst .,/,$(t)).hpp)

# Targets
.PHONY: ALL
ALL : ProUNOLifetimeExample

include $(SETTINGS)/stdtarget.mk

$(GENHPPFILES) :
	-$(MKDIR) $(subst /,$(PS),$(@D))
	cppumaker -Gc -BUCR -O$(OUT_COMP_INC) $(TYPESLIST) $(DKREGISTRYNAME)

Again red text indicates macros that seem to be undefined but MKDIR and PS are defined in settings.mk file. An other way to construct header files is to use a makefile and an other tool : xml2cmp. You can find an example in <OpenOffice.org1.1_SDK>/examples/cpp/remoteclient directory.

A more sophisticated example

The hpp construction is not always so easy. This can occur every time you have a component (in the sense of chapter 13). The problem in this case is the cppumaker tool is unable to generate a hpp file if its corresponding interface not registered.

Home Page

See also

Personal tools