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).
21 ifeq ($(COMPILER_PLUGINS_CXX
),)
22 CLANGCXX
=$(filter-out -m32
-m64
-fsanitize
%,$(CXX
))
24 CLANGCXX
=$(COMPILER_PLUGINS_CXX
)
27 # Compile flags ('make CLANGCXXFLAGS=-g' if you need to debug the plugin); you
28 # may occasionally want to override these:
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-
38 CLANGCXXFLAGS
=-O2
-Wall
-Wextra
-Wundef
-g
41 # The uninteresting rest.
43 # Clang headers require these.
44 CLANGDEFS
=-D__STDC_CONSTANT_MACROS
-D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS
46 CLANGDEFS
+= -fno-rtti
48 # All include locations needed (using -isystem silences various warnings when
49 # including those files):
51 CLANGINCLUDES
=-I
$(CLANGDIR
)/include
53 CLANGINCLUDES
=$(if
$(filter /usr
,$(CLANGDIR
)),,-isystem
$(CLANGDIR
)/include)
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
),)
72 CLANGWERROR
:= -Werror
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.
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 \
87 mv
$(CLANGOUTDIR
)/sources-new.txt
$(CLANGOUTDIR
)/sources.txt
; \
91 ifeq ($(CLANGSRCCHANGED
),1)
94 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): CLANGFORCE
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
:
101 compilerplugins-build
: $(CLANGOUTDIR
) $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
)
103 compilerplugins-clean
:
104 rm -rf
$(CLANGOUTDIR
)
107 mkdir
-p
$(CLANGOUTDIR
)
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 \
120 -include $(CLANGOUTDIR
)/$(1).d
#TODO
122 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): $(3)
123 $(CLANGOUTDIR
)/plugin
$(CLANG_DL_EXT
): CLANGOBJS
+= $(3)
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)
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
)/,,$@
)
146 $(QUIET
)$(CLANGCXX
) /LD
$(CLANGOBJS
) /Fe
: $@
$(CLANGLIBDIR
)/clang.lib \
147 mincore.lib version.lib
/link
$(COMPILER_PLUGINS_CXX_LINKFLAGS
)
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
)
154 # Clang most probably doesn't maintain binary compatibility, so rebuild when clang changes.
155 $(CLANGOUTDIR
)/clang-timestamp
: $(CLANGDIR
)/bin
/clang
$(CLANG_EXE_EXT
)
158 # vim: set noet sw=4 ts=4: