bump product version to 5.0.4.1
[LibreOffice.git] / compilerplugins / Makefile-clang.mk
blobbed75cec99e6493b57190b8b8beaf7639b2035e9
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 # You may occasionally want to override some of these
14 CLANGCXX=$(filter-out -m32 -m64 -fsanitize=%,$(CXX))
16 # Compile flags ('make CLANGCXXFLAGS=-g' if you need to debug the plugin)
17 CLANGCXXFLAGS=-O2 -Wall -Wextra -g
19 # The uninteresting rest.
21 # Clang headers require these.
22 CLANGDEFS=-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti
23 # All include locations needed.
24 CLANGINCLUDES=-isystem $(CLANGDIR)/include -isystem $(CLANGDIR)/tools/clang/include
26 # Clang/LLVM libraries are intentionally not linked in, they are usually built as static libraries, which means the resulting
27 # plugin would be big (even though the clang binary already includes it all) and it'd be necessary to explicitly specify
28 # also all the dependency libraries.
30 CLANGINDIR=$(SRCDIR)/compilerplugins/clang
31 # Cannot use $(WORKDIR), the plugin should survive even 'make clean', otherwise the rebuilt
32 # plugin will cause cache misses with ccache.
33 CLANGOUTDIR=$(BUILDDIR)/compilerplugins/obj
35 QUIET=$(if $(VERBOSE)$(verbose),,@)
37 ifneq ($(ENABLE_WERROR),)
38 CLANGWERROR := -Werror
39 endif
41 compilerplugins: compilerplugins-build
43 # The list of source files, generated automatically (all files in clang/, but not subdirs).
44 CLANGSRC=$(foreach src,$(wildcard $(CLANGINDIR)/*.cxx), $(notdir $(src)))
45 # Remember the sources and if they have changed, force plugin relinking.
46 CLANGSRCCHANGED= \
47 $(shell mkdir -p $(CLANGOUTDIR) ; \
48 echo $(CLANGSRC) | sort > $(CLANGOUTDIR)/sources-new.txt; \
49 if diff $(CLANGOUTDIR)/sources.txt $(CLANGOUTDIR)/sources-new.txt >/dev/null 2>/dev/null; then \
50 echo 0; \
51 else \
52 mv $(CLANGOUTDIR)/sources-new.txt $(CLANGOUTDIR)/sources.txt; \
53 echo 1; \
54 fi; \
56 ifeq ($(CLANGSRCCHANGED),1)
57 .PHONY: CLANGFORCE
58 CLANGFORCE:
59 $(CLANGOUTDIR)/plugin.so: CLANGFORCE
60 endif
61 # Make the .so also explicitly depend on the sources list, to force update in case CLANGSRCCHANGED was e.g. during 'make clean'.
62 $(CLANGOUTDIR)/plugin.so: $(CLANGOUTDIR)/sources.txt
63 $(CLANGOUTDIR)/sources.txt:
64 touch $@
66 compilerplugins-build: $(CLANGOUTDIR) $(CLANGOUTDIR)/plugin.so
68 compilerplugins-clean:
69 rm -rf $(CLANGOUTDIR)
71 $(CLANGOUTDIR):
72 mkdir -p $(CLANGOUTDIR)
74 CLANGOBJS=
76 define clangbuildsrc
77 $(3): $(2) $(SRCDIR)/compilerplugins/Makefile-clang.mk $(CLANGOUTDIR)/clang-timestamp
78 @echo [build CXX] $(subst $(SRCDIR)/,,$(2))
79 $(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
81 -include $(CLANGOUTDIR)/$(1).d
83 $(CLANGOUTDIR)/plugin.so: $(3)
84 $(CLANGOUTDIR)/plugin.so: CLANGOBJS += $(3)
85 endef
87 $(foreach src, $(CLANGSRC), $(eval $(call clangbuildsrc,$(src),$(CLANGINDIR)/$(src),$(CLANGOUTDIR)/$(src:.cxx=.o))))
89 $(CLANGOUTDIR)/plugin.so: $(CLANGOBJS)
90 @echo [build LNK] $(subst $(BUILDDIR)/,,$@)
91 $(QUIET)$(CLANGCXX) -shared $(CLANGOBJS) -o $@ \
92 $(if $(filter MACOSX,$(OS)),-Wl$(CLANG_COMMA)-flat_namespace \
93 -Wl$(CLANG_COMMA)-undefined -Wl$(CLANG_COMMA)suppress)
95 # Clang most probably doesn't maintain binary compatibility, so rebuild when clang changes.
96 $(CLANGOUTDIR)/clang-timestamp: $(CLANGDIR)/bin/clang
97 $(QUIET)touch $@
99 # vim: set noet sw=4 ts=4: