Overview

Using Makefiles to build STEP Tools® software applications on UNIX, MacOS, or Windows is simple because many settings and rules are already handled by pre-installed config files. The sample programs are a great place to see how these are configured. The Windows samples have makefiles as well as project files.

We use environment variables set by the STEP Tools® software installer to tell the C++ compiler where to find header files and libraries. The ROSE_INCLUDE variable points to the header file directory, ROSE_LIB points to the library directory, and ROSE_CONFIG points to a file with makefile definitions for your platform and compiler.

If you choose to adapt one of our sample makefiles, you should check the settings on the following macros used by the default C++ compile rules:

Finding Header Files

You must tell the compiler to look for header files in two extra directories. The first is the ROSE_INCLUDE directory for ROSE library. The second is the subdirectory for your schema, such as ROSE_INCLUDE/stp_aim for the STEP library classes. Make sure that you use the correct directory for your schema! The include directory name is listed on the page for each schema.

In the example below, note that the ROSE_INCLUDE variable is quoted under Windows to avoid problems with whitespace in the path

# for UNIX and MacOS Makefiles
CXX_CFLAGS = -I$(ROSE_INCLUDE)/stp_aim -I$(ROSE_INCLUDE) 

# for Windows Makefiles
CXX_CFLAGS = /I"$(ROSE_INCLUDE)\stp_aim" /I"$(ROSE_INCLUDE)"

Linking To The Libraries

Next, you must tell the linker what library files to use and where to find them. All library files are in the directory pointed to by the ROSE_LIB environment variable. As with the previous example, we quote the ROSE_LIB variable under Windows to avoid problems with whitespace in the path.

You must link against at least two libraries. The first is the ROSE library (rose.lib or -lrose). The second is the library for your schema, such as stp_aim.lib or -lstp_aim for the STEP EXPRESS classes. Make sure that you use the correct library for your schema! The library name is listed on the page for each schema. If your program needs Part 28 XML support, add rosexml.lib or -lrosexml to the list of libraries.

# for UNIX and MacOS Makefiles
CXX_LDFLAGS = -L$(ROSE_LIB)
LIBRARIES   = -lstp_aim -lrosexml -lrose $(CXX_SYSLIBS)

# for Windows Makefiles
CXX_LDFLAGS = /LIBPATH:"$(ROSE_LIB)"
LIBRARIES   = stp_aim.lib rosexml.lib rose.lib $(CXX_SYSLIBS)

An STEP Tools® software installation may contain several versions of the programming libraries for use with different C++ compilers. For example, STEP Tools® software for Windows ships with static and DLL versions built with the /MD compiler flag. The ROSE_LIB environment variable usually points to the most commonly used version.

To build all of your projects against a different version, change the ROSE_LIB variable. To change the version for just one project, use the ROSE environment variable, which points to the root of the STEP Tools® software installation. You can then call out a library directory explicitly. Check the STEP Tools® software release notes and install directory for the available versions each platform.

Complete UNIX Makefile

Below is a Makefile for UNIX and MacOS systems. It builds an executable called my_prog against the STEP class library. At the beginning, We include the ROSE_CONFIG file to set default compile rules and other definitions.

# Sample UNIX and MacOS Makefile
# 
include $(ROSE_CONFIG)

# Set these to the compiler flags and directives for all packages.
# These are used by the CXX_COMPILE and CX_LINK C++ compile and link
# macros.
#
CXX_CFLAGS 	= -I$(ROSE_INCLUDE)/stp_aim -I$(ROSE_INCLUDE) 
CXX_LDFLAGS 	= -L$(ROSE_LIB)
LIBRARIES 	= -lstp_aim -lrosexml -lrose $(CXX_SYSLIBS)

# EXECS AND OBJECT FILES -- All object files are built using the
# default .cxx to .obj rules defined in the $ROSE_CONFIG file
#
EXEC	= my_prog
OBJECTS = \
	main$o \
	other_file_1$o \
	other_file_2$o \
	other_file_3$o


#========================================
# Standard Symbolic Targets
#
default: $(EXEC)
install: $(EXEC)

clean: 		; - $(RM) *.o $(EXECS)
very-clean: 	clean
spotless: 	very-clean

#========================================
# Executables and other targets
#
$(EXEC): $(OBJECTS)
	$(CXX_LINK) -o $@ $(OBJECTS) $(LIBRARIES)

Complete Windows Makefile

A Windows version of the same file has a few syntactic differences, such as the "!" demanded by nmake when including the config file, and the different clean target. The ROSE_INCLUDE and ROSE_LIB variables are quoted to avoid problems with whitespace in the path.

# Sample Windows Makefile
# 
!include $(ROSE_CONFIG)

# Set these to the compiler flags and directives for all packages.
# These are used by the CXX_COMPILE and CX_LINK C++ compile and link
# macros.
#
CXX_CFLAGS 	= /I"$(ROSE_INCLUDE)\stp_aim" /I"$(ROSE_INCLUDE)"
CXX_LDFLAGS 	= /LIBPATH:"$(ROSE_LIB)"
LIBRARIES 	= stp_aim.lib rosexml.lib rose.lib $(CXX_SYSLIBS)

