use strict; use warnings; # This script is intended to change the extension on compiler libraries from .lib (MSVC standard) to .a (GNU standard). # It does this by grabbing the environment variables U3_DEVICE_PATH and LIB. # U3_DEVICE_PATH is used to exclude paths to libraries that aren't on the U3 Compiler-onna-stick # LIB is used to provide a list of paths to scan for the libraries to be checked. my $debug = 0; my $u3_drive = $ENV{'U3_DEVICE_PATH'} or die "HALT: U3_DEVICE_PATH is not set or null ($!)\n"; my @lib_paths = split ";", $ENV{'LIB'} or die "HALT: LIB not set or null ($!)\n"; if ($debug){ print "U3_DEVICE_PATH is $u3_drive\n"; print "$_ is a LIB path\n" for (@lib_paths); } for my $lib_dir (@lib_paths){ -d $lib_dir or die "HALT: $_ not found ($!)\n"; unless ($lib_dir =~ /^$u3_drive/){ print "$lib_dir is not on $u3_drive, skipped.\n" if $debug; next; } print "$lib_dir is on $u3_drive processing...\n" if $debug; opendir THEDIR, $lib_dir or die "HALT: Can't open $lib_dir ($!)\n"; my @lib_files = readdir THEDIR or die "HALT: Can't read $lib_dir ($!)\n"; close THEDIR; for my $lib_file (@lib_files){ unless($lib_file =~ /\.lib$|\.dll\.a$/i){ print "$lib_file does not end with .lib or .dll.a, skipping.\n" if $debug; next; } my $old_file = $lib_dir."\\".$lib_file; my $new_file = $old_file; $new_file =~ s/\.lib$|\.dll\.lib$|\.dll\.a$/.a/i; print "Renaming $old_file to $new_file\n"; rename $old_file, $new_file or die "HALT: Could not rename $new_file ($!)\n"; } }