4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
7 # author Scott Kostyshak
9 # Full author contact details are available in file CREDITS
13 # All .cpp and .h files in the current directory and subdirectories
14 # are checked to see which include statements could be omitted without
15 # causing a build error. Many of these omissions would not be desired.
16 # For example, currently if you don't include Undo.h in Undo.cpp, there
17 # is no error because Undo.h is included in Cursor.h which is included
18 # in Undo.cpp. But clearly we do want to include Undo.h in Undo.cpp.
20 # The results are stored in header_check.sh.log
24 LOG_FILE="$(basename $0).log"
26 # For only standard headers:
31 # Exclude common headers with regex
32 # (e.g. 'debug.h' will exclude 'support/debug.h')
33 # LyX was compiled on exotic environments and these sometimes
34 # require headers not needed on win/linux. So check the logs before
35 # deleting "redundant" standard libraries or includes around various
37 EXCLUDE='\(debug.h\|cstdio\)'
39 NCORES=$(grep "CPU" /proc/cpuinfo | wc -l)
45 # This is not a clean make.
46 IFS='' ERROR_OUTPUT=$(make -j${NCORES} 2>&1 >/dev/null)
49 # Without the grep, ERROR_OUTPUT might contain messages such as:
50 # 2885 translated messages, 2169 fuzzy translations, 1356 untranslated messages.
51 ERROR_OUTPUT=$(echo "${ERROR_OUTPUT}" | grep -i "error")
53 # The sed regex is more strict than it needs to be.
54 if (( ERROR_CODE != 0 )); then
55 cppORh=$(echo "${ERROR_OUTPUT}" | head -n 1 | \
56 sed 's/.*\.\(cpp\|h\):[0-9]\+:[0-9]\+: error: .*/\1/')
57 if [ "${cppORh}" = "cpp" ]; then
59 elif [ "${cppORh}" != "h" ]; then
60 echo -e "Warning: the error was not parsed correctly."\
61 "\nThe following string was expected to be"\
62 "'.cpp' or '.h': \n ${cppORh}" >&2
65 return "${ERROR_CODE}"
68 echo "BUILD_FN exited without error after removing
69 the following include statements invididually:" > "${LOG_FILE}" \
70 || { echo "ERROR: could not create log file, ${LOG_FILE}"; exit 1; }
72 find -regex ".*\(cpp\|h\)$" | \
75 FILE_COPY=$( tempfile )
76 cp "${FILE_}" "${FILE_COPY}" \
77 || { echo "ERROR: bu copy failed" >&2; exit 1; }
78 echo "processing ${FILE_}..."
79 grep "${PATTERN}" "${FILE_}" | \
82 if echo "${INCLUDE}" | grep -q -v "${EXCLUDE}"; then
83 cp "${FILE_COPY}" "${FILE_}" \
84 || { echo "ERROR: restore copy failed" >&2; exit 1; }
85 sed -i "s@${INCLUDE}@@" "${FILE_}"
89 if [ "${BUILD_FN_RET}" = 0 ]; then
90 echo "${FILE_}::${INCLUDE}" >> "${LOG_FILE}"
91 elif [ -n "${PREFIX}" ]; then
92 echo "${PREFIX}${FILE_}::${INCLUDE}" >> "${LOG_FILE}"
96 cp "${FILE_COPY}" "${FILE_}"