# EXECS AND OBJECT FILES -- All object files are built using the
# default .cxx to .obj rules defined in the $ROSE_CONFIG file
#
EXEC	= my_prog.exe
OBJECTS = \
	main$o \
	other_file_1$o \
	other_file_2$o \
	other_file_3$o

#========================================
# Standard Symbolic Targets
#
default: $(EXEC)
install: $(EXEC)

clean: 
	- $(RM) *.obj
	- $(RM) *.exe

very-clean: 	clean
spotless: 	very-clean

#========================================
# Executables and other targets
#
$(EXEC): $(OBJECTS)
	$(CXX_LINK) /out:$@ $(OBJECTS) $(LIBRARIES)

ROSE_CONFIG Definitions

The following Makefile variable definitions are set by including the ROSE_CONFIG file. The exact value of each macro may vary by platform and compiler, but all should be present and available for use in your makefiles.

#========================================
# USER RESERVED -- The following are reserved for users to set on the
# command line.  Makefiles should not set these.  These variables are
# for C/C++ compilation, and linking.
CFLAGS		=
JFLAGS		=
LDFLAGS		=

# OPTIMIZE with the -O option.  Override from the command line for
# building debug versions.
#
OPTFLAGS	= -O

#========================================
# FILE EXTENSIONS.  Extensions and prefixes for different types of
# files change from platform to platform.  Hide these in macros so
# that we can more easily cut and paste between makefiles.
o		= .o
EXE_SFX		= 
SCRIPT_SFX 	= 
LIB_PFX		= lib
LIB_SFX		= .a
LIB_SHARED_SFX	= .so
TMPLIB		= libtemp.a

# FILE TOOLS
AR 	= ar qv
CHMOD 	= chmod
CP	= cp
GREP	= grep
MKDIR 	= mkdir
MUNCH 	= stepmunch
MV	= mv
NM 	= nm
RANLIB	= ranlib
RM 	= rm -f
RMDIR 	= rm -rf
STRIP	= strip
UNZIP 	= unzip
ZIP 	= zip


#========================================
# ANSI C Compile and Link
#
CC		= cc
CC_COMPILE	= $(CC) -c $(OPTFLAGS) $(CFLAGS) $(CC_CFLAGS) $(CC_SYSCFLAGS)
CC_LINK		= $(CC) $(LDFLAGS) $(CC_LDFLAGS) $(CC_SYSLDFLAGS)
CC_CFLAGS 	=
CC_LDFLAGS	=

# Global system things used for compilation, static linking, etc.
CC_SYSCFLAGS 	= 
CC_SYSLDFLAGS 	= 
CC_SYSLIBS	= 


#========================================
# C++ Compile and Link
#
CXX		= CC
CXX_COMPILE	= $(CXX) -c  $(OPTFLAGS) $(CFLAGS) $(CXX_CFLAGS) $(CXX_SYSCFLAGS)
CXX_LINK	= $(CXX) $(LDFLAGS) $(CXX_LDFLAGS) $(CXX_SYSLDFLAGS)
CXX_CFLAGS 	= 
CXX_LDFLAGS	=

# The force flags are used for C/C++ compilers that select the
# language based on the file naming conventions.  Some C++ source
# may be in files with C naming conventions.
CXX_FORCE	= 

# System Flags -- Things for static linking or making sure that the
# compiler understands that a file is a C++ file or whatever.  These
# usually change from platform to platform.
CXX_SYSCFLAGS 	=
CXX_SYSLDFLAGS 	= 
CXX_SYSLIBS	= 


# Compilation Rules -- Repeat the rules for all of the different
# naming conventions.
#
.cxx.o:	; $(CXX_COMPILE) $<
.cpp.o:	; $(CXX_COMPILE) $<
.cc.o:	; $(CXX_COMPILE) $<
.C.o:	; $(CXX_COMPILE) $<

.cxx:	
	$(CXX_COMPILE) $<
	$(CXX_LINK) -o $@ $*.o $(LIBRARIES)
.cpp:	
	$(CXX_COMPILE) $<
	$(CXX_LINK) -o $@ $*.o $(LIBRARIES)
.cc:	
	$(CXX_COMPILE) $<
	$(CXX_LINK) -o $@ $*.o $(LIBRARIES)
.C:	
	$(CXX_COMPILE) $<
	$(CXX_LINK) -o $@ $*.o $(LIBRARIES)


# Compile plain C code
.c.o:	; $(CC_COMPILE) $<
.c:	
	$(CC_COMPILE) $<
	$(CC_LINK) -o $@ $*.o $(LIBRARIES)


#========================================
# JAVA Compile and Package
#
JAR		= jar
JAVADOC		= javadoc

JAVAC		= javac
JAVA_COMPILE	= $(JAVAC) $(JFLAGS) $(JAVA_CFLAGS)
JAVA_CFLAGS 	=

.java.class:	; $(JAVA_COMPILE) $<



#========================================
# ROSE Packages 
#
ROSE_CFLAGS	= -I$(ROSE_INCLUDE)
ROSE_LDFLAGS	= -L$(ROSE_LIB)
ROSE_LIBS	= -lrose