Bug 861425 - Build the clang plugin on Mac; r=jcranmer
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 31 May 2014 09:13:32 -0400
changeset 185995 288387f37b70025dfe935370864187d46b633ce9
parent 185994 7cdfb038dd19826f47e694cd24e2bb4d3e2bf0f9
child 185996 b1935bebcf0e959e163203c724d92cef5e845cb1
push id26871
push userphilringnalda@gmail.com
push dateSun, 01 Jun 2014 03:29:42 +0000
treeherdermozilla-central@0e10c8151654 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcranmer
bugs861425
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 861425 - Build the clang plugin on Mac; r=jcranmer
build/clang-plugin/Makefile.in
build/clang-plugin/configure
build/macosx/mozconfig.common
--- a/build/clang-plugin/Makefile.in
+++ b/build/clang-plugin/Makefile.in
@@ -1,16 +1,18 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 CXX      := @CXX@
 CXXFLAGS := @CXXFLAGS@
 LDFLAGS  := @LDFLAGS@
 VPATH		 := @srcdir@
+DSO_LDOPTS := @DSO_LDOPTS@
+DLL_SUFFIX := @DLL_SUFFIX@
 
 # Helper for end
 NULL :=
 
 CPPSRCS := \
 	clang-plugin.cpp \
 	$(NULL)
 
@@ -19,26 +21,26 @@ TESTSRCS := \
 	TestMustOverride.cpp \
 	TestNonHeapClass.cpp \
 	TestStackClass.cpp \
 	$(NULL)
 
 OBJS := $(patsubst %.cpp,%.o,$(CPPSRCS))
 TESTS := $(patsubst %.cpp,test-%,$(TESTSRCS))
 
-PLUGIN := libclang-plugin.so
+PLUGIN := libclang-plugin.$(DLL_SUFFIX)
 
 all: $(PLUGIN) $(TESTS)
 
 $(OBJS): %.o: %.cpp Makefile
 	$(CXX) -o $@ -c $(CXXFLAGS) $<
 
 $(PLUGIN): $(OBJS)
 	rm -f $@
-	$(CXX) -shared -o $@ $(CXXFLAGS) $(LDFLAGS) $(OBJS) -lclangASTMatchers
+	$(CXX) $(DSO_LDOPTS) -o $@ $(CXXFLAGS) $(OBJS) $(LDFLAGS)
 
 TESTFLAGS := -fsyntax-only -Xclang -verify \
 	-Xclang -load -Xclang $(CURDIR)/$(PLUGIN) \
 	-Xclang -add-plugin -Xclang moz-check
 
 $(TESTS): test-%: tests/%.cpp $(PLUGIN)
 	$(CXX) $(TESTFLAGS) $<
 
--- a/build/clang-plugin/configure
+++ b/build/clang-plugin/configure
@@ -1,10 +1,12 @@
 #!/bin/sh
 
+PLATFORM=`uname`
+
 # Default srcdir to this directory
 srcdir=
 
 for option; do
   case "$option" in
   -*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
   *) optarg= ;;
   esac
@@ -30,19 +32,36 @@ fi
 
 if test ! -x "$LLVMCONFIG"; then
   echo "configure: error: Cannot find an llvm-config binary for building a clang plugin" 1>&2
   exit 1
 fi
 
 echo "$LLVMCONFIG"
 
+LLVMLIBS="core mc analysis asmparser mcparser bitreader"
 LLVMCXXFLAGS=`$LLVMCONFIG --cxxflags`
 LLVMLDFLAGS=`$LLVMCONFIG --ldflags`
+LLVMLDFLAGS="$LLVMLDFLAGS `$LLVMCONFIG --libs $LLVMLIBS`"
+
+if [ $PLATFORM == Darwin ]; then
+  DSO_LDOPTS="-dynamiclib -shared"
+  CLANGLDFLAGS="-lclangFrontend -lclangDriver -lclangSerialization \
+                 -lclangParse -lclangSema -lclangAnalysis -lclangEdit -lclangAST \
+                 -lclangLex -lclangBasic -lclangASTMatchers"
+  DLL_SUFFIX="dylib"
+else
+  DSO_LDOPTS="-shared"
+  CLANGLDFLAGS=-lclangASTMatchers
+  DLL_SUFFIX="so"
+fi
+
 CXXFLAGS="$CXXFLAGS $LLVMCXXFLAGS -fno-rtti -fno-exceptions"
-LDFLAGS="$LDFLAGS $LLVMLDFLAGS"
+LDFLAGS="$LDFLAGS $LLVMLDFLAGS $CLANGLDFLAGS"
 
 cat $srcdir/Makefile.in | sed \
   -e "s%@CXX@%$CXX%" \
   -e "s%@CXXFLAGS@%$CXXFLAGS%" \
   -e "s%@LDFLAGS@%$LDFLAGS%" \
   -e "s%@srcdir@%$srcdir%" \
+  -e "s%@DSO_LDOPTS@%$DSO_LDOPTS%" \
+  -e "s%@DLL_SUFFIX@%$DLL_SUFFIX%" \
   > Makefile
--- a/build/macosx/mozconfig.common
+++ b/build/macosx/mozconfig.common
@@ -3,20 +3,22 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 . "$topsrcdir/build/mozconfig.common"
 
 if [ -d "$topsrcdir/clang" ]; then
     # mozilla-central based build
     export CC=$topsrcdir/clang/bin/clang
     export CXX=$topsrcdir/clang/bin/clang++
+    export LLVMCONFIG=$topsrcdir/clang/bin/llvm-config
 elif [ -d "$topsrcdir/../clang" ]; then
     # comm-central based build
     export CC=$topsrcdir/../clang/bin/clang
     export CXX=$topsrcdir/../clang/bin/clang++
+    export LLVMCONFIG=$topsrcdir/../clang/bin/llvm-config
 fi
 
 # If not set use the system default clang
 if [ -z "$CC" ]; then
     export CC=clang
 fi
 
 # If not set use the system default clang++