annotate src/make-src-depend @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 3ecd8885ac67
children 3d3049ae1304
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 : #-*- Perl -*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 # Copyright (C) 1998 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 # This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 #
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 # XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 # under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 # Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 # later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 #
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 # XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 # for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 #
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 # You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 # along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 # Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 # Author: Martin Buchholz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 eval 'exec perl -w -S $0 ${1+"$@"}'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 if 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 use strict;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 my ($myName, $srcdir, %exists, %uses, %generated_header);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ($myName = $0) =~ s@.*/@@; my $usage ="
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 Usage: $myName
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 Generates Makefile dependencies for the XEmacs src directory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 The dependencies are written to stdout.\n";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 die $usage if @ARGV;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ($srcdir = $0) =~ s@[^/]+$@@;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 $srcdir = "." if $srcdir eq "";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 chdir $srcdir or die "$srcdir: $!";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 opendir SRCDIR, "." or die "$srcdir: $!";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 for (grep (/\.[ch]$/, readdir (SRCDIR))) { $exists{$_} = 1; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 closedir SRCDIR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 for (qw (config.h sheap-adjust.h paths.h Emacs.ad.h)) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 $generated_header{$_} = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
48 # Although this is not technically true, it ought to be true,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
49 # and makes the generated Makefile smaller.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
50 $uses{'lisp.h'}{'config.h'} = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
51
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 for my $file (keys %exists) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 open (FILE, $file) or die "$file: $!";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 undef $/; $_ = <FILE>;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 RemoveComments ($_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 s/[ \t]+//g;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 # Find include dependencies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 for (/^\#include([^\n]+)/gm) {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
59 if (m@^\"([A-Za-z0-9._-]+\.h)\"@) {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 $uses{$file}{$1} = 1 if exists $exists{$1};
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
61 } elsif (m@<([A-Za-z0-9._-]+\.h)>@) {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 $uses{$file}{$1} = 1 if exists $generated_header{$1};
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
63 } elsif (m@\"../lwlib/([A-Za-z0-9._-]+\.h)\"@) {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 $uses{$file}{"\$(LWLIB_SRCDIR)/lwlib.h"} = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 # Make transitive closure of %uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 while (1) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 my $changedP = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 for my $x (keys %uses) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 for my $y (keys %{$uses{$x}}) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 for my $z (keys %{$uses{$y}}) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 if (! exists $uses{$x}{$z}) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 $uses{$x}{$z} = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 $changedP = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 last if !$changedP;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 # Print file header
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 print
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
87 "## This file is automatically generated by \`$myName'. Do not modify.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
89 #if defined(USE_UNION_TYPE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 LISP_UNION_H=lisp-union.h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 LISP_UNION_H=lisp-disunion.h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 ";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
96 my @LISP_H = ('lisp.h', keys %{$uses{'lisp.h'}});
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
97 print "LISP_H=@{[grep (!/lisp-(dis)?union\.h/, @LISP_H)]} \$(LISP_UNION_H)\n";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 sub PrintDeps {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 my $file = shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 my $ofile = $file; $ofile =~ s/c$/o/; print "$ofile: ";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 if (exists $uses{$file}{'lisp.h'}) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 delete @{%{$uses{$file}}}{@LISP_H};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 $uses{$file}{'$(LISP_H)'} = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 print "@{[sort keys %{$uses{$file}}]}\n";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 sub PrintPatternDeps {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 my ($pattern, $CPP_SYMBOL) = @_;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
111 print "#if defined($CPP_SYMBOL)\n";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 for my $file (sort grep (/$pattern/ && /\.c$/, keys %uses)) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 PrintDeps($file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 delete $uses{$file};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 print "#endif\n";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
119 PrintPatternDeps ('-msw\\.', "HAVE_MS_WINDOWS");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
120 PrintPatternDeps ('-x\\.', "HAVE_X_WINDOWS");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
121 PrintPatternDeps ('-tty\\.', "HAVE_TTY");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
122 PrintPatternDeps ('^database', "HAVE_DATABASE");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
123 PrintPatternDeps ('^mule', "MULE");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 PrintPatternDeps ('^(?:External|extw-)', "EXTERNAL_WIDGET");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 for my $file (sort grep (/\.c$/, keys %uses)) { PrintDeps($file); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
128 # Surprisingly robust regexp to remove comments from arbitrary C code
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 sub RemoveComments {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 $_[0] =~
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 s{ (
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 [^\"\'/]+ |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (?:\"[^\"\\]*(?:\\.[^\"\\]*)*\" [^\"\'/]*)+ |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (?:\'[^\'\\]*(?:\\.[^\'\\]*)*\' [^\"\'/]*)+
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 | / (?:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 \*[^*]*\*+(?:[^/*][^*]*\*+)*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 /[^\n]*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 }{defined $1 ? $1 : ""}gsxeo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 }