xref: /PHP-7.0/build/mkdep.awk (revision d0cb7153)
1#  +----------------------------------------------------------------------+
2#  | PHP Version 7                                                        |
3#  +----------------------------------------------------------------------+
4#  | Copyright (c) 2000-2006 The PHP Group                                |
5#  +----------------------------------------------------------------------+
6#  | This source file is subject to version 3.01 of the PHP license,      |
7#  | that is bundled with this package in the file LICENSE, and is        |
8#  | available through the world-wide-web at the following url:           |
9#  | http://www.php.net/license/3_01.txt                                  |
10#  | If you did not receive a copy of the PHP license and are unable to   |
11#  | obtain it through the world-wide-web, please send a note to          |
12#  | license@php.net so we can mail you a copy immediately.               |
13#  +----------------------------------------------------------------------+
14#  | Author: Sascha Schumann <sascha@schumann.cx>                         |
15#  +----------------------------------------------------------------------+
16#
17# $Id$
18#
19# Usage:
20#
21# echo top_srcdir top_builddir srcdir CPP [CPP-ARGS] filenames | \
22#      awk -f mkdep.awk > dependencies
23
24
25{
26	top_srcdir=$1
27	top_builddir=$2
28	srcdir=$3
29	cmd=$4
30
31	for (i = 5; i <= NF; i++) {
32		if (match($i, "^-[A-Z]") == 0)
33			break;
34		cmd=cmd " " $i
35	}
36
37	dif=i-1
38
39	for (; i <= NF; i++)
40		filenames[i-dif]=$i
41
42	no_files=NF-dif
43
44	for(i = 1; i <= no_files; i++) {
45		if (system("test -r " filenames[i]) != 0)
46			continue
47
48		target=filenames[i]
49		sub(srcdir "/", "", target)
50		target2=target
51		sub("\.(c|cpp)$", ".lo", target);
52		sub("\.(c|cpp)$", ".slo", target2);
53
54		for (e in used)
55			delete used[e]
56
57		cmdx=cmd " " filenames[i]
58		done=0
59		while ((cmdx | getline) > 0) {
60			if (match($0, "^# [0-9]* \".*\.h\"") != 0) {
61				if (sub(top_srcdir, "$(top_srcdir)", $3) == 0)
62					sub(top_builddir, "$(top_builddir)", $3)
63				if (substr($3,2,1) != "/" && used[$3] != 1) {
64					if (done == 0)
65						printf(target " " target2 ":")
66					done=1
67					printf(" \\\n\t" substr($3,2,length($3)-2))
68					used[$3] = 1;
69				}
70			}
71		}
72		if (done == 1)
73			print "\n"
74	}
75}
76