annotate src/make-src-depend @ 404:2f8bb876ab1d r21-2-32

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