2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # Make sure variables in this Makefile do not conflict with other variables (e.g. from gbuild).
11 # Compile flags ('make CLANGCXXFLAGS=-g' if you need to debug the plugin); you
12 # may occasionally want to override these:
14 # See LLVM's cmake/modules/AddLLVM.cmake and LLVM build's
15 # tools/llvm-config/BuildVariables.inc:
16 # * Ignore "warning C4141: 'inline': used more than once" as emitted upon
17 # "LLVM_ATTRIBUTE_ALWAYS_INLINE inline" in various LLVM include files.
18 # * Ignore "warning C4577: 'noexcept' used with no exception handling mode
19 # specified; termination on exception is not guaranteed. Specify /EHsc".
20 CLANGCXXFLAGS
=/nologo
/D_HAS_EXCEPTIONS
=0 /wd4141
/wd4577
/O2
/Oi
/EHs-c-
/GR-
22 CLANGCXXFLAGS
=-O2
-Wall
-Wextra
-Wundef
-g
25 # Whether to make plugins use one shared ASTRecursiveVisitor (plugins run faster).
26 # By default enabled, disable if you work on an affected plugin (re-generating takes time).
27 LO_CLANG_SHARED_PLUGINS
=1
30 LO_CLANG_SHARED_PLUGINS
=
33 # The uninteresting rest.
35 include $(SRCDIR
)/solenv
/gbuild
/gbuild.mk
36 include $(SRCDIR
)/solenv
/gbuild
/Output.mk
48 # Clang headers require these.
49 CLANGDEFS
=-D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
51 CLANGDEFS
+= -fno-rtti
53 # All include locations needed (using -isystem silences various warnings when
54 # including those files):
56 CLANGINCLUDES
=-I
$(CLANGDIR
)/include
58 CLANGINCLUDES
=$(if
$(filter /usr
,$(CLANGDIR
)),,-isystem
$(CLANGDIR
)/include)
61 LLVMCONFIG
=$(CLANGDIR
)/bin
/llvm-config
63 # Clang/LLVM libraries are intentionally not linked in, they are usually built as static libraries, which means the resulting
64 # plugin would be big (even though the clang binary already includes it all) and it'd be necessary to explicitly specify
65 # also all the dependency libraries.
67 CLANGINDIR
=$(SRCDIR
)/compilerplugins
/clang
68 # Cannot use $(WORKDIR), the plugin should survive even 'make clean', otherwise the rebuilt
69 # plugin will cause cache misses with ccache.
70 CLANGOUTDIR
=$(BUILDDIR
)/compilerplugins
/obj
72 ifdef LO_CLANG_SHARED_PLUGINS
73 CLANGCXXFLAGS
+=-DLO_CLANG_SHARED_PLUGINS
76 ifeq ($(HAVE_GCC_SPLIT_DWARF
),TRUE
)
77 CLANGCXXFLAGS
+=-gsplit-dwarf
80 QUIET
=$(if
$(verbose
),,@
)
82 ifneq ($(ENABLE_WERROR
),)
87 CLANGWERROR
:= -Werror
91 compilerplugins
: compilerplugins-build
93 ifdef LO_CLANG_SHARED_PLUGINS
94 # The shared source, intentionally put first in the list because it takes the longest to build.
95 CLANGSRC
=sharedvisitor
/sharedvisitor.
cxx
97 # The list of source files, generated automatically (all files in clang/, but not subdirs).
98 CLANGSRC
+=$(foreach src
,$(wildcard $(CLANGINDIR
)/*.
cxx), $(notdir $(src
)))
100 # Remember the sources and if they have changed, force plugin relinking.
102 $(shell mkdir
-p
$(CLANGOUTDIR
) ; \
103 echo
$(CLANGSRC
) |
sort > $(CLANGOUTDIR
)/sources-new.txt
; \
104 if diff
$(CLANGOUTDIR
)/sources.txt
$(CLANGOUTDIR
)/sources-new.txt
>/dev
/null
2>/dev
/null
; then \
107 mv
$(CLANGOUTDIR
)/sources-new.txt
$(CLANGOUTDIR
)/sources.txt
; \
111 ifeq ($(CLANGSRCCHANGED
),1)
114 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): CLANGFORCE
116 # Make the .so also explicitly depend on the sources list, to force update in case CLANGSRCCHANGED was e.g. during 'make clean'.
117 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): $(CLANGOUTDIR
)/sources.txt
118 $(CLANGOUTDIR
)/sources.txt
:
121 compilerplugins-build
: $(CLANGOUTDIR
) $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
)
123 compilerplugins-clean
:
124 rm -rf
$(CLANGOUTDIR
)
127 mkdir
-p
$(CLANGOUTDIR
)
134 $(3): $(2) $(SRCDIR
)/compilerplugins
/Makefile-clang.mk
$(CLANGOUTDIR
)/clang-timestamp
135 $$(call gb_Output_announce
,$(subst $(SRCDIR
)/,,$(2)),$(true
),CXX
,3)
136 $(QUIET
)$(COMPILER_PLUGINS_CXX
) $(CLANGCXXFLAGS
) $(CLANGWERROR
) $(CLANGDEFS
) \
137 $(CLANGINCLUDES
) /I
$(BUILDDIR
)/config_host
$(2) /MD \
140 -include $(CLANGOUTDIR
)/$(1).d
#TODO
142 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): $(3)
143 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): CLANGOBJS
+= $(3)
149 $(3): $(2) $(SRCDIR
)/compilerplugins
/Makefile-clang.mk
$(CLANGOUTDIR
)/clang-timestamp
150 $$(call gb_Output_announce
,$(subst $(SRCDIR
)/,,$(2)),$(true
),CXX
,3)
151 $(QUIET
)$(COMPILER_PLUGINS_CXX
) $(CLANGCXXFLAGS
) $(CLANGWERROR
) $(CLANGDEFS
) $(CLANGINCLUDES
) -I
$(BUILDDIR
)/config_host
$(2) -fPIC
-c
-o
$(3) -MMD
-MT
$(3) -MP
-MF
$(CLANGOUTDIR
)/$(1).d
153 -include $(CLANGOUTDIR
)/$(1).d
155 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): $(3)
156 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): CLANGOBJS
+= $(3)
161 $(foreach src
, $(CLANGSRC
), $(eval
$(call clangbuildsrc
,$(src
),$(CLANGINDIR
)/$(src
),$(CLANGOUTDIR
)/$(src
:.
cxx=.o
))))
163 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): $(CLANGOBJS
)
164 $(call gb_Output_announce
,$(subst $(BUILDDIR
)/,,$@
),$(true
),LNK
,4)
166 $(QUIET
)$(COMPILER_PLUGINS_CXX
) /LD
$(CLANGOBJS
) /Fe
: $@
$(CLANGLIBDIR
)/clang.lib \
167 mincore.lib version.lib
/link
$(COMPILER_PLUGINS_CXX_LINKFLAGS
)
169 $(QUIET
)$(COMPILER_PLUGINS_CXX
) -shared
$(CLANGOBJS
) -o
$@ \
170 $(if
$(filter MACOSX
,$(OS
)),-Wl
$(CLANG_COMMA
)-flat_namespace \
171 -Wl
$(CLANG_COMMA
)-undefined
-Wl
$(CLANG_COMMA
)suppress
)
174 # Clang most probably doesn't maintain binary compatibility, so rebuild when clang changes
175 # (either the binary can change if it's a local build, or config_clang.h will change if configure detects
176 # a new version of a newly installed system clang).
177 $(CLANGOUTDIR
)/clang-timestamp
: $(CLANGDIR
)/bin
/clang
$(CLANG_EXE_EXT
) $(BUILDDIR
)/config_host
/config_clang.h
181 ifdef LO_CLANG_SHARED_PLUGINS
182 # Update the shared visitor source if needed. It is intentionally included in the sources and generated only when
183 # needed, because the generating takes a while.
184 # If you want to remake the source with LO_CLANG_SHARED_PLUGINS disabled, run 'make LO_CLANG_SHARED_PLUGINS=1'.
185 $(CLANGINDIR
)/sharedvisitor
/sharedvisitor.
cxx: $(shell grep
-l
"LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR
)/*.
cxx)
186 $(CLANGINDIR
)/sharedvisitor
/sharedvisitor.
cxx: $(CLANGOUTDIR
)/sharedvisitor
/generator
$(CLANG_EXE_EXT
)
187 $(call gb_Output_announce
,$(subst $(SRCDIR
)/,,$@
),$(true
),GEN
,1)
188 $(QUIET
)$(CLANGOUTDIR
)/sharedvisitor
/generator
$(CLANG_EXE_EXT
) \
189 $(COMPILER_PLUGINS_TOOLING_ARGS
:%=-arg
=%) \
190 $(shell grep
-l
"LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR
)/*.
cxx) \
191 > $(CLANGINDIR
)/sharedvisitor
/sharedvisitor.
cxx
193 CLANGTOOLLIBS
= -lclangTooling
-lclangDriver
-lclangFrontend
-lclangParse
-lclangSema
-lclangEdit
-lclangAnalysis \
194 -lclangAST
-lclangLex
-lclangSerialization
-lclangBasic
$(shell $(LLVMCONFIG
) --ldflags --libs
--system-libs
)
195 # Path to the clang system headers (no idea if there's a better way to get it).
196 CLANGTOOLDEFS
= -DCLANGSYSINCLUDE
=$(shell $(LLVMCONFIG
) --libdir)/clang
/$(shell $(LLVMCONFIG
) --version | sed
's/svn//')/include
198 $(CLANGOUTDIR
)/sharedvisitor
/generator
$(CLANG_EXE_EXT
): $(CLANGINDIR
)/sharedvisitor
/generator.
cxx \
199 |
$(CLANGOUTDIR
)/sharedvisitor
200 $(call gb_Output_announce
,$(subst $(BUILDDIR
)/,,$@
),$(true
),GEN
,1)
201 $(QUIET
)$(COMPILER_PLUGINS_CXX
) $(CLANGCXXFLAGS
) $(CLANGWERROR
) $(CLANGDEFS
) $(CLANGTOOLDEFS
) $(CLANGINCLUDES
) \
202 -DCLANGDIR
=$(CLANGDIR
) -DBUILDDIR
=$(BUILDDIR
) -I
$(BUILDDIR
)/config_host \
203 -c
$< -o
$(CLANGOUTDIR
)/sharedvisitor
/generator.o
-MMD
-MT
$@
-MP \
204 -MF
$(CLANGOUTDIR
)/sharedvisitor
/generator.d
205 $(QUIET
)$(COMPILER_PLUGINS_CXX
) $(CLANGCXXFLAGS
) $(CLANGOUTDIR
)/sharedvisitor
/generator.o \
206 -o
$@
$(CLANGTOOLLIBS
)
208 $(CLANGOUTDIR
)/sharedvisitor
/generator
$(CLANG_EXE_EXT
): $(SRCDIR
)/compilerplugins
/Makefile-clang.mk
$(CLANGOUTDIR
)/clang-timestamp
210 $(CLANGOUTDIR
)/sharedvisitor
:
211 mkdir
-p
$(CLANGOUTDIR
)/sharedvisitor
213 -include $(CLANGOUTDIR
)/sharedvisitor
/generator.d
217 # vim: set noet sw=4 ts=4: