Branch libreoffice-5-0-4
[LibreOffice.git] / solenv / gbuild / platform / filter-showIncludes.awk
blob06788a94d3688e36bd7a5c37eba5ba344850571e
1 #!/usr/bin/gawk -f
2 # -*- tab-width: 4; indent-tabs-mode: t -*-
4 # This file is part of the LibreOffice project.
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/.
11 # Create dependency information from the output of cl.exe's showInclude. It
12 # needs additional information - the output name to which to write, objfile
13 # that depends on the includes, and the original file name.
14 # For best results all arguments should be absolute paths.
16 # It also consolidates the file names to a canonical form, and filters out
17 # duplicates.
19 # based on filter-showInclude.pl by Jan Holesovsky <kendy@suse.cz>
21 BEGIN {
22 if (!depfile || !objectfile || !sourcefile) {
23 print "usage: filter-showIncludes.awk -vdepfile=depfile.d " \
24 "-vobjectfile=objfile.o -vsourcefile=source.cxx" > "/dev/stderr"
25 exit 1
27 tempfile = depfile ".tmp"
28 print objectfile " : \\\n " sourcefile " \\" > tempfile
30 showincludes_prefix = ENVIRON["SHOWINCLUDES_PREFIX"];
31 if (!showincludes_prefix) {
32 showincludes_prefix = "Note: including file:"
35 # to match especially drive letters in whitelist case insensitive
36 IGNORECASE = 1
37 whitelist = \
38 "^(" ENVIRON["SRCDIR"] "|" ENVIRON["WORKDIR"] ")"
39 firstline = 1
43 sub(/^ */, "")
44 if (index($0, showincludes_prefix) == 1) {
45 $0 = substr($0, length(showincludes_prefix) + 1)
46 sub(/^ */, "")
47 gsub(/\\/, "/")
48 gsub(/ /, "\\ ")
49 if ($0 ~ whitelist) { # filter out system headers
50 if (!($0 in incfiles)) {
51 incfiles[$0]
52 print " " $0 " \\" > tempfile
55 } else {
56 # because MSVC stupidly prints the include files on stderr, it's
57 # necessary to forward everything that isn't matched by the pattern
58 # so users get to see compiler errros
59 if (firstline) { # ignore the line that just prints name of sourcefile
60 firstline = 0
61 } else {
62 print $0 > "/dev/stderr"
67 END {
68 if (!tempfile) {
69 exit 1
71 print "" > tempfile
73 # fdo#40099 if header.h does not exist, it will simply be considered out of
74 # date and any targets that use it as a prerequisite will be updated,
75 # which avoid misery when the header is deliberately deleted and removed
76 # as an include
77 # see http://www.makelinux.net/make3/make3-CHP-8-SECT-3
78 for (file in incfiles) {
79 print file " :\n" > tempfile
82 close(tempfile)
83 movecmd = "mv " tempfile " " depfile
84 ret = system(movecmd)
85 if (ret) {
86 print "ERROR: " movecmd " FAILED with status " ret > "/dev/stderr"
87 exit ret
91 # vim: set noet sw=4 ts=4: