mkdeps.sh revision 8b23a6c7e1aee255004dd19098d4c2462b61b849
1#!/bin/sh
2#
3# Copyright (C) 2008 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# This script is used to transform the dependency files generated by GCC
18# For example, a typical .d file will have a line like:
19#
20#    source.o: /full/path/to/source.c other.h headers.h
21#    ...
22#
23# the script is used to replace 'source.o' to a full path, as in
24#
25#    objs/intermediates/emulator/source.o: /full/path/to/source.c other.h headers.h
26#
27# parameters
28#
29# $1: object file (full path)
30# $2: source dependency file to modify (erased on success)
31# $3: target source dependency file
32#
33
34# quote the object path. we change a single '.' into
35# a '\.' since this will be parsed by sed.
36#
37OBJECT=`echo $1 | sed -e s/\\\\./\\\\\\\\./g`
38#echo OBJECT=$OBJECT
39
40OBJ_NAME=`basename $OBJECT`
41#echo OBJ_NAME=$OBJ_NAME
42
43# we replace $OBJ_NAME with $OBJECT only if $OBJ_NAME starts the line
44# that's because some versions of GCC (e.g. 4.2.3) already produce
45# a correct dependency line with the full path to the object file.
46# In this case, we don't want to touch anything
47#
48cat $2 | sed -e s%^$OBJ_NAME%$OBJECT%g > $3 && rm -f $2
49
50
51
52