xref: /trunk/main/solenv/gbuild/processdeps.awk (revision fc3c81da)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22# this awk script mangles makedepend output for a single object file
23# usage:
24# awk -f .../processdeps.awk \
25#     -v OUTDIR=outdir \
26#     -v SRCDIR=srcdir \
27#     -v WORKDIR=workdir \
28#     -v REPODIR=repodir \
29#     -v OBJECTFILE=objectfile
30# called like this the script will read from stdin
31# and write to stdout. It will:
32#  - replace the objectfile with the one given on the commandline
33#  - normalize paths to mixed paths (replacing all \ with /)
34#  - replace the string given as WORKDIR with $(WORKDIR)/
35#  - replace the string given as OUTDIR with $(OUTDIR)/
36#  - replace the string given as SRCDIR with $(SRCDIR)/
37#  - replace the string given as REPODIR with $(REPODIR)/
38#  - translates absolute mixed windows paths to cygwin paths by
39#    substituting a path starting with X:... to /cygdrive/X/...
40
41function mangle_path(path) {
42    gsub("\\\\", "/", path);
43    gsub("\r", "", path);
44    if( path ~ /^[a-zA-Z]:/ )
45        path = tolower(substr(path,0,1)) substr(path,2);
46    gsub(WORKDIR, "$(WORKDIR)/", path);
47    gsub(OUTDIR, "$(OUTDIR)/", path);
48    gsub(SRCDIR, "$(SRCDIR)/", path);
49    gsub(REPODIR, "$(REPODIR)/", path);
50    if( path ~ /^[a-zA-Z]:/ )
51        path = "/cygdrive/" tolower(substr(path,0,1)) substr(path,3);
52    return path;
53}
54
55BEGIN {
56   WORKDIR = tolower(substr(WORKDIR,0,1)) substr(WORKDIR,2);
57   OUTDIR = tolower(substr(OUTDIR,0,1)) substr(OUTDIR,2);
58   SRCDIR = tolower(substr(SRCDIR,0,1)) substr(SRCDIR,2);
59   REPODIR = tolower(substr(REPODIR,0,1)) substr(REPODIR,2);
60#   print "# WORKDIR=" WORKDIR;
61#   print "# OUTDIR=" OUTDIR;
62#   print "# SRCDIR=" SRCDIR;
63#   print "# REPODIR=" REPODIR;
64   print mangle_path(OBJECTFILE) ": \\";
65}
66
67/^[^#]/ {
68    print "\t" mangle_path($2) " \\";
69}
70
71END {
72    print "\n";
73}
74