annotate src/make-src-depend @ 428:3ecd8885ac67 r21-2-22

Import from CVS: tag r21-2-22
author cvs
date Mon, 13 Aug 2007 11:28:15 +0200
parents
children abe6d1db359e
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 for my $file (keys %exists) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 open (FILE, $file) or die "$file: $!";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 undef $/; $_ = <FILE>;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 RemoveComments ($_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 s/[ \t]+//g;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 # Find include dependencies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 for (/^\#include([^\n]+)/gm) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 if (m@^\"([A-Za-z0-9_-]+\.h)\"@) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 $uses{$file}{$1} = 1 if exists $exists{$1};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 } elsif (m@<([A-Za-z0-9_-]+\.h)>@) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 $uses{$file}{$1} = 1 if exists $generated_header{$1};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 } elsif (m@\"../lwlib/([A-Za-z0-9_-]+\.h)\"@) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 $uses{$file}{"\$(LWLIB_SRCDIR)/lwlib.h"} = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 # Make transitive closure of %uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 while (1) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 my $changedP = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 for my $x (keys %uses) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 for my $y (keys %{$uses{$x}}) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 for my $z (keys %{$uses{$y}}) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 if (! exists $uses{$x}{$z}) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 $uses{$x}{$z} = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 $changedP = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 last if !$changedP;
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 # Print file header
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 print
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 "## This file automatically generated by $myName. Do not modify.
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 #ifdef USE_UNION_TYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 LISP_UNION_H=lisp-union.h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 LISP_UNION_H=lisp-disunion.h
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 ";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 my @LISP_H = ('lisp.h', 'config.h');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #@LISP_H = grep (! /lisp-(dis)?union\.h/, @LISP_H);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 print "LISP_H = @{[grep (!/lisp-(dis)?union\.h/, @LISP_H)]} \$(LISP_UNION_H)\n";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 sub PrintDeps {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 my $file = shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 my $ofile = $file; $ofile =~ s/c$/o/; print "$ofile: ";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 if (exists $uses{$file}{'lisp.h'}) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 delete @{%{$uses{$file}}}{@LISP_H};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 $uses{$file}{'$(LISP_H)'} = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 print "@{[sort keys %{$uses{$file}}]}\n";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 }
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 sub PrintPatternDeps {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 my ($pattern, $CPP_SYMBOL) = @_;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 print "#ifdef $CPP_SYMBOL\n";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 for my $file (sort grep (/$pattern/ && /\.c$/, keys %uses)) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 PrintDeps($file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 delete $uses{$file};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 print "#endif\n";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 }
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 PrintPatternDeps ('-msw', "HAVE_MS_WINDOWS");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 PrintPatternDeps ('-x', "HAVE_X_WINDOWS");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 PrintPatternDeps ('database', "HAVE_DATABASE");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 PrintPatternDeps ('^mule', "MULE");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 PrintPatternDeps ('^(?:External|extw-)', "EXTERNAL_WIDGET");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 for my $file (sort grep (/\.c$/, keys %uses)) { PrintDeps($file); }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 sub RemoveComments {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 $_[0] =~
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 s{ (
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 [^\"\'/]+ |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 (?:\"[^\"\\]*(?:\\.[^\"\\]*)*\" [^\"\'/]*)+ |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (?:\'[^\'\\]*(?:\\.[^\'\\]*)*\' [^\"\'/]*)+
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 | / (?:
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 /[^\n]*
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 }{defined $1 ? $1 : ""}gsxeo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 }