Bump version to 6.0-14
[LibreOffice.git] / compilerplugins / Makefile-clang.mk
blob89a798ebd34aec630fdc376d8a620d36e9f775a5
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 CLANG_COMMA :=,
13 ifeq ($(OS),WNT)
14 CLANG_DL_EXT = .dll
15 CLANG_EXE_EXT = .exe
16 else
17 CLANG_DL_EXT = .so
18 CLANG_EXE_EXT =
19 endif
21 ifeq ($(COMPILER_PLUGINS_CXX),)
22 CLANGCXX=$(filter-out -m32 -m64 -fsanitize%,$(CXX))
23 else
24 CLANGCXX=$(COMPILER_PLUGINS_CXX)
25 endif
27 # Compile flags ('make CLANGCXXFLAGS=-g' if you need to debug the plugin); you
28 # may occasionally want to override these:
29 ifeq ($(OS),WNT)
30 # See LLVM's cmake/modules/AddLLVM.cmake and LLVM build's
31 # tools/llvm-config/BuildVariables.inc:
32 # * Ignore "warning C4141: 'inline': used more than once" as emitted upon
33 # "LLVM_ATTRIBUTE_ALWAYS_INLINE inline" in various LLVM include files.
34 # * Ignore "warning C4577: 'noexcept' used with no exception handling mode
35 # specified; termination on exception is not guaranteed. Specify /EHsc".
36 CLANGCXXFLAGS=/nologo /D_HAS_EXCEPTIONS=0 /wd4141 /wd4577 /O2 /Oi /EHs-c- /GR-
37 else
38 CLANGCXXFLAGS=-O2 -Wall -Wextra -Wundef -g
39 endif
41 # The uninteresting rest.
43 # Clang headers require these.
44 CLANGDEFS=-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
45 ifneq ($(OS),WNT)
46 CLANGDEFS += -fno-rtti
47 endif
48 # All include locations needed (using -isystem silences various warnings when
49 # including those files):
50 ifeq ($(OS),WNT)
51 CLANGINCLUDES=-I$(CLANGDIR)/include
52 else
53 CLANGINCLUDES=$(if $(filter /usr,$(CLANGDIR)),,-isystem $(CLANGDIR)/include)
54 endif
56 # Clang/LLVM libraries are intentionally not linked in, they are usually built as static libraries, which means the resulting
57 # plugin would be big (even though the clang binary already includes it all) and it'd be necessary to explicitly specify
58 # also all the dependency libraries.
60 CLANGINDIR=$(SRCDIR)/compilerplugins/clang
61 # Cannot use $(WORKDIR), the plugin should survive even 'make clean', otherwise the rebuilt
62 # plugin will cause cache misses with ccache.
63 CLANGOUTDIR=$(BUILDDIR)/compilerplugins/obj
65 QUIET=$(if $(verbose),,@)
67 ifneq ($(ENABLE_WERROR),)
68 ifeq ($(OS),WNT)
69 CLANGWERROR :=
70 #TODO: /WX
71 else
72 CLANGWERROR := -Werror
73 endif
74 endif
76 compilerplugins: compilerplugins-build
78 # The list of source files, generated automatically (all files in clang/, but not subdirs).
79 CLANGSRC=$(foreach src,$(wildcard $(CLANGINDIR)/*.cxx), $(notdir $(src)))
80 # Remember the sources and if they have changed, force plugin relinking.
81 CLANGSRCCHANGED= \
82 $(shell mkdir -p $(CLANGOUTDIR) ; \
83 echo $(CLANGSRC) | sort > $(CLANGOUTDIR)/sources-new.txt; \
84 if diff $(CLANGOUTDIR)/sources.txt $(CLANGOUTDIR)/sources-new.txt >/dev/null 2>/dev/null; then \
85 echo 0; \
86 else \
87 mv $(CLANGOUTDIR)/sources-new.txt $(CLANGOUTDIR)/sources.txt; \
88 echo 1; \
89 fi; \
91 ifeq ($(CLANGSRCCHANGED),1)
92 .PHONY: CLANGFORCE
93 CLANGFORCE:
94 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): CLANGFORCE
95 endif
96 # Make the .so also explicitly depend on the sources list, to force update in case CLANGSRCCHANGED was e.g. during 'make clean'.
97 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): $(CLANGOUTDIR)/sources.txt
98 $(CLANGOUTDIR)/sources.txt:
99 touch $@
101 compilerplugins-build: $(CLANGOUTDIR) $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT)
103 compilerplugins-clean:
104 rm -rf $(CLANGOUTDIR)
106 $(CLANGOUTDIR):
107 mkdir -p $(CLANGOUTDIR)
109 CLANGOBJS=
111 ifeq ($(OS),WNT)
113 define clangbuildsrc
114 $(3): $(2) $(SRCDIR)/compilerplugins/Makefile-clang.mk $(CLANGOUTDIR)/clang-timestamp
115 @echo [build CXX] $(subst $(SRCDIR)/,,$(2))
116 $(QUIET)$(CLANGCXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) \
117 $(CLANGINCLUDES) /I$(BUILDDIR)/config_host $(2) $(CXXFLAGS_CXX11) /MD \
118 /c /Fo: $(3)
120 -include $(CLANGOUTDIR)/$(1).d #TODO
122 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): $(3)
123 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): CLANGOBJS += $(3)
124 endef
126 else
128 define clangbuildsrc
129 $(3): $(2) $(SRCDIR)/compilerplugins/Makefile-clang.mk $(CLANGOUTDIR)/clang-timestamp
130 @echo [build CXX] $(subst $(SRCDIR)/,,$(2))
131 $(QUIET)$(CLANGCXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) $(CLANGINCLUDES) -I$(BUILDDIR)/config_host $(2) -fPIC $(CXXFLAGS_CXX11) -c -o $(3) -MMD -MT $(3) -MP -MF $(CLANGOUTDIR)/$(1).d
133 -include $(CLANGOUTDIR)/$(1).d
135 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): $(3)
136 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): CLANGOBJS += $(3)
137 endef
139 endif
141 $(foreach src, $(CLANGSRC), $(eval $(call clangbuildsrc,$(src),$(CLANGINDIR)/$(src),$(CLANGOUTDIR)/$(src:.cxx=.o))))
143 $(CLANGOUTDIR)/plugin$(CLANG_DL_EXT): $(CLANGOBJS)
144 @echo [build LNK] $(subst $(BUILDDIR)/,,$@)
145 ifeq ($(OS),WNT)
146 $(QUIET)$(CLANGCXX) /LD $(CLANGOBJS) /Fe: $@ $(CLANGLIBDIR)/clang.lib \
147 mincore.lib version.lib /link $(COMPILER_PLUGINS_CXX_LINKFLAGS)
148 else
149 $(QUIET)$(CLANGCXX) -shared $(CLANGOBJS) -o $@ \
150 $(if $(filter MACOSX,$(OS)),-Wl$(CLANG_COMMA)-flat_namespace \
151 -Wl$(CLANG_COMMA)-undefined -Wl$(CLANG_COMMA)suppress)
152 endif
154 # Clang most probably doesn't maintain binary compatibility, so rebuild when clang changes.
155 $(CLANGOUTDIR)/clang-timestamp: $(CLANGDIR)/bin/clang$(CLANG_EXE_EXT)
156 $(QUIET)touch $@
158 # vim: set noet sw=4 ts=4: