The attached patches attempt to fix cross builds. For example, if you

try to use i686-darwin to build for arm-eabi, you'll quickly run into
several false assumptions that the target OS must be the same as the
host OS. These patches split $(OS) into $(HOST_OS) and $(TARGET_OS) to
help builds like "make check" and the test-suite able to cross
compile. Along the way a target of *-unknown-eabi is defined as
"Freestanding" so that TARGET_OS checks have something to work with.

Patch by Sandeep Patel!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79296 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anton Korobeynikov 2009-08-18 00:40:33 +00:00
parent e1b80b6946
commit e55db74152
9 changed files with 82 additions and 26 deletions

View File

@ -89,8 +89,11 @@ PROJ_mandir := $(DESTDIR)$(PROJ_prefix)/share/man
LLVM_ON_UNIX:=@LLVM_ON_UNIX@ LLVM_ON_UNIX:=@LLVM_ON_UNIX@
LLVM_ON_WIN32:=@LLVM_ON_WIN32@ LLVM_ON_WIN32:=@LLVM_ON_WIN32@
# Target operating system for which LLVM will be compiled. # Host operating system for which LLVM will be run.
OS=@OS@ OS=@OS@
HOST_OS=@HOST_OS@
# Target operating system for which LLVM will compile for.
TARGET_OS=@TARGET_OS@
# Target hardware architecture # Target hardware architecture
ARCH=@ARCH@ ARCH=@ARCH@
@ -128,6 +131,7 @@ LDFLAGS+=@LDFLAGS@
# Path to the library archiver program. # Path to the library archiver program.
AR_PATH = @AR@ AR_PATH = @AR@
AR = @AR@
# Path to the nm program # Path to the nm program
NM_PATH = @NM@ NM_PATH = @NM@

View File

