#!/usr/bin/perl $flags = "SYNOPSYS|VIEWLOGIC"; if (@ARGV < 2) { printf ("Usage: \n"); printf (" gen_vhd.perl $flags target_dir\n"); printf ("Generate specific VHDL files for either SYNOPSYS or Viewlogic.\n"); printf ("Resulting files will be placed in 'target_dir'\n"); printf ("Will process all *.generic files in the current directory\n"); exit -1; } $gen_flag = $ARGV[0]; $target_dir = $ARGV[1]; if (!( $gen_flag eq "SYNOPSYS" || $gen_flag eq "VIEWLOGIC")) { printf "Unrecognized flag: $gen_flag\n"; printf "Choices are $flags \n"; exit -1; } opendir (DIR, ".") || die "Directory listing of current directory failed\n"; @filenames = readdir(DIR); closedir(DIR); FILELOOP: foreach $vhd_file (@filenames) { if ($vhd_file eq "." || $vhd_file eq ".." ) { next FILELOOP; } @words = split('\.',$vhd_file); $test = $words[0]; if ($words[2] eq "generic") { $target_file = ">$target_dir/$words[0].$words[1]" ; open(OUTFILE,$target_file) || die "Can't open output file '$target_file'\n"; printf("processing $vhd_file..\n"); $cmd = "cpp -D$gen_flag $vhd_file |" || die "Can't execute '$cmd'"; $pid = open (LAST, $cmd); while () { $this_line = $_; @words = split(' ', $this_line); if (!($words[0] eq "#")) { print OUTFILE $this_line; } } close(LAST); close(OUTFILE); } }