Mercurial > hg > xemacs-beta
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 427:0a0253eac470 | 428:3ecd8885ac67 |
|---|---|
| 1 : #-*- Perl -*- | |
| 2 # Copyright (C) 1998 Free Software Foundation, Inc. | |
| 3 | |
| 4 # This file is part of XEmacs. | |
| 5 # | |
| 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 | |
| 9 # later version. | |
| 10 # | |
| 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 | |
| 14 # for more details. | |
| 15 # | |
| 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. | |
| 20 | |
| 21 # Author: Martin Buchholz | |
| 22 eval 'exec perl -w -S $0 ${1+"$@"}' | |
| 23 if 0; | |
| 24 | |
| 25 use strict; | |
| 26 my ($myName, $srcdir, %exists, %uses, %generated_header); | |
| 27 | |
| 28 ($myName = $0) =~ s@.*/@@; my $usage =" | |
| 29 Usage: $myName | |
| 30 | |
| 31 Generates Makefile dependencies for the XEmacs src directory. | |
| 32 The dependencies are written to stdout.\n"; | |
| 33 | |
| 34 die $usage if @ARGV; | |
| 35 | |
| 36 ($srcdir = $0) =~ s@[^/]+$@@; | |
| 37 $srcdir = "." if $srcdir eq ""; | |
| 38 chdir $srcdir or die "$srcdir: $!"; | |
| 39 | |
| 40 opendir SRCDIR, "." or die "$srcdir: $!"; | |
| 41 for (grep (/\.[ch]$/, readdir (SRCDIR))) { $exists{$_} = 1; } | |
| 42 closedir SRCDIR; | |
| 43 | |
| 44 for (qw (config.h sheap-adjust.h paths.h Emacs.ad.h)) { | |
| 45 $generated_header{$_} = 1; | |
| 46 } | |
| 47 | |
| 48 for my $file (keys %exists) { | |
| 49 open (FILE, $file) or die "$file: $!"; | |
| 50 undef $/; $_ = <FILE>; | |
| 51 RemoveComments ($_); | |
| 52 s/[ \t]+//g; | |
| 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; | |
| 61 } | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 # Make transitive closure of %uses | |
| 66 while (1) { | |
| 67 my $changedP = 0; | |
| 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}) { | |
| 72 $uses{$x}{$z} = 1; | |
| 73 $changedP = 1; | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 } | |
| 78 last if !$changedP; | |
| 79 } | |
| 80 | |
| 81 # Print file header | |
| 82 print | |
| 83 "## This file automatically generated by $myName. Do not modify. | |
| 84 | |
| 85 #ifdef USE_UNION_TYPE | |
| 86 LISP_UNION_H=lisp-union.h | |
| 87 #else | |
| 88 LISP_UNION_H=lisp-disunion.h | |
| 89 #endif | |
| 90 "; | |
| 91 | |
| 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"; | |
| 95 | |
| 96 sub PrintDeps { | |
| 97 my $file = shift; | |
| 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; | |
| 102 } | |
| 103 print "@{[sort keys %{$uses{$file}}]}\n"; | |
| 104 } | |
| 105 | |
| 106 sub PrintPatternDeps { | |
| 107 my ($pattern, $CPP_SYMBOL) = @_; | |
| 108 print "#ifdef $CPP_SYMBOL\n"; | |
| 109 for my $file (sort grep (/$pattern/ && /\.c$/, keys %uses)) { | |
| 110 PrintDeps($file); | |
| 111 delete $uses{$file}; | |
| 112 } | |
| 113 print "#endif\n"; | |
| 114 } | |
| 115 | |
| 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"); | |
| 121 | |
| 122 for my $file (sort grep (/\.c$/, keys %uses)) { PrintDeps($file); } | |
| 123 | |
| 124 sub RemoveComments { | |
| 125 $_[0] =~ | |
| 126 s{ ( | |
| 127 [^\"\'/]+ | | |
| 128 (?:\"[^\"\\]*(?:\\.[^\"\\]*)*\" [^\"\'/]*)+ | | |
| 129 (?:\'[^\'\\]*(?:\\.[^\'\\]*)*\' [^\"\'/]*)+ | |
| 130 ) | |
| 131 | / (?: | |
| 132 \*[^*]*\*+(?:[^/*][^*]*\*+)*/ | |
| 133 | | |
| 134 /[^\n]* | |
| 135 ) | |
| 136 }{defined $1 ? $1 : ""}gsxeo; | |
| 137 } |
