[cfe-commits] [llvm-commits] Ping^2: Fix for bug 11060: configure --target does not work

Sebastian Pop spop at codeaurora.org
Fri Oct 21 15:36:56 PDT 2011


On Fri, Oct 21, 2011 at 5:23 PM, Eric Christopher <echristo at apple.com> wrote:
> *shrug* After some discussion I can't come up with a reason why not that
> isn't something we already have a problem with :)
> So if you send me another diff I'll check it in.

I attached the updated patches on top of the latest trunk.
Thanks Eric for your fast review!

Sebastian
--
Qualcomm Innovation Center, Inc is a member of Code Aurora Forum
-------------- next part --------------
From 39dad21c93d03837ffb555eefaa1761cef77793c Mon Sep 17 00:00:00 2001
From: Sebastian Pop <spop at codeaurora.org>
Date: Tue, 11 Oct 2011 12:04:55 -0500
Subject: [PATCH] add getDefaultTargetTriple

---
 autoconf/configure.ac                   |    2 ++
 configure                               |    5 +++++
 include/llvm/Config/config.h.cmake      |    3 +++
 include/llvm/Config/config.h.in         |    3 +++
 include/llvm/Config/llvm-config.h.cmake |    3 +++
 include/llvm/Config/llvm-config.h.in    |    3 +++
 include/llvm/Support/Host.h             |    9 +++++++++
 lib/Support/Unix/Host.inc               |   19 +++++++++++++------
 lib/Support/Windows/Host.inc            |    5 +++++
 9 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index b8b61bc..967b085 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1467,6 +1467,8 @@ AC_DEFINE_UNQUOTED(LLVM_CONFIGTIME, "$LLVM_CONFIGTIME",
                    [Time at which LLVM was configured])
 AC_DEFINE_UNQUOTED(LLVM_HOSTTRIPLE, "$host",
                    [Host triple we were built on])
+AC_DEFINE_UNQUOTED(LLVM_DEFAULT_TARGET_TRIPLE, "$target",
+                   [Default target triple to build for])
 
 # Determine which bindings to build.
 if test "$BINDINGS_TO_BUILD" = auto ; then
diff --git a/configure b/configure
index c8b3c76..ecdbe98 100755
--- a/configure
+++ b/configure
@@ -20885,6 +20885,11 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+cat >>confdefs.h <<_ACEOF
+#define LLVM_DEFAULT_TARGET_TRIPLE "$target"
+_ACEOF
+
+
 # Determine which bindings to build.
 if test "$BINDINGS_TO_BUILD" = auto ; then
   BINDINGS_TO_BUILD=""
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index e44d429..9c56c99 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -557,6 +557,9 @@
 /* Host triple we were built on */
 #cmakedefine LLVM_HOSTTRIPLE "${LLVM_HOSTTRIPLE}"
 
+/* Default target triple to build for */
+#cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}"
+
 /* Installation directory for include files */
 #cmakedefine LLVM_INCLUDEDIR "${LLVM_INCLUDEDIR}"
 
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 86f4e77..b396d38 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -543,6 +543,9 @@
 /* Installation directory for data files */
 #undef LLVM_DATADIR
 
+/* Default target triple to build for */
+#undef LLVM_DEFAULT_TARGET_TRIPLE
+
 /* Installation directory for documentation */
 #undef LLVM_DOCSDIR
 
diff --git a/include/llvm/Config/llvm-config.h.cmake b/include/llvm/Config/llvm-config.h.cmake
index 4147fd1..ff3ab74 100644
--- a/include/llvm/Config/llvm-config.h.cmake
+++ b/include/llvm/Config/llvm-config.h.cmake
@@ -37,6 +37,9 @@
 /* Host triple we were built on */
 #cmakedefine LLVM_HOSTTRIPLE "${LLVM_HOSTTRIPLE}"
 
+/* Default target triple to build for */
+#cmakedefine LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}"
+
 /* Installation directory for include files */
 #cmakedefine LLVM_INCLUDEDIR "${LLVM_INCLUDEDIR}"
 
diff --git a/include/llvm/Config/llvm-config.h.in b/include/llvm/Config/llvm-config.h.in
index b2257f3..49288fd 100644
--- a/include/llvm/Config/llvm-config.h.in
+++ b/include/llvm/Config/llvm-config.h.in
@@ -37,6 +37,9 @@
 /* Host triple we were built on */
 #undef LLVM_HOSTTRIPLE
 
+/* Default target triple to build for */
+#undef LLVM_DEFAULT_TARGET_TRIPLE
+
 /* Installation directory for include files */
 #undef LLVM_INCLUDEDIR
 
diff --git a/include/llvm/Support/Host.h b/include/llvm/Support/Host.h
index f77d4c1..ec17a4d 100644
--- a/include/llvm/Support/Host.h
+++ b/include/llvm/Support/Host.h
@@ -33,6 +33,15 @@ namespace sys {
     return !isLittleEndianHost();
   }
 
+  /// getDefaultTargetTriple() - Return the triple of the default
+  /// target system.
+  ///
+  /// The target triple is a string in the format of:
+  ///   CPU_TYPE-VENDOR-OPERATING_SYSTEM
+  /// or
+  ///   CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
+  std::string getDefaultTargetTriple();
+
   /// getHostTriple() - Return the target triple of the running
   /// system.
   ///
diff --git a/lib/Support/Unix/Host.inc b/lib/Support/Unix/Host.inc
index dda3ce2..f76ed2a 100644
--- a/lib/Support/Unix/Host.inc
+++ b/lib/Support/Unix/Host.inc
@@ -35,12 +35,9 @@ static std::string getOSVersion() {
   return info.release;
 }
 
-std::string sys::getHostTriple() {
-  // FIXME: Derive directly instead of relying on the autoconf generated
-  // variable.
-
-  StringRef HostTripleString(LLVM_HOSTTRIPLE);
-  std::pair<StringRef, StringRef> ArchSplit = HostTripleString.split('-');
+static std::string getTriple(const char *name) {
+  StringRef TripleString(name);
+  std::pair<StringRef, StringRef> ArchSplit = TripleString.split('-');
 
   // Normalize the arch, since the host triple may not actually match the host.
   std::string Arch = ArchSplit.first;
@@ -64,3 +61,13 @@ std::string sys::getHostTriple() {
 
   return Triple;
 }
+
+std::string sys::getDefaultTargetTriple() {
+  return getTriple(LLVM_DEFAULT_TARGET_TRIPLE);
+}
+
+std::string sys::getHostTriple() {
+  // FIXME: Derive directly instead of relying on the autoconf generated
+  // variable.
+  return getTriple(LLVM_HOSTTRIPLE);
+}
diff --git a/lib/Support/Windows/Host.inc b/lib/Support/Windows/Host.inc
index 733830e..278550a 100644
--- a/lib/Support/Windows/Host.inc
+++ b/lib/Support/Windows/Host.inc
@@ -21,3 +21,8 @@ std::string sys::getHostTriple() {
   // FIXME: Adapt to running version.
   return LLVM_HOSTTRIPLE;
 }
+
+std::string sys::getDefaultTargetTriple() {
+  // FIXME: Adapt to running version.
+  return LLVM_DEFAULT_TARGET_TRIPLE;
+}
-- 
1.7.4.1

-------------- next part --------------
From eb47d369001282840407fd8a1a3460a37dc7aab6 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <spop at codeaurora.org>
Date: Tue, 11 Oct 2011 12:07:51 -0500
Subject: [PATCH] use getDefaultTargetTriple instead of getHostTriple

---
 examples/clang-interpreter/main.cpp              |    2 +-
 lib/Frontend/CompilerInvocation.cpp              |    4 ++--
 lib/Frontend/CreateInvocationFromCommandLine.cpp |    2 +-
 tools/driver/cc1as_main.cpp                      |    4 ++--
 tools/driver/driver.cpp                          |    2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp
index c9734e5..4192c09 100644
--- a/examples/clang-interpreter/main.cpp
+++ b/examples/clang-interpreter/main.cpp
@@ -76,7 +76,7 @@ int main(int argc, const char **argv, char * const *envp) {
 
   llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
   DiagnosticsEngine Diags(DiagID, DiagClient);
-  Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
+  Driver TheDriver(Path.str(), llvm::sys::getDefaultTargetTriple(),
                    "a.out", /*IsProduction=*/false, Diags);
   TheDriver.setTitle("clang interpreter");
 
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 76ceb9b..08622e8 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1909,9 +1909,9 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
   Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version);
   Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
 
-  // Use the host triple if unspecified.
+  // Use the default target triple if unspecified.
   if (Opts.Triple.empty())
-    Opts.Triple = llvm::sys::getHostTriple();
+    Opts.Triple = llvm::sys::getDefaultTargetTriple();
 }
 
 //
diff --git a/lib/Frontend/CreateInvocationFromCommandLine.cpp b/lib/Frontend/CreateInvocationFromCommandLine.cpp
index fc15081..e94b944 100644
--- a/lib/Frontend/CreateInvocationFromCommandLine.cpp
+++ b/lib/Frontend/CreateInvocationFromCommandLine.cpp
@@ -48,7 +48,7 @@ clang::createInvocationFromCommandLine(ArrayRef<const char *> ArgList,
   Args.push_back("-fsyntax-only");
 
   // FIXME: We shouldn't have to pass in the path info.
-  driver::Driver TheDriver("clang", llvm::sys::getHostTriple(),
+  driver::Driver TheDriver("clang", llvm::sys::getDefaultTargetTriple(),
                            "a.out", false, *Diags);
 
   // Don't check that inputs exist, they may have been remapped.
diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp
index 4215a32..5a17512 100644
--- a/tools/driver/cc1as_main.cpp
+++ b/tools/driver/cc1as_main.cpp
@@ -151,8 +151,8 @@ void AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
 
   // Target Options
   Opts.Triple = Triple::normalize(Args->getLastArgValue(OPT_triple));
-  if (Opts.Triple.empty()) // Use the host triple if unspecified.
-    Opts.Triple = sys::getHostTriple();
+  if (Opts.Triple.empty()) // Use the default target triple if unspecified.
+    Opts.Triple = sys::getDefaultTargetTriple();
 
   // Language Options
   Opts.IncludePaths = Args->getAllArgValues(OPT_I);
diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp
index bd1d2a2..4f5d3fe 100644
--- a/tools/driver/driver.cpp
+++ b/tools/driver/driver.cpp
@@ -382,7 +382,7 @@ int main(int argc_, const char **argv_) {
 #else
   const bool IsProduction = false;
 #endif
-  Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
+  Driver TheDriver(Path.str(), llvm::sys::getDefaultTargetTriple(),
                    "a.out", IsProduction, Diags);
 
   // Attempt to find the original path used to invoke the driver, to determine
-- 
1.7.4.1



More information about the cfe-commits mailing list