2 # Copyright (C) 1998 Free Software Foundation, Inc.
4 # This file is part of XEmacs.
6 # XEmacs is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2, or (at your option) any
11 # XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with XEmacs; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
21 # Author: Martin Buchholz
22 eval 'exec perl -w -S $0 ${1+"$@"}'
26 my ($myName, $srcdir, %exists, %uses, %generated_header);
28 ($myName = $0) =~ s@.*/@@; my $usage ="
31 Generates Makefile dependencies for the XEmacs src directory.
32 The dependencies are written to stdout.
37 ($srcdir = $0) =~ s@[^/]+$@@;
38 chdir $srcdir or die "$srcdir: $!";
40 opendir SRCDIR, "." or die "$srcdir: $!";
41 for (grep (/\.[ch]$/, readdir (SRCDIR))) { $exists{$_} = 1; }
44 for (qw (config.h puresize-adjust.h sheap-adjust.h paths.h Emacs.ad.h)) {
45 $generated_header{$_} = 1;
48 for my $file (keys %exists) {
49 open (FILE, $file) or die "$file: $!";
50 undef $/; $_ = <FILE>;
53 # Find include dependencies
54 for (/^\#include([^\n]+)/gm) {
55 if (m@^\"([A-Za-z0-9_-]+\.h)\"@) {
56 $uses{$file}{$1} = 1 if exists $exists{$1};
57 } elsif (m@<([A-Za-z0-9_-]+\.h)>@) {
58 $uses{$file}{$1} = 1 if exists $generated_header{$1};
59 } elsif (m@\"../lwlib/([A-Za-z0-9_-]+\.h)\"@) {
60 $uses{$file}{"\$(LWLIB_SRCDIR)/lwlib.h"} = 1;
65 # Make transitive closure of %uses
68 for my $x (keys %uses) {
69 for my $y (keys %{$uses{$x}}) {
70 for my $z (keys %{$uses{$y}}) {
71 if (! exists $uses{$x}{$z}) {
83 "## This file automatically generated by $myName. Do not modify.
86 LISP_UNION_H=lisp-union.h
88 LISP_UNION_H=lisp-disunion.h
92 my @LISP_H = ('lisp.h', 'config.h');
93 #@LISP_H = grep (! /lisp-(dis)?union\.h/, @LISP_H);
94 print "LISP_H = @{[grep (!/lisp-(dis)?union\.h/, @LISP_H)]} \$(LISP_UNION_H)\n";
98 my $ofile = $file; $ofile =~ s/c$/o/; print "$ofile: ";
99 if (exists $uses{$file}{'lisp.h'}) {
100 delete @{%{$uses{$file}}}{@LISP_H};
101 $uses{$file}{'$(LISP_H)'} = 1;
103 print "@{[sort keys %{$uses{$file}}]}\n";
106 sub PrintPatternDeps {
107 my ($pattern, $CPP_SYMBOL) = @_;
108 print "#ifdef $CPP_SYMBOL\n";
109 for my $file (sort grep (/$pattern/ && /\.c$/, keys %uses)) {
116 PrintPatternDeps ('-msw', "HAVE_MS_WINDOWS");
117 PrintPatternDeps ('-x', "HAVE_X_WINDOWS");
118 PrintPatternDeps ('database', "HAVE_DATABASE");
119 PrintPatternDeps ('^mule', "MULE");
120 PrintPatternDeps ('^(?:External|extw-)', "EXTERNAL_WIDGET");
122 for my $file (sort grep (/\.c$/, keys %uses)) { PrintDeps($file); }
128 (?:\"[^\"\\]*(?:\\.[^\"\\]*)*\" [^\"\'/]*)+ |
129 (?:\'[^\'\\]*(?:\\.[^\'\\]*)*\' [^\"\'/]*)+
132 \*[^*]*\*+(?:[^/*][^*]*\*+)*/
136 }{defined $1 ? $1 : ""}gsxeo;