xref: /PHP-7.3/build/mkdep.awk (revision 3362620b)
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# Usage:
18#
19# echo top_srcdir top_builddir srcdir CPP [CPP-ARGS] filenames | \
20#      awk -f mkdep.awk > dependencies
21
22
23{
24	top_srcdir=$1
25	top_builddir=$2
26	srcdir=$3
27	cmd=$4
28
29	for (i = 5; i <= NF; i++) {
30		if (match($i, "^-[A-Z]") == 0)
31			break;
32		cmd=cmd " " $i
33	}
34
35	dif=i-1
36
37	for (; i <= NF; i++)
38		filenames[i-dif]=$i
39
40	no_files=NF-dif
41
42	for(i = 1; i <= no_files; i++) {
43		if (system("test -r " filenames[i]) != 0)
44			continue
45
46		target=filenames[i]
47		sub(srcdir "/", "", target)
48		target2=target
49		sub("\.(c|cpp)$", ".lo", target);
50		sub("\.(c|cpp)$", ".slo", target2);
51
52		for (e in used)
53			delete used[e]
54
55		cmdx=cmd " " filenames[i]
56		done=0
57		while ((cmdx | getline) > 0) {
58			if (match($0, "^# [0-9]* \".*\.h\"") != 0) {
59				if (sub(top_srcdir, "$(top_srcdir)", $3) == 0)
60					sub(top_builddir, "$(top_builddir)", $3)
61				if (substr($3,2,1) != "/" && used[$3] != 1) {
62					if (done == 0)
63						printf(target " " target2 ":")
64					done=1
65					printf(" \\\n\t" substr($3,2,length($3)-2))
66					used[$3] = 1;
67				}
68			}
69		}
70		if (done == 1)
71			print "\n"
72	}
73}
74