1#! @PERL@ 2# -*- Perl -*- 3# @generated_automatically@ 4 5eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac' 6 if 0; 7 8# Builds a self-contained C++ header file by performing recursive inclusion. 9# Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> 10# Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com) 11# 12# This file is part of the Parma Polyhedra Library (PPL). 13# 14# The PPL is free software; you can redistribute it and/or modify it 15# under the terms of the GNU General Public License as published by the 16# Free Software Foundation; either version 3 of the License, or (at your 17# option) any later version. 18# 19# The PPL is distributed in the hope that it will be useful, but WITHOUT 20# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22# for more details. 23# 24# You should have received a copy of the GNU General Public License 25# along with this program; if not, write to the Free Software Foundation, 26# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA. 27# 28# For the most up-to-date information see the Parma Polyhedra Library 29# site: http://bugseng.com/products/ppl/ . 30 31use strict; 32use warnings; 33use Getopt::Long; 34 35sub filter($$$$); 36sub filter($$$$) { 37 my ($file, $dirs, $level, $files) = @_; 38 return if (exists($$files{$file})); 39 $$files{$file} = undef; 40 my $fh; 41 open $fh, $file or die "Cannot open $file"; 42 my $comment = 0; 43 my $copyright = 0; 44 my $print_from = 1; 45 while (my $line = <$fh>) { 46 my $iname; 47 if (($iname) = ($line =~ '^\s*#include\s+"([^"]+)"\s*\n$')) { 48 my $lineno = $.; 49 my $ifile; 50 foreach my $idir (@$dirs) { 51 $ifile = $idir . '/' . $iname; 52 last if -e $ifile; 53 } 54 filter($ifile, $dirs, $level+1, $files); 55 $print_from = 1; 56 next; 57 } 58 if ($level > 0) { 59 if ($print_from) { 60 print "/* Automatically generated from PPL source file $file line $.. */\n"; 61 $print_from = 0; 62 } 63 next if ($line =~ '^\s*#ifndef\s+PPL_[A-Za-z0-9_]+_hh\s*$'); 64 next if ($line =~ '^\s*#define\s+PPL_[A-Za-z0-9_]+_hh(\s+1)?\s*$'); 65 next if ($line =~ '^\s*#endif\s*//\s*!defined\(PPL_[A-Za-z0-9_]+_hh\)\s*$'); 66 if ($line =~ '/\*') { 67 $comment = 1; 68 } 69 if ($comment && $line =~ 'Copyright.*Roberto Bagnara <bagnara@cs.unipr.it>') { 70 $copyright = 1; 71 print "*/\n" unless $line =~ '/\*'; 72 } 73 if ($line =~ '\*/') { 74 $comment = 0; 75 if ($copyright) { 76 $copyright = 0; 77 next; 78 } 79 } 80 next if $copyright; 81 } 82 print $line; 83 } 84 close $fh; 85 86} 87 88 89my @dirs; 90 91unless (GetOptions("I=s" => \@dirs) && @ARGV == 1) { 92 print STDERR "Usage: $0 [-I dir]... file\n"; 93 exit; 94} 95my $file = $ARGV[0]; 96 97my ($dir, $name) = ($file =~ '^(?:(.*)/)?([^/]+)$'); 98$dir = '.' unless defined($dir); 99unshift @dirs, $dir; 100 101my %files; 102 103filter($file, \@dirs, 0, \%files); 104