summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in4
-rwxr-xr-xbin/gen-iwyu-dummy-lib64
-rw-r--r--solenv/gbuild/StaticLibrary.mk12
3 files changed, 80 insertions, 0 deletions
diff --git a/Makefile.in b/Makefile.in
index 0a8c286aae30..a31dde3345ca 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -62,6 +62,10 @@ PARALLELISM_OPTION := $(if $(filter-out 0,$(PARALLELISM)),-j $(PARALLELISM),)
IWYU_OPTION := $(if $(IWYU_PATH),-k CXX=$(IWYU_PATH),)
+iwyudummy: bootstrap fetch
+ # $(SRCDIR)/bin/gen-iwyu-dummy-lib
+ cd $(BUILDDIR)/iwyudummy && $(MAKE) $(IWYU_OPTION) $(GMAKE_OPTIONS)
+
#
# Partial Build
#
diff --git a/bin/gen-iwyu-dummy-lib b/bin/gen-iwyu-dummy-lib
new file mode 100755
index 000000000000..ac117fe1f7db
--- /dev/null
+++ b/bin/gen-iwyu-dummy-lib
@@ -0,0 +1,64 @@
+#!/bin/bash
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+# Create a makefile that builds every non-generated header as a source file.
+# This should help to ensure the headers are self-contained and don't
+# impose unnecessary requirements (unnecessary includes) on client code.
+#
+# This script is fully compliant with the UNIX philosophy
+# (and if you can't read it you are clearly not worthy)
+
+set -e
+
+iwyu_INCLUDES=$(grep -h -r ":$" ${BUILDDIR}/workdir/Dep/*Object* | grep -v 'workdir\|config_host' | sed -e "s,^${SRCDIR}/,," | sed -e "s/:$//" | sort -u)
+
+iwyu_INCLUDEDIRS=$(echo "${iwyu_INCLUDES}" | sed -e "s,/[^/]*$,," | grep -v "^include" | sort -u)
+
+iwyu_EXTERNALS=$(ls ${SRCDIR}/*/*Library*mk ${SRCDIR}/*/*Executable*mk | xargs awk 'BEGIN {domatch=0;} /))/ {domatch=0;} domatch { if (!($1 in exts)) {exts[$1]; print $1;} } /use_external(s)?,/ { if (index($0, "))")) { gsub(/.*,/, ""); gsub(/)+/, ""); if (!($0 in exts)) {exts[$0]; print $0; } } else { domatch=1;} }' | grep -v '$(\|)\|tde\|expat_x64\|zlib_x64\|mozilla\|apr\|serf')
+
+mkdir -p ${BUILDDIR}/iwyudummy
+iwyu_MOD=${BUILDDIR}/iwyudummy/Module_iwyudummy.mk
+iwyu_LIB=${BUILDDIR}/iwyudummy/StaticLibrary_iwyudummy.mk
+
+echo 'module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))' > ${BUILDDIR}/iwyudummy/Makefile
+echo "include ${SRCDIR}/solenv/gbuild/partial_build.mk" >> ${BUILDDIR}/iwyudummy/Makefile
+echo '$(eval $(call gb_Module_Module,iwyudummy))' > ${iwyu_MOD}
+echo '$(eval $(call gb_Module_add_targets,iwyudummy,StaticLibrary_iwyudummy))' >> ${iwyu_MOD}
+
+echo '$(eval $(call gb_StaticLibrary_StaticLibrary,iwyudummy))' > ${iwyu_LIB}
+# clang will "compile" headers to .gch by default
+echo '$(eval $(call gb_StaticLibrary_add_cxxflags,iwyudummy,-x c++))' >> ${iwyu_LIB}
+echo '$(eval $(call gb_StaticLibrary_use_custom_headers,iwyudummy,officecfg/registry))' >> ${iwyu_LIB}
+echo '$(eval $(call gb_StaticLibrary_use_sdk_api,iwyudummy))' >> ${iwyu_LIB}
+echo '$(eval $(call gb_StaticLibrary_use_externals,iwyudummy,\' >> ${iwyu_LIB}
+for ext in ${iwyu_EXTERNALS}; do
+ echo "${ext} \\";
+done >> ${iwyu_LIB}
+echo '))' >> ${iwyu_LIB}
+
+echo '$(eval $(call gb_StaticLibrary_set_include,iwyudummy,\' >> ${iwyu_LIB}
+echo '$$(INCLUDE) \' >> ${iwyu_LIB}
+for dir in ${iwyu_INCLUDEDIRS}; do
+ if echo ${dir} | grep ".*/inc/" &>/dev/null; then
+ iwyu_INCLUDEDIRS_EXTRA+=" ${dir%/inc/*}/inc"
+ fi
+done
+for dir in $(echo ${iwyu_INCLUDEDIRS_EXTRA} | sed -e "s/ /\n/g" | uniq) ${iwyu_INCLUDEDIRS}; do
+ echo "-I${SRCDIR}/${dir} \\";
+done >> ${iwyu_LIB}
+# it fails to find stddef.h?
+echo '-I/usr/lib/clang/3.4/include \' >> ${iwyu_LIB}
+echo "))" >> ${iwyu_LIB} >> ${iwyu_LIB}
+
+echo '$(eval $(call gb_StaticLibrary__add_iwyu_headers,iwyudummy,\' >> ${iwyu_LIB}
+for hdr in ${iwyu_INCLUDES}; do
+ echo "${hdr} \\";
+done >> ${iwyu_LIB}
+echo '))' >> ${iwyu_LIB}
+
diff --git a/solenv/gbuild/StaticLibrary.mk b/solenv/gbuild/StaticLibrary.mk
index 39ba0fa49979..a78a781fe563 100644
--- a/solenv/gbuild/StaticLibrary.mk
+++ b/solenv/gbuild/StaticLibrary.mk
@@ -50,6 +50,18 @@ $(call gb_Helper_make_userfriendly_targets,$(1),StaticLibrary)
endef
+# this is a crude hack to "build" header files with include-what-you-use
+define gb_StaticLibrary__add_iwyu_header
+$(call gb_LinkTarget_get_target,$(call gb_StaticLibrary_get_linktarget,$(1))) : $(call gb_GenCxxObject_get_target,$(basename $(2)))
+$(call gb_GenCxxObject_get_target,$(basename $(2))) : $(SRCDIR)/$(2)
+$(call gb_GenCxxObject_get_target,$(basename $(2))) : WARNINGS_NOT_ERRORS := $(true)
+$(call gb_GenCxxObject_get_target,$(basename $(2))) : GEN_CXX_SOURCE := $(SRCDIR)/$(2)
+
+endef
+define gb_StaticLibrary__add_iwyu_headers
+$(foreach file,$(2),$(call gb_StaticLibrary__add_iwyu_header,$(1),$(file)))
+endef
+
define gb_StaticLibrary_forward_to_Linktarget
gb_StaticLibrary_$(1) = $$(call gb_LinkTarget_$(1),$$(call gb_StaticLibrary_get_linktarget,$$(1)),$$(2),$$(3),StaticLibrary_$$(1))