bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / Makefile-clang.mk
blobce3ab90a0ec2769143d41a43baf2223d0a4a6c97
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:
13 ifeq ($(OS),WNT)
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-
21 else
22 CLANGCXXFLAGS=-O2 -Wall -Wextra -Wundef -g
23 endif
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
28 #TODO:
29 ifeq ($(OS),WNT)
30 LO_CLANG_SHARED_PLUGINS=
31 endif
33 # The uninteresting rest.
35 include $(SRCDIR)/solenv/gbuild/gbuild.mk
36 include $(SRCDIR)/solenv/gbuild/Output.mk
38 CLANG_COMMA :=,
40 ifeq ($(OS),WNT)
41 CLANG_DL_EXT = .dll
42 CLANG_EXE_EXT = .exe
43 else
44 CLANG_DL_EXT = .so
45 CLANG_EXE_EXT =
46 endif
48 # Clang headers require these.
49 CLANGDEFS=-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
50 ifneq ($(OS),WNT)
51 CLANGDEFS += -fno-rtti
52 endif
53 # All include locations needed (using -isystem silences various warnings when
54 # including those files):
55 ifeq ($(OS),WNT)
56 CLANGINCLUDES=-I$(CLANGDIR)/include
57 else
58 CLANGINCLUDES=$(if $(filter /usr,$(CLANGDIR)),,-isystem $(CLANGDIR)/include)
59 endif
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
74 endif
76 ifeq ($(HAVE_GCC_SPLIT_DWARF),TRUE)
77 CLANGCXXFLAGS+=-gsplit-dwarf
78 endif
80 QUIET=$(if $(verbose),,@)
82 ifneq ($(ENABLE_WERROR),)
83 ifeq ($(OS),WNT)
84 CLANGWERROR :=
85 #TODO: /WX
86 else
87 CLANGWERROR := -Werror
88 endif
89 endif
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
96 endif
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.
101 CLANGSRCCHANGED= \
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 \
105 echo 0; \
106 else \
107 mv $(CLANGOUTDIR)/sources-new.txt $(CLANGOUTDIR)/sources.txt; \
108 echo 1; \
109 fi; \
111 ifeq ($(CLANGSRCCHANGED),1)
112 .PHONY: CLANGFORCE
113 CLANGFORCE:
114 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): CLANGFORCE
115 endif
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:
119 touch $@
121 compilerplugins-build: $(CLANGOUTDIR) $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT)
123 compilerplugins-clean:
124 rm -rf $(CLANGOUTDIR)
126 $(CLANGOUTDIR):
127 mkdir -p $(CLANGOUTDIR)
129 CLANGOBJS=
131 ifeq ($(OS),WNT)
133 define clangbuildsrc
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 \
138 /c /Fo: $(3)
140 -include $(CLANGOUTDIR)/$(1).d #TODO
142 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): $(3)
143 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): CLANGOBJS += $(3)
144 endef
146 else
148 define clangbuildsrc
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)
157 endef
159 endif
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)
165 ifeq ($(OS),WNT)
166 $(QUIET)$(COMPILER_PLUGINS_CXX) /LD $(CLANGOBJS) /Fe: $@ $(CLANGLIBDIR)/clang.lib \
167 mincore.lib version.lib /link $(COMPILER_PLUGINS_CXX_LINKFLAGS)
168 else
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)
172 endif
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
178 $(QUIET)touch $@
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
214 # TODO WNT version
215 endif
217 # vim: set noet sw=4 ts=4: