gn build: Make check-{clang,lld,llvm} pass on FreeBSD.

Mostly achieved by assuming that anything that isn't Win or Mac is ELF,
which seems reasonable enough for now.

Differential Revision: https://reviews.llvm.org/D57870

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353470 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/gn/secondary/clang/tools/libclang/BUILD.gn b/utils/gn/secondary/clang/tools/libclang/BUILD.gn
index c2fad99..7417e59 100644
--- a/utils/gn/secondary/clang/tools/libclang/BUILD.gn
+++ b/utils/gn/secondary/clang/tools/libclang/BUILD.gn
@@ -12,8 +12,8 @@
 # - the GN build doesn't have LIBCLANG_BUILD_STATIC
 
 libclang_target_type = "shared_library"
-if (host_os == "linux") {
-  # Linux needs -fPIC to build shared libs but they aren't on by default.
+if (host_os != "win" && host_os != "mac") {
+  # ELF targets need -fPIC to build shared libs but they aren't on by default.
   # For now, make libclang a static lib there.
   libclang_target_type = "static_library"
 }
diff --git a/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
index ebeb6f3..4d0a3a8 100644
--- a/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ b/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -269,12 +269,12 @@
     ]
   }
 
-  if (current_os == "linux" || current_os == "android") {
-    values += [ "LTDL_SHLIB_EXT=.so" ]
-  } else if (current_os == "mac") {
+  if (current_os == "mac") {
     values += [ "LTDL_SHLIB_EXT=.dylib" ]
   } else if (current_os == "win") {
     values += [ "LTDL_SHLIB_EXT=.dll" ]
+  } else {
+    values += [ "LTDL_SHLIB_EXT=.so" ]
   }
 
   if (llvm_enable_libedit) {
diff --git a/utils/gn/secondary/llvm/lib/Transforms/Hello/BUILD.gn b/utils/gn/secondary/llvm/lib/Transforms/Hello/BUILD.gn
index 9240193..9e55578 100644
--- a/utils/gn/secondary/llvm/lib/Transforms/Hello/BUILD.gn
+++ b/utils/gn/secondary/llvm/lib/Transforms/Hello/BUILD.gn
@@ -11,9 +11,9 @@
     "Hello.cpp",
   ]
 
-  if (host_os == "linux") {
+  if (host_os != "mac" && host_os != "win") {
     # The GN build currently doesn't globally pass -fPIC, but that's
-    # needed for building .so files on Linux.  Just pass it manually
+    # needed for building .so files on ELF.  Just pass it manually
     # for loadable_modules for now.
     cflags = [ "-fPIC" ]
   }
diff --git a/utils/gn/secondary/llvm/test/BUILD.gn b/utils/gn/secondary/llvm/test/BUILD.gn
index 6da35dd..0dc292e 100644
--- a/utils/gn/secondary/llvm/test/BUILD.gn
+++ b/utils/gn/secondary/llvm/test/BUILD.gn
@@ -83,24 +83,28 @@
     assert(false, "unimplemented host_cpu " + host_cpu)
   }
 
+  if (host_os == "win") {
+    extra_values += [ "EXEEXT=.exe" ]
+  } else {
+    extra_values += [ "EXEEXT=" ]
+  }
+
   if (host_os == "mac") {
-    extra_values += [
-      "EXEEXT=",
-      "HOST_OS=Darwin",
-      "SHLIBEXT=.dylib",
-    ]
-  } else if (host_os == "linux") {
-    extra_values += [
-      "EXEEXT=",
-      "HOST_OS=Linux",
-      "SHLIBEXT=.so",
-    ]
+    extra_values += [ "SHLIBEXT=.dylib" ]
   } else if (host_os == "win") {
-    extra_values += [
-      "EXEEXT=.exe",
-      "HOST_OS=Windows",
-      "SHLIBEXT=.dll",
-    ]
+    extra_values += [ "SHLIBEXT=.dll" ]
+  } else {
+    extra_values += [ "SHLIBEXT=.so" ]
+  }
+
+  if (host_os == "freebsd") {
+    extra_values += [ "HOST_OS=FreeBSD" ]
+  } else if (host_os == "mac") {
+    extra_values += [ "HOST_OS=Darwin" ]
+  } else if (host_os == "linux") {
+    extra_values += [ "HOST_OS=Linux" ]
+  } else if (host_os == "win") {
+    extra_values += [ "HOST_OS=Windows" ]
   } else {
     assert(false, "unsupported host_os " + host_os)
   }
diff --git a/utils/gn/secondary/llvm/tools/bugpoint-passes/BUILD.gn b/utils/gn/secondary/llvm/tools/bugpoint-passes/BUILD.gn
index 385c469..260c390 100644
--- a/utils/gn/secondary/llvm/tools/bugpoint-passes/BUILD.gn
+++ b/utils/gn/secondary/llvm/tools/bugpoint-passes/BUILD.gn
@@ -11,9 +11,9 @@
     "TestPasses.cpp",
   ]
 
-  if (host_os == "linux") {
+  if (host_os != "mac" && host_os != "win") {
     # The GN build currently doesn't globally pass -fPIC, but that's
-    # needed for building .so files on Linux.  Just pass it manually
+    # needed for building .so files on ELF.  Just pass it manually
     # for loadable_modules for now.
     cflags = [ "-fPIC" ]
   }
diff --git a/utils/gn/secondary/llvm/tools/bugpoint/BUILD.gn b/utils/gn/secondary/llvm/tools/bugpoint/BUILD.gn
index 84a4908..d14aec2 100644
--- a/utils/gn/secondary/llvm/tools/bugpoint/BUILD.gn
+++ b/utils/gn/secondary/llvm/tools/bugpoint/BUILD.gn
@@ -33,7 +33,7 @@
 
   # Support plugins.
   # FIXME: Disable dead stripping once other binaries are dead-stripped.
-  if (host_os == "linux") {
+  if (host_os != "mac" && host_os != "win") {
     # Make sure bugpoint plugins can access bugpoint's symbols.
     # Corresponds to export_executable_symbols() in cmake.
     ldflags = [ "-rdynamic" ]
diff --git a/utils/gn/secondary/llvm/tools/llc/BUILD.gn b/utils/gn/secondary/llvm/tools/llc/BUILD.gn
index 45cde4a..5f7aff1 100644
--- a/utils/gn/secondary/llvm/tools/llc/BUILD.gn
+++ b/utils/gn/secondary/llvm/tools/llc/BUILD.gn
@@ -21,7 +21,7 @@
 
   # Support plugins.
   # FIXME: Disable dead stripping once other binaries are dead-stripped.
-  if (host_os == "linux") {
+  if (host_os != "mac" && host_os != "win") {
     # Corresponds to export_executable_symbols() in cmake.
     ldflags = [ "-rdynamic" ]
   }
diff --git a/utils/gn/secondary/llvm/tools/lli/BUILD.gn b/utils/gn/secondary/llvm/tools/lli/BUILD.gn
index 0e17358..171e0dd 100644
--- a/utils/gn/secondary/llvm/tools/lli/BUILD.gn
+++ b/utils/gn/secondary/llvm/tools/lli/BUILD.gn
@@ -22,7 +22,7 @@
   sources = [
     "lli.cpp",
   ]
-  if (host_os == "linux") {
+  if (host_os != "mac" && host_os != "win") {
     # Corresponds to export_executable_symbols() in cmake.
     ldflags = [ "-rdynamic" ]
   }
diff --git a/utils/gn/secondary/llvm/tools/lto/BUILD.gn b/utils/gn/secondary/llvm/tools/lto/BUILD.gn
index 3cc62d3..135b952 100644
--- a/utils/gn/secondary/llvm/tools/lto/BUILD.gn
+++ b/utils/gn/secondary/llvm/tools/lto/BUILD.gn
@@ -1,8 +1,8 @@
 import("//llvm/version.gni")
 
 lto_target_type = "shared_library"
-if (host_os == "linux") {
-  # Linux needs -fPIC to build shared libs but they aren't on by default.
+if (host_os != "mac" && host_os != "win") {
+  # ELF targets need -fPIC to build shared libs but they aren't on by default.
   # For now, make libclang a static lib there.
   lto_target_type = "static_library"
 }
diff --git a/utils/gn/secondary/llvm/tools/opt/BUILD.gn b/utils/gn/secondary/llvm/tools/opt/BUILD.gn
index 7deae1c..2bf062c 100644
--- a/utils/gn/secondary/llvm/tools/opt/BUILD.gn
+++ b/utils/gn/secondary/llvm/tools/opt/BUILD.gn
@@ -32,7 +32,7 @@
 
   # Support plugins.
   # FIXME: Disable dead stripping once other binaries are dead-stripped.
-  if (host_os == "linux") {
+  if (host_os != "mac" && host_os != "win") {
     # Corresponds to export_executable_symbols() in cmake.
     ldflags = [ "-rdynamic" ]
   }
diff --git a/utils/gn/secondary/llvm/triples.gni b/utils/gn/secondary/llvm/triples.gni
index 1987afa..a82bd9b 100644
--- a/utils/gn/secondary/llvm/triples.gni
+++ b/utils/gn/secondary/llvm/triples.gni
@@ -1,5 +1,7 @@
 if (current_cpu == "x64") {
-  if (current_os == "linux") {
+  if (current_os == "freebsd") {
+    llvm_current_triple = "x86_64-unknown-freebsd"
+  } else if (current_os == "linux") {
     llvm_current_triple = "x86_64-unknown-linux-gnu"
   } else if (current_os == "mac") {
     llvm_current_triple = "x86_64-apple-darwin"
diff --git a/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn b/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn
index 6bf6e70..4ad9317 100644
--- a/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn
+++ b/utils/gn/secondary/llvm/unittests/Passes/BUILD.gn
@@ -17,9 +17,9 @@
       "//llvm/include/llvm/IR:public_tablegen",
     ]
 
-    if (host_os == "linux") {
+    if (host_os != "mac" && host_os != "win") {
       # The GN build currently doesn't globally pass -fPIC, but that's
-      # needed for building .so files on Linux.  Just pass it manually
+      # needed for building .so files on ELF.  Just pass it manually
       # for loadable_modules for now.
       cflags = [ "-fPIC" ]
     }
@@ -46,7 +46,7 @@
     defines = [ "LLVM_ENABLE_PLUGINS" ]
   }
 
-  if (host_os == "linux") {
+  if (host_os != "mac" && host_os != "win") {
     # Corresponds to export_executable_symbols() in cmake.
     ldflags = [ "-rdynamic" ]
   }
diff --git a/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn b/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn
index a04559e..aac3da7 100644
--- a/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn
+++ b/utils/gn/secondary/llvm/unittests/Support/DynamicLibrary/BUILD.gn
@@ -15,9 +15,9 @@
       "PipSqueak.cpp",
     ]
 
-    if (host_os == "linux") {
+    if (host_os != "mac" && host_os != "win") {
       # The GN build currently doesn't globally pass -fPIC, but that's
-      # needed for building .so files on Linux.  Just pass it manually
+      # needed for building .so files on ELF.  Just pass it manually
       # for loadable_modules for now.
       cflags = [ "-fPIC" ]
     }
@@ -42,7 +42,7 @@
     "ExportedFuncs.cpp",
   ]
 
-  if (host_os == "linux") {
+  if (host_os != "mac" && host_os != "win") {
     # Corresponds to export_executable_symbols() in cmake.
     ldflags = [ "-rdynamic" ]
   }