#!/usr/bin/env perl # Copyright (c) 1999,2005,2006 Utrecht University (The Netherlands), # ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), # INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg # (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), # and Tel-Aviv University (Israel). All rights reserved. # # This file is part of CGAL (www.cgal.org); you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; version 2.1 of the License. # See the file LICENSE.LGPL distributed with CGAL. # # Licensees holding a valid commercial license may use this file in # accordance with the commercial license agreement provided with the software. # # This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE # WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # # $URL$ # $Id$ # # Author(s) : Geert-Jan Giezeman # usage: cgal_conditional_include file1 ... # Protects CGAL and other include directives in the following way: # #include # # is converted to # # #ifndef CGAL_HANDLE_H # #include # #endif # #include # # is converted to # # #ifndef CGAL_PROTECT_STDLIB_H # #include # #define CGAL_PROTECT_STDLIB_H # #endif # The only filenames that are not protected are the ones that figure in # the following list (with .h suffix added). @non_protected_files = ( 'LEDA/REDEFINE_NAMES', 'LEDA/UNDEFINE_NAMES', 'assert'); $tmpfilename = "CondIncl$$"; FILE: foreach $filename (@ARGV) { if (!open("infile", $filename)) { print STDERR "Could not open ${filename} for reading\n$!\n"; next FILE; } open("tmpfile", ">$tmpfilename") || die "Could not open temp file for writing\n$!\n"; $last = ''; Line: while () { if (($leading_space, $basename) = m|^([\s]*)#[\s]*include[\s]*[\s]*|) { # protect CGAL header files $protect_name = $basename; $protect_name =~ s'/'_'g; $protect_name =~ tr/a-z/A-Z/; $protect_name = "CGAL_" . $protect_name . '_H'; $protect_line = '#ifndef ' . $protect_name . "\n"; if ( $last !~ m|^[\s]*$protect_line|) { print tmpfile $leading_space; print tmpfile $protect_line; # print tmpfile "#include \n"; print tmpfile $_; print tmpfile $leading_space; print tmpfile "#endif // $protect_name\n"; } else { print tmpfile $_; } $last = ''; } elsif (($leading_space, $basename) = m|^([\s]*)#[\s]*include[\s]*<(.*)\.h>[\s]*|) { # protect other header files foreach $special_name (@non_protected_files) { if ($basename =~ m#^$special_name$#) { print tmpfile $_; $last = ''; next Line; } } $protect_name = $basename; $protect_name =~ s'/'_'g; $protect_name =~ tr/a-z/A-Z/; $protect_name = 'CGAL_PROTECT_' . $protect_name . '_H'; $protect_line = '#ifndef ' . $protect_name . "\n"; if ( $last !~ m|^[\s]*$protect_line|) { print tmpfile $leading_space; print tmpfile $protect_line; print tmpfile $_; print tmpfile $leading_space; print tmpfile "#define $protect_name\n"; print tmpfile $leading_space; print tmpfile "#endif // $protect_name\n"; } else { print tmpfile $_; } $last = ''; } else { # copy other lines print tmpfile $_; $last = $_; } } close infile; close tmpfile; if ($?) { print STDERR "Conversion of ${filename} failed\n$!\n"; next FILE; } if (!rename($tmpfilename,${filename})) { print STDERR "Cannot rename $tmpfilename to ${filename}.\n$!\n"; print STDERR "Conversion of ${filename} failed\n"; } }