Mercurial > hg > xemacs-beta
diff src/make-src-depend @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | |
children | e11d67e05968 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/make-src-depend Mon Aug 13 10:28:48 2007 +0200 @@ -0,0 +1,137 @@ +: #-*- Perl -*- +# Copyright (C) 1998 Free Software Foundation, Inc. + +# This file is part of XEmacs. +# +# XEmacs is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# XEmacs is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with XEmacs; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# Author: Martin Buchholz +eval 'exec perl -w -S $0 ${1+"$@"}' + if 0; + +use strict; +my ($myName, $srcdir, %exists, %uses, %generated_header); + +($myName = $0) =~ s@.*/@@; my $usage =" +Usage: $myName + +Generates Makefile dependencies for the XEmacs src directory. +The dependencies are written to stdout. +"; + +die $usage if @ARGV; + +($srcdir = $0) =~ s@[^/]+$@@; +chdir $srcdir or die "$srcdir: $!"; + +opendir SRCDIR, "." or die "$srcdir: $!"; +for (grep (/\.[ch]$/, readdir (SRCDIR))) { $exists{$_} = 1; } +closedir SRCDIR; + +for (qw (config.h puresize-adjust.h sheap-adjust.h paths.h Emacs.ad.h)) { + $generated_header{$_} = 1; +} + +for my $file (keys %exists) { + open (FILE, $file) or die "$file: $!"; + undef $/; $_ = <FILE>; + RemoveComments ($_); + s/[ \t]+//g; + # Find include dependencies + for (/^\#include([^\n]+)/gm) { + if (m@^\"([A-Za-z0-9_-]+\.h)\"@) { + $uses{$file}{$1} = 1 if exists $exists{$1}; + } elsif (m@<([A-Za-z0-9_-]+\.h)>@) { + $uses{$file}{$1} = 1 if exists $generated_header{$1}; + } elsif (m@\"../lwlib/([A-Za-z0-9_-]+\.h)\"@) { + $uses{$file}{"\$(LWLIB_SRCDIR)/lwlib.h"} = 1; + } + } +} + +# Make transitive closure of %uses +while (1) { + my $changedP = 0; + for my $x (keys %uses) { + for my $y (keys %{$uses{$x}}) { + for my $z (keys %{$uses{$y}}) { + if (! exists $uses{$x}{$z}) { + $uses{$x}{$z} = 1; + $changedP = 1; + } + } + } + } + last if !$changedP; +} + +# Print file header +print +"## This file automatically generated by $myName. Do not modify. + +#ifdef USE_UNION_TYPE +LISP_UNION_H=lisp-union.h +#else +LISP_UNION_H=lisp-disunion.h +#endif +"; + +my @LISP_H = ('lisp.h', 'config.h', sort keys %{$uses{'lisp.h'}}); +#@LISP_H = grep (! /lisp-(dis)?union\.h/, @LISP_H); +print "LISP_H = @{[grep (!/lisp-(dis)?union\.h/, @LISP_H)]} \$(LISP_UNION_H)\n"; + +sub PrintDeps { + my $file = shift; + my $ofile = $file; $ofile =~ s/c$/o/; print "$ofile: "; + if (exists $uses{$file}{'lisp.h'}) { + delete @{%{$uses{$file}}}{@LISP_H}; + $uses{$file}{'$(LISP_H)'} = 1; + } + print "@{[sort keys %{$uses{$file}}]}\n"; +} + +sub PrintPatternDeps { + my ($pattern, $CPP_SYMBOL) = @_; + print "#ifdef $CPP_SYMBOL\n"; + for my $file (sort grep (/$pattern/ && /\.c$/, keys %uses)) { + PrintDeps($file); + delete $uses{$file}; + } + print "#endif\n"; +} + +PrintPatternDeps ('-msw', "HAVE_MS_WINDOWS"); +PrintPatternDeps ('-x', "HAVE_X_WINDOWS"); +PrintPatternDeps ('database', "HAVE_DATABASE"); +PrintPatternDeps ('^mule', "MULE"); +PrintPatternDeps ('^(?:External|extw-)', "EXTERNAL_WIDGET"); + +for my $file (sort grep (/\.c$/, keys %uses)) { PrintDeps($file); } + +sub RemoveComments { + $_[0] =~ + s{ ( + [^\"\'/]+ | + (?:\"[^\"\\]*(?:\\.[^\"\\]*)*\" [^\"\'/]*)+ | + (?:\'[^\'\\]*(?:\\.[^\'\\]*)*\' [^\"\'/]*)+ + ) + | / (?: + \*[^*]*\*+(?:[^/*][^*]*\*+)*/ + | + /[^\n]* + ) + }{defined $1 ? $1 : ""}gsxeo; +}