Changes between Version 11 and Version 12 of pm-switch


Ignore:
Timestamp:
Dec 20, 2010 9:32:34 AM (9 years ago)
Author:
stefan
Comment:

document new example Makefiles

Legend:

Unmodified
Added
Removed
Modified
  • pm-switch

    v11 v12  
    209209The changes here are similar to those described above.
    210210
    211 == {{{Root/Xxx/examples}}} ==
    212 
    213 Again, the main difference here is that one has to build from the new set of variables defined above in linking to the installed libraries. Alternatively, if you would like to check for or assume the presence of pkg-config on the system the examples will be built on, the most ideal thing would be to build your example Makefiles to show to use pkg-config, as this is the exact use case we are attempting to support.
     211== {{{Root/Xxx/examples/Makefile.in}}} ==
     212
     213The changes to the examples Makefile's are more involved, since compiler and linker flags are assembled differently, depending on whether pkg-config is available or not. Supporting a build under cygwin with cl messes up the Makefile additionally.
     214Note that currently a build of the examples under cygwin with cl or icl compiler and with pkg-config available is ***not supported***.
     215
     216A typical examples Makefile.in starts like before:
     217{{{
     218# Copyright (C) ...
     219# All Rights Reserved.
     220# This file is distributed under the Common Public License.
     221
     222# $Id$
     223
     224##########################################################################
     225#    You can modify this example makefile to fit for your own program.   #
     226#    Usually, you only need to change the five CHANGEME entries below.   #
     227##########################################################################
     228
     229# To compile other examples, either changed the following line, or
     230# add the argument DRIVER=problem_name to make
     231DRIVER = driver
     232
     233# CHANGEME: This should be the name of your executable
     234EXE = $(DRIVER)@EXEEXT@
     235
     236# CHANGEME: Here is the name of all object files corresponding to the source
     237#           code that you wrote in order to define the problem statement
     238OBJS =  $(DRIVER).@OBJEXT@
     239
     240# CHANGEME: Additional libraries
     241ADDLIBS =
     242
     243# CHANGEME: Additional flags for compilation (e.g., include flags)
     244ADDINCFLAGS =
     245
     246# CHANGEME: Directory to the sources for the (example) problem definition
     247# files
     248SRCDIR = @srcdir@
     249VPATH = @srcdir@
     250
     251##########################################################################
     252#  Usually, you don't have to change anything below.  Note that if you   #
     253#  change certain compiler options, you might have to recompile the      #
     254#  COIN package.                                                         #
     255##########################################################################
     256}}}
     257
     258Next, we define a few variables:
     259{{{
     260COIN_HAS_PKGCONFIG = @COIN_HAS_PKGCONFIG_TRUE@TRUE
     261COIN_CXX_IS_CL = @COIN_CXX_IS_CL_TRUE@TRUE
     262COIN_HAS_SAMPLE = @COIN_HAS_SAMPLE_TRUE@TRUE
     263COIN_HAS_NETLIB = @COIN_HAS_NETLIB_TRUE@TRUE
     264}}}
     265This leads to storing the value TRUE in COIN_HAS_PKGCONFIG, if pkg-config is used.
     266Also COIN_CXX_IS_CL is set to TRUE if the MS or Intel compiler (cl, icl) is used under Windows.
     267The variables COIN_HAS_SAMPLE and COIN_HAS_NETLIB get the value TRUE, if the Sample or Netlib data projects were found during configure.
     268
     269Setting the compiler and compiler flags works as before:
     270{{{
     271# C++ Compiler command
     272CXX = @CXX@
     273
     274# C++ Compiler options
     275CXXFLAGS = @CXXFLAGS@
     276
     277# additional C++ Compiler options for linking
     278CXXLINKFLAGS = @RPATH_FLAGS@
     279
     280# C Compiler command
     281CC = @CC@
     282
     283# C Compiler options
     284CFLAGS = @CFLAGS@
     285}}}
     286
     287Some examples have paths to Data directories compiled into their binaries.
     288This is achieved by setting a compiler define in the compiler flags:
     289{{{
     290# Sample data directory
     291ifeq ($(COIN_HAS_SAMPLE), TRUE)
     292  ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
     293    CXXFLAGS += -DSAMPLEDIR=\"`PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --variable=datadir coindatasample`\"
     294      CFLAGS += -DSAMPLEDIR=\"`PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --variable=datadir coindatasample`\"
     295  else
     296    CXXFLAGS += -DSAMPLEDIR=\"@SAMPLE_DATA_INSTALLED@\"
     297      CFLAGS += -DSAMPLEDIR=\"@SAMPLE_DATA_INSTALLED@\"
     298  endif
     299endif
     300
     301# Netlib data directory
     302ifeq ($(COIN_HAS_NETLIB), TRUE)
     303  ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
     304    CXXFLAGS += -DNETLIBDIR=\"`PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --variable=datadir coindatanetlib`\"
     305      CFLAGS += -DNETLIBDIR=\"`PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --variable=datadir coindatanetlib`\"
     306  else
     307    CXXFLAGS += -DNETLIBDIR=\"@NETLIB_DATA_INSTALLED@\"
     308      CFLAGS += -DNETLIBDIR=\"@NETLIB_DATA_INSTALLED@\"
     309  endif
     310endif
     311}}}
     312Here, SAMPLEDIR is defined if COIN_HAS_SAMPLE is TRUE. If pkg-config is available, then the path to the sample directory is obtained by calling pkg-config.
     313If pkg-config is not available, then the AC_COIN_CHECK_PACKAGE macro in configure.ac should have setup a variable SAMPLE_DATA_INSTALLED that contains the path to the installed sample data. Not that the variable SAMPLE_DATA_INSTALLED is only setup if pkg-config is not available, because only then the coindatasample.pc file is parsed by configure itself.
     314
     315Next we setup the include-flags.
     316Again, we distinguish between a setup where pkg-config is available (and thus is used to check for compiler flags) and where it is not available.
     317In the latter case, the AC_COIN_CHECK_PACKAGE macro should have setup a variable XXXLIB_CFLAGS_INSTALLED.
     318{{{
     319ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
     320  INCL = `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --cflags xxx`
     321else
     322  INCL = @XXXLIB_CFLAGS_INSTALLED@
     323endif
     324INCL += $(ADDINCFLAGS)
     325}}}
     326
     327Finally, the linker flags containing all library dependencies.
     328If pkg-config is available, then we use it to request the dependencies.
     329If it is not available, then AC_COIN_CHECK_PACKAGE has setup a variable XXXLIB_LIBS_INSTALLED that contains all dependencies of our project.
     330Additionally, we need to list the library of our project.
     331Since the cl and icl compiler use a different syntax, we have to distinguish here between which type of compiler is used.
     332For the XXXLIB_LIBS_INSTALLED variable, configure has already done this.
     333{{{
     334# Linker flags
     335ifeq ($(COIN_HAS_PKGCONFIG), TRUE)
     336  LIBS = `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --libs xxx`
     337else
     338  ifeq ($(COIN_CXX_IS_CL), TRUE)
     339    LIBS = /link /libpath:`$(CYGPATH_W) @abs_lib_dir@` libXxx.lib @XXXLIB_LIBS_INSTALLED@
     340  else
     341    LIBS = -L@abs_lib_dir@ -lXxx @XXXLIB_LIBS_INSTALLED@
     342  endif
     343endif
     344}}}
     345
     346The rest is as before:
     347{{{
     348# The following is necessary under cygwin, if native compilers are used
     349CYGPATH_W = @CYGPATH_W@
     350
     351# Here we list all possible generated objects or executables to delete them
     352CLEANFILES = \
     353        driver.@OBJEXT@ driver@EXEEXT@ \
     354        driverC.@OBJEXT@ driverC@EXEEXT@
     355
     356all: $(EXE)
     357
     358.SUFFIXES: .cpp .c .o .obj
     359
     360$(EXE): $(OBJS)
     361        bla=;\
     362        for file in $(OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; done; \
     363        $(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(LIBS) $(ADDLIBS)
     364
     365clean:
     366        rm -rf $(CLEANFILES)
     367
     368.cpp.o:
     369        $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
     370
     371
     372.cpp.obj:
     373        $(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
     374
     375.c.o:
     376        $(CC) $(CFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
     377
     378
     379.c.obj:
     380        $(CC) $(CFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`
     381}}}