:#-*- 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 Buchholzeval'exec perl -w -S $0 ${1+"$@"}'if0;usestrict;my($myName,$srcdir,%exists,%uses,%generated_header);($myName=$0)=~s@.*/@@;my$usage="Usage: $myNameGenerates Makefile dependencies for the XEmacs src directory.The dependencies are written to stdout.";die$usageif@ARGV;($srcdir=$0)=~s@[^/]+$@@;chdir$srcdirordie"$srcdir: $!";opendirSRCDIR,"."ordie"$srcdir: $!";for(grep(/\.[ch]$/,readdir(SRCDIR))){$exists{$_}=1;}closedirSRCDIR;for(qw (config.h puresize-adjust.hsheap-adjust.hpaths.hEmacs.ad.h)){$generated_header{$_}=1;}formy$file(keys%exists){open(FILE,$file)ordie"$file: $!";undef$/;$_=<FILE>;RemoveComments($_);s/[ \t]+//g;# Find include dependenciesfor(/^\#include([^\n]+)/gm){if(m@^\"([A-Za-z0-9_-]+\.h)\"@){$uses{$file}{$1}=1ifexists$exists{$1};}elsif(m@<([A-Za-z0-9_-]+\.h)>@){$uses{$file}{$1}=1ifexists$generated_header{$1};}elsif(m@\"../lwlib/([A-Za-z0-9_-]+\.h)\"@){$uses{$file}{"\$(LWLIB_SRCDIR)/lwlib.h"}=1;}}}# Make transitive closure of %useswhile(1){my$changedP=0;formy$x(keys%uses){formy$y(keys%{$uses{$x}}){formy$z(keys%{$uses{$y}}){if(!exists$uses{$x}{$z}){$uses{$x}{$z}=1;$changedP=1;}}}}lastif!$changedP;}# Print file headerprint"## This file automatically generated by $myName. Do not modify.#ifdef USE_UNION_TYPELISP_UNION_H=lisp-union.h#elseLISP_UNION_H=lisp-disunion.h#endif";my@LISP_H=('lisp.h','config.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";formy$file(sortgrep(/$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");formy$file(sortgrep(/\.c$/,keys%uses)){PrintDeps($file);}sub RemoveComments{$_[0]=~s{ ( [^\"\'/]+ | (?:\"[^\"\\]*(?:\\.[^\"\\]*)*\" [^\"\'/]*)+ | (?:\'[^\'\\]*(?:\\.[^\'\\]*)*\' [^\"\'/]*)+ ) | / (?: \*[^*]*\*+(?:[^/*][^*]*\*+)*/ | /[^\n]* ) }{defined $1 ? $1 : ""}gsxeo;}