@ -287,7 +287,7 @@ CPP.Defines :=
# OPTIMIZE_OPTION - The optimization level option we want to build LLVM with # OPTIMIZE_OPTION - The optimization level option we want to build LLVM with
# this can be overridden on the make command line. # this can be overridden on the make command line.
ifndef OPTIMIZE_OPTION ifndef OPTIMIZE_OPTION
ifneq ($(OS),MingW) ifneq ($(HOST_OS),MingW)
OPTIMIZE_OPTION := -O3 OPTIMIZE_OPTION := -O3
else else
OPTIMIZE_OPTION := -O2 OPTIMIZE_OPTION := -O2
@ -297,8 +297,8 @@ endif
ifeq ($(ENABLE_OPTIMIZED),1) ifeq ($(ENABLE_OPTIMIZED),1)
BuildMode := Release BuildMode := Release
# Don't use -fomit-frame-pointer on Darwin or FreeBSD. # Don't use -fomit-frame-pointer on Darwin or FreeBSD.
ifneq ($(OS),FreeBSD) ifneq ($(HOST_OS),FreeBSD)
ifneq ($(OS),Darwin) ifneq ($(HOST_OS),Darwin)
OmitFramePointer := -fomit-frame-pointer OmitFramePointer := -fomit-frame-pointer
endif endif
endif endif
@ -306,7 +306,7 @@ ifeq ($(ENABLE_OPTIMIZED),1)
# Darwin requires -fstrict-aliasing to be explicitly enabled. # Darwin requires -fstrict-aliasing to be explicitly enabled.
# Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues # Avoid -fstrict-aliasing on Darwin for now, there are unresolved issues
# with -fstrict-aliasing and ipa-type-escape radr://6756684 # with -fstrict-aliasing and ipa-type-escape radr://6756684
#ifeq ($(OS),Darwin) #ifeq ($(HOST_OS),Darwin)
# EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing # EXTRA_OPTIONS += -fstrict-aliasing -Wstrict-aliasing
#endif #endif
CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer) CXX.Flags += $(OPTIMIZE_OPTION) $(OmitFramePointer)
@ -379,10 +379,10 @@ ifdef SHARED_LIBRARY
endif endif
ifeq ($(ENABLE_PIC),1) ifeq ($(ENABLE_PIC),1)
ifeq ($(OS), $(filter $(OS), Cygwin MingW)) ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
# Nothing. Win32 defaults to PIC and warns when given -fPIC # Nothing. Win32 defaults to PIC and warns when given -fPIC
else else
ifeq ($(OS),Darwin) ifeq ($(HOST_OS),Darwin)
# Common symbols not allowed in dylib files # Common symbols not allowed in dylib files
CXX.Flags += -fno-common CXX.Flags += -fno-common
C.Flags += -fno-common C.Flags += -fno-common
@ -393,7 +393,7 @@ ifeq ($(ENABLE_PIC),1)
endif endif
endif endif
else else
ifeq ($(OS),Darwin) ifeq ($(HOST_OS),Darwin)
CXX.Flags += -mdynamic-no-pic CXX.Flags += -mdynamic-no-pic
C.Flags += -mdynamic-no-pic C.Flags += -mdynamic-no-pic
endif endif
@ -420,7 +420,7 @@ ifeq ($(ARCH),Alpha)
LD.Flags += -Wl,--no-relax LD.Flags += -Wl,--no-relax
endif endif
ifeq ($(OS),MingW) ifeq ($(HOST_OS),MingW)
ifeq ($(LLVM_CROSS_COMPILING),1) ifeq ($(LLVM_CROSS_COMPILING),1)
# Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016 # Work around http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525016
ifdef TOOLNAME ifdef TOOLNAME
@ -502,7 +502,7 @@ endif
# Adjust to user's request # Adjust to user's request
#-------------------------------------------------------------------- #--------------------------------------------------------------------
ifeq ($(OS),Darwin) ifeq ($(HOST_OS),Darwin)
DARWIN_VERSION := `sw_vers -productVersion` DARWIN_VERSION := `sw_vers -productVersion`
# Strip a number like 10.4.7 to 10.4 # Strip a number like 10.4.7 to 10.4
DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/') DARWIN_VERSION := $(shell echo $(DARWIN_VERSION)| sed -E 's/(10.[0-9]).*/\1/')
@ -511,9 +511,8 @@ ifeq ($(OS),Darwin)
SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \ SharedLinkOptions=-Wl,-flat_namespace -Wl,-undefined -Wl,suppress \
-dynamiclib -mmacosx-version-min=$(DARWIN_VERSION) -dynamiclib -mmacosx-version-min=$(DARWIN_VERSION)
TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
else else
ifeq ($(OS),Cygwin) ifeq ($(HOST_OS),Cygwin)
SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \ SharedLinkOptions=-shared -nostdlib -Wl,--export-all-symbols \
-Wl,--enable-auto-import -Wl,--enable-auto-image-base -Wl,--enable-auto-import -Wl,--enable-auto-image-base
else else
@ -521,6 +520,10 @@ else
endif endif
endif endif
ifeq ($(TARGET_OS),Darwin)
TargetCommonOpts += -mmacosx-version-min=$(DARWIN_VERSION)
endif
# Adjust LD.Flags depending on the kind of library that is to be built. Note # Adjust LD.Flags depending on the kind of library that is to be built. Note
# that if LOADABLE_MODULE is specified then the resulting shared library can # that if LOADABLE_MODULE is specified then the resulting shared library can
# be opened with dlopen. # be opened with dlopen.
@ -558,7 +561,7 @@ ifndef KEEP_SYMBOLS
endif endif
# Adjust linker flags for building an executable # Adjust linker flags for building an executable
ifneq ($(OS),Darwin) ifneq ($(HOST_OS),Darwin)
ifneq ($(DARWIN_MAJVERS),4) ifneq ($(DARWIN_MAJVERS),4)
ifdef TOOLNAME ifdef TOOLNAME
ifdef EXAMPLE_TOOL ifdef EXAMPLE_TOOL
@ -580,7 +583,7 @@ endif
CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \ CompileCommonOpts += -Wall -W -Wno-unused-parameter -Wwrite-strings \
$(EXTRA_OPTIONS) $(EXTRA_OPTIONS)
ifeq ($(OS),HP-UX) ifeq ($(HOST_OS),HP-UX)
CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE CompileCommonOpts := -D_REENTRANT -D_HPUX_SOURCE
endif endif
@ -608,7 +611,7 @@ ifdef UNIVERSAL
# Building universal cannot compute dependencies automatically. # Building universal cannot compute dependencies automatically.
DISABLE_AUTO_DEPENDENCIES=1 DISABLE_AUTO_DEPENDENCIES=1
else else
ifeq ($(OS),Darwin) ifeq ($(TARGET_OS),Darwin)
ifeq ($(ARCH),x86_64) ifeq ($(ARCH),x86_64)
TargetCommonOpts = -m64 TargetCommonOpts = -m64
else else
@ -619,7 +622,7 @@ else
endif endif
endif endif
ifeq ($(OS),SunOS) ifeq ($(HOST_OS),SunOS)
CPP.BaseFlags += -include llvm/System/Solaris.h CPP.BaseFlags += -include llvm/System/Solaris.h
endif endif
@ -1172,7 +1175,7 @@ endif
# not exporting all of the weak symbols from the binary. This reduces dyld # not exporting all of the weak symbols from the binary. This reduces dyld
# startup time by 4x on darwin in some cases. # startup time by 4x on darwin in some cases.
ifdef TOOL_NO_EXPORTS ifdef TOOL_NO_EXPORTS
ifeq ($(OS),Darwin) ifeq ($(HOST_OS),Darwin)
# Tiger tools don't support this. # Tiger tools don't support this.
ifneq ($(DARWIN_MAJVERS),4) ifneq ($(DARWIN_MAJVERS),4)
@ -1180,7 +1183,7 @@ LD.Flags += -Wl,-exported_symbol -Wl,_main
endif endif
endif endif
ifeq ($(OS), $(filter $(OS), Linux NetBSD FreeBSD)) ifeq ($(HOST_OS), $(filter $(HOST_OS), Linux NetBSD FreeBSD))
LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map LD.Flags += -Wl,--version-script=$(LLVM_SRC_ROOT)/autoconf/ExportMap.map
endif endif
endif endif
@ -1234,7 +1237,7 @@ endif
############################################################################### ###############################################################################
# FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX" # FIXME: This should be checking for "if not GCC or ICC", not for "if HP-UX"
ifeq ($(OS),HP-UX) ifeq ($(HOST_OS),HP-UX)
DISABLE_AUTO_DEPENDENCIES=1 DISABLE_AUTO_DEPENDENCIES=1
endif endif

