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 $srcdir = "." if $srcdir eq "";
39 chdir $srcdir or die "$srcdir: $!";
41 opendir SRCDIR, "." or die "$srcdir: $!";
42 for (grep (/\.[ch]$/, readdir (SRCDIR))) { $exists{$_} = 1; }
45 for (qw (config.h sheap-adjust.h paths.h Emacs.ad.h)) {
46 $generated_header{$_} = 1;
49 for my $file (keys %exists) {
50 open (FILE, $file) or die "$file: $!";
51 undef $/; $_ = <FILE>;
54 # Find include dependencies
55 for (/^\#include([^\n]+)/gm) {
56 if (m@^\"([A-Za-z0-9_-]+\.h)\"@) {
57 $uses{$file}{$1} = 1 if exists $exists{$1};
58 } elsif (m@<([A-Za-z0-9_-]+\.h)>@) {
59 $uses{$file}{$1} = 1 if exists $generated_header{$1};
60 } elsif (m@\"../lwlib/([A-Za-z0-9_-]+\.h)\"@) {
61 $uses{$file}{"\$(LWLIB_SRCDIR)/lwlib.h"} = 1;
66 # Make transitive closure of %uses
69 for my $x (keys %uses) {
70 for my $y (keys %{$uses{$x}}) {
71 for my $z (keys %{$uses{$y}}) {
72 if (! exists $uses{$x}{$z}) {
84 "## This file automatically generated by $myName. Do not modify.
87 LISP_UNION_H=lisp-union.h
89 LISP_UNION_H=lisp-disunion.h
93 my @LISP_H = ('lisp.h', 'config.h');
94 #@LISP_H = grep (! /lisp-(dis)?union\.h/, @LISP_H);
95 print "LISP_H = @{[grep (!/lisp-(dis)?union\.h/, @LISP_H)]} \$(LISP_UNION_H)\n";
99 my $ofile = $file; $ofile =~ s/c$/o/; print "$ofile: ";
100 if (exists $uses{$file}{'lisp.h'}) {
101 delete @{%{$uses{$file}}}{@LISP_H};
102 $uses{$file}{'$(LISP_H)'} = 1;
104 print "@{[sort keys %{$uses{$file}}]}\n";
107 sub PrintPatternDeps {
108 my ($pattern, $CPP_SYMBOL) = @_;
109 print "#ifdef $CPP_SYMBOL\n";
110 for my $file (sort grep (/$pattern/ && /\.c$/, keys %uses)) {
117 PrintPatternDeps ('-msw', "HAVE_MS_WINDOWS");
118 PrintPatternDeps ('-x', "HAVE_X_WINDOWS");
119 PrintPatternDeps ('database', "HAVE_DATABASE");
120 PrintPatternDeps ('^mule', "MULE");
121 PrintPatternDeps ('^(?:External|extw-)', "EXTERNAL_WIDGET");
123 for my $file (sort grep (/\.c$/, keys %uses)) { PrintDeps($file); }
129 (?:\"[^\"\\]*(?:\\.[^\"\\]*)*\" [^\"\'/]*)+ |
130 (?:\'[^\'\\]*(?:\\.[^\'\\]*)*\' [^\"\'/]*)+
133 \*[^*]*\*+(?:[^/*][^*]*\*+)*/
137 }{defined $1 ? $1 : ""}gsxeo;