blob: 4935a8cad02b67e99fd8009e1ecd2465fcfb0151 [file] [log] [blame]
# -*- Makefile -*-
#
# $Id$
#
# configuration file for gcc
#
##############################################################################
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed
# with this work for additional information regarding copyright
# ownership. The ASF licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# Copyright 1999-2007 Rogue Wave Software, Inc.
#
##############################################################################
CXX = gcc
CCVER := $(shell $(CXX) -dumpversion | sed "s/[^0-9]*\([0-9.]*\).*/\1/g")
# determine the major version of gcc
CXX_MAJOR := $(shell echo "$(CCVER)" | sed "s/^\([1-9][0-9]*\).*/\1/")
CXX_MINOR := $(shell echo "$(CCVER)" | sed "s/[1-9]*\.\([0-9]*\).*/\1/")
# determine the major and minor version of the OS when needed
ifeq ($(OSNAME),AIX)
OS_MAJOR := $(shell uname -v)
OS_MINOR := $(shell uname -r)
else
ifeq ($(OSNAME),Darwin)
OS_MAJOR := $(shell uname -r | sed "s/^\([1-9]*\).*/\1/")
OS_MINOR := $(shell uname -r | sed "s/^[1-9][0-9]*\.\([1-9]*\).*/\1/")
endif
endif
# -W and -Wextra are the same
WARNFLAGS = -W -Wall -Wcast-qual -Winline -Wshadow -Wwrite-strings
# -Wno-long-long not available prior to 2.90
ifeq ($(shell [ $(CXX_MAJOR) -gt 2 -o $(CXX_MAJOR) -eq 2 \
-a $(CXX_MINOR) -ge 90 ] && echo 1), 1)
WARNFLAGS += -Wno-long-long
endif # gcc >= 2.90
# prevent (bogus?) warnings on SunOS
ifneq ($(OSNAME),SunOS)
WARNFLAGS += -Wcast-align
else
# prevent gcc 3.x warnings about #pragma ident on SunOS
ifeq ($(CXX_MAJOR),3)
ifeq ($(shell expr $(CXX_MINOR) \< 4),1)
WARNFLAGS += -Wno-unknown-pragmas
endif # gcc < 3.4
endif # gcc == 3.x
endif # !SunOS
# do not enable -Wunreachable-code: it's useless the way implemented
# ifeq ($(shell expr $(CXX_MAJOR) \> 3 \& $(CXX_MINOR) \> 3),1)
# WARNFLAGS += -Wunreachable-code
# endif # gcc > 3.3
DEPENDFLAGS = -M
# avoid adding -FPIC on IBM AIX and Cygwin where
# gcc generated code is always position independent
ifeq (,$(findstring AIX,$(OSNAME)))
ifeq (,$(findstring CYGWIN,$(OSNAME)))
PICFLAGS = -fPIC
endif
endif
ifeq ($(OSNAME),SunOS)
# linker flags for symbol versioning
# temporarily disabled (not fully implemented)
# MAPFLAGS = -Wl,-M
endif
ifneq ($(MAPFLAGS),)
# path to mapfile (relative to $(TOPDIR)) for symbol versioning
ifneq ($(CXX_MAJOR),2)
MAPFILE = src/mapfile.$(CXX)
else
# gcc 2.x implements a different ABI than gcc 3
MAPFILE = src/mapfile.$(CXX)-$(CXX_MAJOR)
endif
endif
ifneq ($(OSNAME),Darwin)
# no -shared option for GCC on Mac OS X (Darwin)
LDSOFLAGS = -shared
else
# flags needed when linking the library
LDSOFLAGS = -dynamiclib \
-compatibility_version 4 -current_version $(LIBVER)
# use appropriate install_name
ifeq ($(shell [ $(OS_MAJOR) -ge 9 ] && echo 1), 1)
LDSOFLAGS += -install_name @rpath/$(LIBNAME)
else
LDSOFLAGS += -install_name $(LIBNAME)
endif
endif
# -fPIC needed both to compile and link shared libs on HP-UX 11
ifeq ($(OSNAME),HP-UX)
LDSOFLAGS += -fPIC
endif
ifeq ($(CXX_MAJOR),3)
ifeq ($(shell [ $(CXX_MINOR) -lt 4 ] && echo 1),1)
# for gcc 3 prior to gcc 3.4 force linking with libgcc_s.so
# and avoid linking with libgcc_s.a to get stack unwinding
# due to exceptions right (see STDCXX-369)
LDSOFLAGS += -shared-libgcc
endif
endif
CXXFLAGS = -pedantic -nostdinc++
ifeq ($(CXX_MAJOR),2)
ifeq ($(shell expr $(CXX_MINOR) / 10),9)
CXXFLAGS += -fhonor-std -ftemplate-depth-32
else
CXXFLAGS += -ftemplate-depth-32
endif
endif
ifeq ($(OSNAME),IRIX64)
ifeq ($(CXX_MAJOR),2)
# prevent (some) assembler errors caused by overly long symbol
# names (the option is not supported in gcc 3 and beyond)
CXXFLAGS += -fsquangle
endif
# disable ld warnings about libs not used to resolve any symbols
LDFLAGS += -Wl,-woff,84
endif
# prevent (some) assemler errors caused by overly long symbol names
ifeq ($(OSNAME),OSF1)
CXXFLAGS += -fsquangle
endif
CXXPRELINK =
# enable C++ C library headers (the <cname> kind)
CPPFLAGS = -I$(TOPDIR)/include/ansi
# decrease warning level to prevent annoying linker warnings
# about duplicate symbols (the linker has no concept of weak symbols)
ifeq ($(OSNAME),AIX)
LDFLAGS = -Wl,-bh:5
endif
ifneq ($(CXX_MAJOR),2)
# gcc 3.x needs to explicitly link with libsupc++ for language support
# g++ 3.x links with it as well as libstdc++ automatically
# Recently, Apple ships a C++ compiler based on LLVM which does not
# include a C++ support library; gcc builds on Darwin require a stock
# GNU compiler
LDLIBS = -lsupc++
endif # gcc > 2
# The flag(s) to use to embed a library search path into generated executables.
ifeq ($(OSNAME),Linux)
RPATH = -Wl,-R
else
ifeq ($(OSNAME),SunOS)
RPATH = -Wl,-R
else
ifeq ($(OSNAME),AIX)
ifeq ($(shell [ $(OS_MAJOR) -gt 5 -o $(OS_MAJOR) -eq 5 \
-a $(OS_MINOR) -ge 3 ] && echo 1), 1)
# -bsrv4, -R only available on AIX 5.3 and newer
RPATH = -Wl,-bsvr4,-R
endif
else
ifeq ($(OSNAME),HP-UX)
RPATH = -Wl,+b
else
ifeq ($(OSNAME),IRIX64)
RPATH = -Wl,-rpath,
else
ifeq ($(OSNAME),OSF1)
RPATH = -Wl,-rpath,
endif
endif
endif
endif
endif
endif
ifeq ($(OSNAME),Darwin)
ifeq ($(shell [ $(OS_MAJOR) -ge 9 ] && echo 1), 1)
RPATH = -Wl,-rpath,
endif
endif
# debug/optimization options
DEBUG_CXXFLAGS = -g
DEBUG_CPPFLAGS =
OPTMZ_CXXFLAGS = -O2
OPTMZ_CPPFLAGS =
# shared/static library options
SHARED_CXXFLAGS =
SHARED_CPPFLAGS =
SHARED_LDFLAGS =
ifeq ($(OSNAME),AIX)
SHARED_SUFFIX = .a
endif
ifeq ($(OSNAME),HP-UX)
SHARED_SUFFIX = .sl
endif
ifeq ($(OSNAME),Darwin)
SHARED_SUFFIX = .dylib
endif
ifneq ($(findstring CYGWIN,$(OSNAME)),)
SHARED_SUFFIX = .dll
SHARED_CPPFLAGS += -D_RWSHARED
LDFLAGS += -Wl,-force-exe-suffix
endif
STATIC_CXXFLAGS =
STATIC_CPPFLAGS =
STATIC_LDFLAGS =
# compiler and linker flags for thread safety
# use undocumented (though long implemented) gcc option -pthread
# which defines _REENTRANT;
# the same option is named -pthreads on Solaris
ifeq ($(findstring CYGWIN,$(OSNAME)),)
ifeq ($(OSNAME),SunOS)
MULTI_CPPFLAGS_POSIX = -pthreads
MULTI_LDFLAGS_POSIX = -pthreads
else
ifeq ($(OSNAME),IRIX64)
# no -pthreads option (or similar) on IRIX?
MULTI_CPPFLAGS_POSIX = -D_REENTRANT
MULTI_LDFLAGS_POSIX = -lpthread
else
# option doesn't exist in Darwin gcc
ifneq ($(OSNAME),Darwin)
MULTI_CPPFLAGS_POSIX = -pthread
MULTI_LDFLAGS_POSIX = -pthread
endif
endif
endif
else
# on Cygwin use MingW-threads by default
# -mthreads not defines _REENTRANT
MULTI_CPPFLAGS_POSIX = -D_REENTRANT -mthreads
MULTI_LDFLAGS_POSIX = -mthreads
# link with libcatgets and libiconv
LDLIBS += -lcatgets -liconv
endif
MULTI_CPPFLAGS_SOLARIS = -threads
MULTI_LDFLAGS_SOLARIS = -threads
MULTI_CPPFLAGS_DCE =
MULTI_LDFLAGS_DCE =
# POSIX
MULTI_CPPFLAGS = $(MULTI_CPPFLAGS_POSIX)
MULTI_LDFLAGS = $(MULTI_LDFLAGS_POSIX)
SINGL_CPPFLAGS =
SINGL_LDFLAGS =
# gcc can generate 32-bit or 64-bit code by default, depending
# on how it's configured
# determine whether the default compiler invocation produces
# wide (64-bit) or narrow (32-bit) code and set compiler,
# linker, and other options accordingly
wide = $(shell cd /tmp; tmpfile=stdcxx-longsize-$$; export tmpfile; \
echo "int main() { return 8 == sizeof (long); }" \
> $$tmpfile.c \
&& $(CXX) $$tmpfile.c >/dev/null 2>&1 -o $$tmpfile; \
./$$tmpfile; echo $$?; rm -f $$tmpfile.c $$tmpfile)
ifeq ($(wide),0)
# narrow (32-bit) mode is implicit
# use wide (64-bit) flags to explicitly enable LP64 mode
ifeq ($(OSNAME),HP-UX)
# -milp32 and -mlp64 are options specific to HP-UX
CXXFLAGS.wide = -mlp64
LDFLAGS.wide = -mlp64
LDSOFLAGS.wide = -mlp64
ARFLAGS.wide =
else
CXXFLAGS.wide = -m64
LDFLAGS.wide = -m64
LDSOFLAGS.wide = -m64
ARFLAGS.wide =
endif
else
# wide (64-bit) mode is implicit
# use narrow (32-bit) flags to explicitly enable ILP32 mode
ifeq ($(OSNAME),HP-UX)
CXXFLAGS.narrow = -milp32
LDFLAGS.narrow = -milp32
LDSOFLAGS.narrow = -milp32
ARFLAGS.narrow =
else
CXXFLAGS.narrow = -m32
LDFLAGS.narrow = -m32
LDSOFLAGS.narrow = -m32
ARFLAGS.narrow =
endif
endif