Date: Mon, 29 Oct 2012 12:18:43 +0000 (UTC) From: Emanuel Haupt <ehaupt@FreeBSD.org> To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r306605 - head/Tools/scripts Message-ID: <201210291218.q9TCIhrR059116@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ehaupt Date: Mon Oct 29 12:18:43 2012 New Revision: 306605 URL: http://svn.freebsd.org/changeset/ports/306605 Log: Add convert-makefile-header.pl, a perl script that converts old style Makefile headers to the new format. Feature safe: yes Added: head/Tools/scripts/convert-makefile-header.pl (contents, props changed) Added: head/Tools/scripts/convert-makefile-header.pl ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/Tools/scripts/convert-makefile-header.pl Mon Oct 29 12:18:43 2012 (r306605) @@ -0,0 +1,111 @@ +#!/usr/bin/env perl +# +# convert-makefile-header.pl - perl script that converts old style Makefile +# headers to the new format. +# +# Created by: Emanuel Haupt <ehaupt@FreeBSD.org> +# +# MAINTAINER= ehaupt@FreeBSD.org +# +# $FreeBSD$ + +use strict; +use warnings; + +use File::Basename; +use Getopt::Long qw(:config posix_default no_ignore_case); + +sub usage() { + my $bn=basename($0); + print(<< "_ENOUSAGE"); +Usage: $bn [OPTION] PORT + -c use 'created by' header + -d use simple \$FreeBSD\$ RCS string header (default) + -h, --help this help + -n, --nowrite don't change file, just print what would be done + +_ENOUSAGE +} + +sub get_creator($) { + my $header=shift; + my $creator; + for my $line (@$header) { + if($line=~m'\s+whom:\s+(.*)'i) { + return $1; + } elsif($line=~m'\s+Created by:\s+(.*)'i) { + return $1; + } + } + return $creator; +} + +MAIN: { + # get options + my $opt={}; + GetOptions($opt, 'help|h', 'default|d', 'createdby|c', 'nowrite|n'); + + if(defined($opt->{help})) { + usage(); + exit 0; + } + + if(not @ARGV) { + push(@ARGV, '.'); + } + + for my $arg (@ARGV) { + my @header; + my @makefile; + my $in_header=1; + if(-f "$arg/Makefile") { + my $mf=$arg . "/Makefile"; + open(F,'<'.$mf); + while(my $line=<F>) { + chomp($line); + if($line=~m'^#' and $in_header) { + push(@header, $line); + } else { + $in_header=0; + push(@makefile, $line); + } + } + close(F); + + my $outh; + if(defined($opt->{nowrite})) { + $outh = \*STDOUT; + } else { + open(MF,'>'.$mf.'.tmp_header_rename'); + $outh = \*MF; + } + + # write new Makefile + if(defined($opt->{default}) || !defined($opt->{createdby})) { + print $outh "# \$FreeBSD\$\n"; + } elsif(defined($opt->{createdby})) { + my $creator=get_creator(\@header); + if(defined($creator)) { + print $outh "# Created by: $creator\n"; + } else { + print STDERR "$mf creator not found. Reverting to RCS string only.\n"; + } + print $outh "# \$FreeBSD\$\n"; + } + + for my $line (@makefile) { + print $outh $line . "\n"; + } + + if(not defined($opt->{nowrite})) { + # move new Makefile + `mv $mf $mf.orig`; + `mv $mf.tmp_header_rename $mf`; + print STDERR "$mf converted.\n"; + } + + } else { + print STDERR "$arg/Makefile does not exist.\n"; + } + } +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210291218.q9TCIhrR059116>