xref: /aoo41x/main/solenv/gbuild/processdeps.awk (revision e76eebc6)
1*e76eebc6SAndrew Rist#**************************************************************
2*e76eebc6SAndrew Rist#
3*e76eebc6SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*e76eebc6SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*e76eebc6SAndrew Rist#  distributed with this work for additional information
6*e76eebc6SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*e76eebc6SAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*e76eebc6SAndrew Rist#  "License"); you may not use this file except in compliance
9*e76eebc6SAndrew Rist#  with the License.  You may obtain a copy of the License at
10*e76eebc6SAndrew Rist#
11*e76eebc6SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*e76eebc6SAndrew Rist#
13*e76eebc6SAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*e76eebc6SAndrew Rist#  software distributed under the License is distributed on an
15*e76eebc6SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e76eebc6SAndrew Rist#  KIND, either express or implied.  See the License for the
17*e76eebc6SAndrew Rist#  specific language governing permissions and limitations
18*e76eebc6SAndrew Rist#  under the License.
19*e76eebc6SAndrew Rist#
20*e76eebc6SAndrew 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);
43cdf0e10cSrcweir    if( path ~ /^[a-zA-Z]:/ )
44cdf0e10cSrcweir        path = tolower(substr(path,0,1)) substr(path,2);
45cdf0e10cSrcweir    gsub(WORKDIR, "$(WORKDIR)/", path);
46cdf0e10cSrcweir    gsub(OUTDIR, "$(OUTDIR)/", path);
47cdf0e10cSrcweir    gsub(SRCDIR, "$(SRCDIR)/", path);
48cdf0e10cSrcweir    gsub(REPODIR, "$(REPODIR)/", path);
49cdf0e10cSrcweir    if( path ~ /^[a-zA-Z]:/ )
50cdf0e10cSrcweir        path = "/cygdrive/" tolower(substr(path,0,1)) substr(path,3);
51cdf0e10cSrcweir    return path;
52cdf0e10cSrcweir}
53cdf0e10cSrcweir
54cdf0e10cSrcweirBEGIN {
55cdf0e10cSrcweir   WORKDIR = tolower(substr(WORKDIR,0,1)) substr(WORKDIR,2);
56cdf0e10cSrcweir   OUTDIR = tolower(substr(OUTDIR,0,1)) substr(OUTDIR,2);
57cdf0e10cSrcweir   SRCDIR = tolower(substr(SRCDIR,0,1)) substr(SRCDIR,2);
58cdf0e10cSrcweir   REPODIR = tolower(substr(REPODIR,0,1)) substr(REPODIR,2);
59cdf0e10cSrcweir#   print "# WORKDIR=" WORKDIR;
60cdf0e10cSrcweir#   print "# OUTDIR=" OUTDIR;
61cdf0e10cSrcweir#   print "# SRCDIR=" SRCDIR;
62cdf0e10cSrcweir#   print "# REPODIR=" REPODIR;
63cdf0e10cSrcweir   print mangle_path(OBJECTFILE) ": \\";
64cdf0e10cSrcweir}
65cdf0e10cSrcweir
66cdf0e10cSrcweir/^[^#]/ {
67cdf0e10cSrcweir    print "\t" mangle_path($2) " \\";
68cdf0e10cSrcweir}
69cdf0e10cSrcweir
70cdf0e10cSrcweirEND {
71cdf0e10cSrcweir    print "\n";
72cdf0e10cSrcweir}
73