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