conditional compilation

conditional compilation

Post by stuart.rei.. » Wed, 17 Jan 2001 18:53:24



All,

I have some code which needs to compile on solaris 2.5.1 and
solaris 2.7. There are some minor probs with RPC code which
could easily be solved with some conditional compilations

Is the some #define somewhere which I can use to differentiate
between the two OS.

ie

#ifdef SOL_251
Do solaris 2.5.1 code
#else
Do solaris 2.7 code
#endif

I working on Sun sparc workstation, using SC5.0 compiler.

Any help much appreciated

Regards
Stuart

Sent via Deja.com
http://www.deja.com/

 
 
 

conditional compilation

Post by Michael Uma » Thu, 18 Jan 2001 07:32:15


Stuart,

I would create a preprocessor symbol of my own and pass it in the
makefile. gmake can execute 'uname' to determine which OS it is running
on, depending on how that make variable is set you can set the
preprocessor symbol {i.e. -D SOL_251}.

We do this at Sonic, so I can build for both IRIX and IRIX64...

FOR EXAMPLE:

##############################################################################

# MODULE  : Make.common
# PROJECT  : Sonic Common Library

# DATE  : April 16, 2000
#
# Variables :
#
# $INCLUDE : Set to include specification for project
# $PLIBDIRS : Set to library search path specification {-L xx/}
# $PLIBS  : Set to librarys to link with {-l xx -l yy}
# $ADDSYMS : Set to additional preprocessor symbols to define.
#
##############################################################################

# NOTE  : Added preprocessing of module to force include of
#     platform header.
##############################################################################

#SHELL  = /sbin/sh
CPUTYPE  = $(shell uname -m)
OSTYPE  = $(shell uname -s)

BASEPATH = /disk1/dev/main
INCLUDEDIRS = -I .              \
    -I ..              \
    -I /usr/include            \
    -I /usr/include/CC $(INCLUDE)

LIBDIRS  = $(PLIBDIRS) -L ../base
LIBS  = $(PLIBS) -lc
OBJPATH  =

ifeq ($(OSTYPE), IRIX64)

CC   = CC
AR   = ar
DEBUG  = -g3
SYMBOLS  = -D__unix -D__IX__ -DIRIX -D$(CPUTYPE) $(ADDSYMS)
CCOPTS  = -c -ignore_suffix -n32 -woff 1155 $(SYMBOLS) -LANG:std  \
    -LANG:namespaces=ON $(DEBUG) $(INCLUDEDIRS)
STDHEADER = $(BASEPATH)/common/SystemHeaders/IxSysHeaders.h

endif

ifeq ($(OSTYPE), IRIX)

CC   = CC
AR   = ar
DEBUG  = -g3
SYMBOLS  = -D__unix -D__IX__ -DIRIX -D$(CPUTYPE) $(ADDSYMS)
CCOPTS  = -c -ignore_suffix -n32 -woff 1155 $(SYMBOLS) -LANG:std  \
    -LANG:namespaces=ON $(DEBUG) $(INCLUDEDIRS)
STDHEADER = $(BASEPATH)/common/SystemHeaders/IxSysHeaders.h

endif

ifeq ($(OSTYPE), Linux)

CC   = gcc
AR   = ar
DEBUG  =
SYMBOLS  = -D__unix -D__IX__ -DLINUX -D$(CPUTYPE) -D_REENTRANT
$(ADDSYMS)
CCOPTS  = -c $(SYMBOLS) $(DEBUG) $(INCLUDEDIRS)

endif

I hope this helps you out...

Later,
Michael Uman
Sr. Software Engineer
Sonic Solutions


> All,

> I have some code which needs to compile on solaris 2.5.1 and
> solaris 2.7. There are some minor probs with RPC code which
> could easily be solved with some conditional compilations

> Is the some #define somewhere which I can use to differentiate
> between the two OS.

> ie

> #ifdef SOL_251
> Do solaris 2.5.1 code
> #else
> Do solaris 2.7 code
> #endif

> I working on Sun sparc workstation, using SC5.0 compiler.

> Any help much appreciated

> Regards
> Stuart

> Sent via Deja.com
> http://www.deja.com/