Branch libreoffice-5-0-4
[LibreOffice.git] / bin / gen-iwyu-dummy-lib
blob62e7c7bc2fd8aeb0a7fffb0ed897314c39c0a65c
1 #!/bin/bash
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # Create a makefile that builds every non-generated header as a source file.
11 # This should help to ensure the headers are self-contained and don't
12 # impose unnecessary requirements (unnecessary includes) on client code.
14 # This script is fully compliant with the UNIX philosophy
15 # (and if you can't read it you are clearly not worthy)
17 set -e
19 iwyu_INCLUDES=$(grep -h -r ":$" ${BUILDDIR}/workdir/Dep/*Object* \
20 | grep -v 'workdir\|config_host' | grep -v "^/usr" \
21 | sed -e "s,^${SRCDIR}/,," | sed -e "s/:$//" | sort -u)
23 iwyu_INCLUDEDIRS=$(echo "${iwyu_INCLUDES}" | sed -e "s,/[^/]*$,," | grep -v "^include" | sort -u)
25 iwyu_EXTERNALS=$(ls ${SRCDIR}/*/*Library*mk ${SRCDIR}/*/*Executable*mk \
26 | xargs awk -f bin/gen-iwyu-dummy-lib.awk \
27 | grep -v '$(\|)\|tde\|expat_x64\|zlib_x64\|mozilla\|apr\|serf')
29 mkdir -p ${BUILDDIR}/iwyudummy
30 iwyu_MOD=${BUILDDIR}/iwyudummy/Module_iwyudummy.mk
31 iwyu_LIB=${BUILDDIR}/iwyudummy/StaticLibrary_iwyudummy.mk
33 echo 'module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))' > ${BUILDDIR}/iwyudummy/Makefile
34 echo "include ${SRCDIR}/solenv/gbuild/partial_build.mk" >> ${BUILDDIR}/iwyudummy/Makefile
35 echo '$(eval $(call gb_Module_Module,iwyudummy))' > ${iwyu_MOD}
36 echo '$(eval $(call gb_Module_add_targets,iwyudummy,StaticLibrary_iwyudummy))' >> ${iwyu_MOD}
38 # prevent some common configuration errors
39 echo 'ifneq ($(COMPILER_PLUGINS),)' > ${iwyu_LIB}
40 echo ' $(call gb_Output_error,--enable-compiler-plugins does not work well with this: bailing out)' > ${iwyu_LIB}
41 echo 'endif' > ${iwyu_LIB}
43 echo '$(eval $(call gb_StaticLibrary_StaticLibrary,iwyudummy))' > ${iwyu_LIB}
44 # clang will "compile" headers to .gch by default
45 echo '$(eval $(call gb_StaticLibrary_add_cxxflags,iwyudummy,-x c++ -Wno-unused-macros))' >> ${iwyu_LIB}
46 echo '$(eval $(call gb_StaticLibrary_use_custom_headers,iwyudummy,officecfg/registry))' >> ${iwyu_LIB}
47 echo '$(eval $(call gb_StaticLibrary_use_sdk_api,iwyudummy))' >> ${iwyu_LIB}
48 echo '$(eval $(call gb_StaticLibrary_use_externals,iwyudummy,\' >> ${iwyu_LIB}
49 for ext in ${iwyu_EXTERNALS}; do
50 echo "${ext} \\";
51 done >> ${iwyu_LIB}
52 echo '))' >> ${iwyu_LIB}
54 echo '$(eval $(call gb_StaticLibrary_set_include,iwyudummy,\' >> ${iwyu_LIB}
55 echo '$$(INCLUDE) \' >> ${iwyu_LIB}
56 for dir in ${iwyu_INCLUDEDIRS}; do
57 if echo ${dir} | grep ".*/inc/" &>/dev/null; then
58 iwyu_INCLUDEDIRS_EXTRA+=" ${dir%/inc/*}/inc"
60 done
61 for dir in $(echo ${iwyu_INCLUDEDIRS_EXTRA} | sed -e "s/ /\n/g" | uniq) ${iwyu_INCLUDEDIRS}; do
62 echo "-I${SRCDIR}/${dir} \\";
63 done >> ${iwyu_LIB}
64 # it fails to find stddef.h?
65 echo '-I/usr/lib/clang/3.4/include \' >> ${iwyu_LIB}
66 echo "))" >> ${iwyu_LIB} >> ${iwyu_LIB}
68 echo '$(eval $(call gb_StaticLibrary__add_iwyu_headers,iwyudummy,\' >> ${iwyu_LIB}
69 for hdr in ${iwyu_INCLUDES}; do
70 echo "${hdr} \\";
71 done >> ${iwyu_LIB}
72 echo '))' >> ${iwyu_LIB}