View File

@ -175,6 +175,16 @@ AC_CACHE_CHECK([type of operating system we're going to host on],
llvm_cv_no_link_all_option="-Wl,--no-whole-archive" llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
llvm_cv_os_type="MingW" llvm_cv_os_type="MingW"
llvm_cv_platform_type="Win32" ;; llvm_cv_platform_type="Win32" ;;
*-unknown-eabi*)
llvm_cv_link_all_option="-Wl,--whole-archive"
llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
llvm_cv_os_type="Freestanding"
llvm_cv_platform_type="Unix" ;;
*-unknown-elf*)
llvm_cv_link_all_option="-Wl,--whole-archive"
llvm_cv_no_link_all_option="-Wl,--no-whole-archive"
llvm_cv_os_type="Freestanding"
llvm_cv_platform_type="Unix" ;;
*) *)
llvm_cv_link_all_option="" llvm_cv_link_all_option=""
llvm_cv_no_link_all_option="" llvm_cv_no_link_all_option=""
@ -182,6 +192,43 @@ AC_CACHE_CHECK([type of operating system we're going to host on],
llvm_cv_platform_type="Unknown" ;; llvm_cv_platform_type="Unknown" ;;
esac]) esac])
AC_CACHE_CHECK([type of operating system we're going to target],
[llvm_cv_target_os_type],
[case $target in
*-*-aix*)
llvm_cv_target_os_type="AIX" ;;
*-*-irix*)
llvm_cv_target_os_type="IRIX" ;;
*-*-cygwin*)
llvm_cv_target_os_type="Cygwin" ;;
*-*-darwin*)
llvm_cv_target_os_type="Darwin" ;;
*-*-freebsd*)
llvm_cv_target_os_type="FreeBSD" ;;
*-*-openbsd*)
llvm_cv_target_os_type="OpenBSD" ;;
*-*-netbsd*)
llvm_cv_target_os_type="NetBSD" ;;
*-*-dragonfly*)
llvm_cv_target_os_type="DragonFly" ;;
*-*-hpux*)
llvm_cv_target_os_type="HP-UX" ;;
*-*-interix*)
llvm_cv_target_os_type="Interix" ;;
*-*-linux*)
llvm_cv_target_os_type="Linux" ;;
*-*-solaris*)
llvm_cv_target_os_type="SunOS" ;;
*-*-win32*)
llvm_cv_target_os_type="Win32" ;;
*-*-mingw*)
llvm_cv_target_os_type="MingW" ;;
*-unknown-eabi*)
llvm_cv_target_os_type="Freestanding" ;;
*)
llvm_cv_target_os_type="Unknown" ;;
esac])
dnl Make sure we aren't attempting to configure for an unknown system dnl Make sure we aren't attempting to configure for an unknown system
if test "$llvm_cv_os_type" = "Unknown" ; then if test "$llvm_cv_os_type" = "Unknown" ; then
AC_MSG_ERROR([Operating system is unknown, configure can't continue]) AC_MSG_ERROR([Operating system is unknown, configure can't continue])
@ -190,6 +237,8 @@ fi
dnl Set the "OS" Makefile variable based on the platform type so the dnl Set the "OS" Makefile variable based on the platform type so the
dnl makefile can configure itself to specific build hosts dnl makefile can configure itself to specific build hosts
AC_SUBST(OS,$llvm_cv_os_type) AC_SUBST(OS,$llvm_cv_os_type)
AC_SUBST(HOST_OS,$llvm_cv_os_type)
AC_SUBST(TARGET_OS,$llvm_cv_target_os_type)
dnl Set the LINKALL and NOLINKALL Makefile variables based on the platform dnl Set the LINKALL and NOLINKALL Makefile variables based on the platform
AC_SUBST(LINKALL,$llvm_cv_link_all_option) AC_SUBST(LINKALL,$llvm_cv_link_all_option)

View File

@ -13,7 +13,7 @@ PARALLEL_DIRS = Utils Instrumentation Scalar IPO Hello
include $(LEVEL)/Makefile.config include $(LEVEL)/Makefile.config
# No support for plugins on windows targets # No support for plugins on windows targets
ifeq ($(OS), $(filter $(OS), Cygwin MingW)) ifeq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
PARALLEL_DIRS := $(filter-out Hello, $(PARALLEL_DIRS)) PARALLEL_DIRS := $(filter-out Hello, $(PARALLEL_DIRS))
endif endif

View File

@ -53,7 +53,7 @@ RUNTESTFLAGS += --ignore "$(strip $(IGNORE_TESTS))"
endif endif
# Both AuroraUX & Solaris do not have the -m flag for ulimit # Both AuroraUX & Solaris do not have the -m flag for ulimit
ifeq ($(OS),SunOS) ifeq ($(HOST_OS),SunOS)
ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -v 512000 ; ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -v 512000 ;
else else
ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -m 512000 ; ulimit -v 512000 ; ULIMIT=ulimit -t 600 ; ulimit -d 512000 ; ulimit -m 512000 ; ulimit -v 512000 ;
@ -93,7 +93,7 @@ clean::
$(RM) -rf `find $(LLVM_OBJ_ROOT)/test -name Output -type d -print` $(RM) -rf `find $(LLVM_OBJ_ROOT)/test -name Output -type d -print`
# dsymutil is used on the Darwin to manipulate DWARF debugging information. # dsymutil is used on the Darwin to manipulate DWARF debugging information.
ifeq ($(OS),Darwin) ifeq ($(TARGET_OS),Darwin)
DSYMUTIL=dsymutil DSYMUTIL=dsymutil
else else
DSYMUTIL=true DSYMUTIL=true

View File

@ -73,7 +73,7 @@ proc llvm2cpp-test { files } {
} }
set retval [ catch { set retval [ catch {
exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir -lLLVMCore -lLLVMSupport -lLLVMbzip2 -lLLVMSystem -lstdc++ } msg ] exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir -lLLVMCore -lLLVMSupport -lLLVMSystem -lstdc++ } msg ]
if { $retval != 0 } { if { $retval != 0 } {
fail "$test: gcc returned $retval\n$msg" fail "$test: gcc returned $retval\n$msg"
continue continue

View File

@ -39,7 +39,7 @@ ifeq ($(ENABLE_PIC),1)
endif endif
# No support for lto / gold on windows targets # No support for lto / gold on windows targets
ifeq ($(OS), $(filter $(OS), Cygwin MingW)) ifeq ($(TARGET_OS), $(filter $(TARGET_OS), Cygwin MingW))
DIRS := $(filter-out lto gold, $(DIRS)) DIRS := $(filter-out lto gold, $(DIRS))
endif endif

View File

@ -22,7 +22,7 @@ LINK_COMPONENTS := $(TARGETS_TO_BUILD) ipo scalaropts linker bitreader bitwriter
include $(LEVEL)/Makefile.common include $(LEVEL)/Makefile.common
ifeq ($(OS),Darwin) ifeq ($(HOST_OS),Darwin)
# set dylib internal version number to llvmCore submission number # set dylib internal version number to llvmCore submission number
ifdef LLVM_SUBMIT_VERSION ifdef LLVM_SUBMIT_VERSION
LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \ LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version \

View File

@ -18,7 +18,7 @@ BUILD_ARCHIVE = 1
CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include CPP.Flags += -I$(LLVM_SRC_ROOT)/utils/unittest/googletest/include
CPP.Flags += $(NO_MISSING_FIELD_INITIALIZERS) $(NO_VARIADIC_MACROS) CPP.Flags += $(NO_MISSING_FIELD_INITIALIZERS) $(NO_VARIADIC_MACROS)
ifeq ($(OS),MingW) ifeq ($(HOST_OS),MingW)
CPP.Flags += -DGTEST_OS_WINDOWS=1 CPP.Flags += -DGTEST_OS_WINDOWS=1
endif endif