PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/solenv/gbuild/platform/filter-showIncludes.awk

https://bitbucket.org/markjenkins/libreoffice_ubuntu-debian-fixes
AWK | 91 lines | 58 code | 6 blank | 27 comment | 0 complexity | f01d911c5068e5f0c54b63dd3b9c3195 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause-No-Nuclear-License-2014
  1. #!/usr/bin/gawk -f
  2. # -*- tab-width: 4; indent-tabs-mode: t -*-
  3. #
  4. # This file is part of the LibreOffice project.
  5. #
  6. # This Source Code Form is subject to the terms of the Mozilla Public
  7. # License, v. 2.0. If a copy of the MPL was not distributed with this
  8. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #
  10. # Create dependency information from the output of cl.exe's showInclude. It
  11. # needs additional information - the output name to which to write, objfile
  12. # that depends on the includes, and the original file name.
  13. # For best results all arguments should be absolute paths.
  14. #
  15. # It also consolidates the file names to a canonical form, and filters out
  16. # duplicates.
  17. #
  18. # based on filter-showInclude.pl by Jan Holesovsky <kendy@suse.cz>
  19. BEGIN {
  20. if (!depfile || !objectfile || !sourcefile) {
  21. print "usage: filter-showIncludes.awk -vdepfile=depfile.d " \
  22. "-vobjectfile=objfile.o -vsourcefile=source.cxx" > "/dev/stderr"
  23. exit 1
  24. }
  25. tempfile = depfile ".tmp"
  26. print objectfile " : \\\n " sourcefile " \\" > tempfile
  27. showincludes_prefix = ENVIRON["SHOWINCLUDES_PREFIX"];
  28. if (!showincludes_prefix) {
  29. showincludes_prefix = "Note: including file:"
  30. }
  31. regex = "^ *" showincludes_prefix " *"
  32. pattern = "/" regex "/"
  33. # to match especially drive letters in whitelist case insensitive
  34. IGNORECASE = 1
  35. whitelist = \
  36. "^(" ENVIRON["SRCDIR"] "|" ENVIRON["OUTDIR"] "|" ENVIRON["WORKDIR"] ")"
  37. firstline = 1
  38. }
  39. {
  40. if ($0 ~ regex) {
  41. sub(regex, "")
  42. gsub(/\\/, "/")
  43. gsub(/ /, "\\ ")
  44. if ($0 ~ whitelist) { # filter out system headers
  45. if (!($0 in incfiles)) {
  46. incfiles[$0]
  47. print " " $0 " \\" > tempfile
  48. }
  49. }
  50. } else {
  51. # because MSVC stupidly prints the include files on stderr, it's
  52. # necessary to forward everything that isn't matched by the pattern
  53. # so users get to see compiler errros
  54. if (firstline) { # ignore the line that just prints name of sourcefile
  55. firstline = 0
  56. } else {
  57. print $0 > "/dev/stderr"
  58. }
  59. }
  60. }
  61. END {
  62. if (!tempfile) {
  63. exit 1
  64. }
  65. print "" > tempfile
  66. # fdo#40099 if header.h does not exist, it will simply be considered out of
  67. # date and any targets that use it as a prerequisite will be updated,
  68. # which avoid misery when the header is deliberately deleted and removed
  69. # as an include
  70. # see http://www.makelinux.net/make3/make3-CHP-8-SECT-3
  71. for (file in incfiles) {
  72. print file " :\n" > tempfile
  73. }
  74. close(tempfile)
  75. movecmd = "mv " tempfile " " depfile
  76. ret = system(movecmd)
  77. if (ret) {
  78. print "ERROR: " movecmd " FAILED with status " ret > "/dev/stderr"
  79. exit ret
  80. }
  81. }
  82. # vim: set noet sw=4 ts=4: