newlib-cygwin/winsup/cygwin/speclib

92 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl
use Getopt::Long;
use File::Temp qw'tempdir';
use File::Basename;
use strict;
sub dllname($;$);
my $verbose;
my $static;
my $exclude;
GetOptions('static!'=>\$static, 'v|exclude!'=>\$exclude);
my $lib = shift;
my $nm = shift;
my $ar = shift;
my $libdll = shift;
open my $nm_fd, '-|', $nm, '-Ap', '--defined-only', @ARGV, $libdll or
die "$0: execution of $nm for object files failed - $!\n";
my %match_syms = ();
my $symfiles = ();
my $lastfn;
my @headtail = ();
my %extract = ();
my $libdllname;
while (<$nm_fd>) {
study;
m%^\Q$libdll\E:([^:]*):\d+ i \.idata\$([56])% and do {
if ($2 eq 5) {
push @headtail, $1;
} else {
pop @headtail;
}
next;
};
m%^\Q$libdll\E:[^:]*:\d+ I (__head_.*)$% and do {
$libdllname = $1;
next;
};
next unless m%^([^:]*):([^:]*(?=:))?.* [DTI] (.*)%o;
if ($1 ne $libdll) {
$match_syms{$3} = 1;
} elsif ($match_syms{$3} ? !$exclude : $exclude) {
$extract{$2} = 1;
}
}
close $nm_fd;
%extract or die "$0: couldn't find symbols for $lib\n";
defined($libdllname) or die "$0: couldn't determine __head_<NAME> - malformed import archive?\n";
for (@headtail) {
$extract{$_} = 1;
}
Remove unneeded header files from source files throughout. Update copyrights where appropriate. * globals.cc: New file for generic global variables. * mkglobals_h: New file to generate globals.h. * mkstatic: New Script used to build a (currently non-working) static libcygwin_s.a. * Makefile.in: Add unused rule to build a non-working libcygwin_s.a. (DLL_OFILES): Add globals.o. Make all objects rely on globals.h. (globals.h): New target. Generate globals.h. * cygtls.h: Honor new CYGTLS_HANDLE define to control when the HANDLE operator is allowed in _cygtls. * dcrt0.cc: Move most globals to globals.cc. * init.cc: Ditto. * environ.cc (strip_title_path): Remove now-unneeded extern. * fhandler_serial.cc (fhandler_serial::open): Ditto. * pinfo.cc: Ditto. (commune_process): Ditto. * shared.cc: Ditto. * glob.cc: Ditto. * strace.cc: Ditto. * exceptions.cc: Define CYGTLS_HANDLE before including winsup.h. * path.cc (stat_suffixes): Move here. * security.h: Add forward class path_conv declaration. * smallprint.cc (__small_vsprintf): Make a true c++ function. (__small_sprintf): Ditto. (small_printf): Ditto. (console_printf): Ditto. (__small_vswprintf): Ditto. (__small_swprintf): Ditto. * spawn.cc (spawn_guts): Remove _stdcall decoration in favor of regparm. (hExeced): Move to globals.cc * strfuncs.cc (current_codepage): Ditto. (active_codepage): Ditto. * sync.cc (lock_process::locker): Move here from dcrt0.cc. * syscalls.cc (stat_suffixes): Move to path.cc. * tty.cc (tty::create_master): Uncapitalize fatal warning for consistency. * winsup.h: Include globals.h to declare most of the grab bag list of globals which were previously defined here. * mount.h: Move USER_* defines back to shared_info.h. * speclib: Force temporary directory cleanup.
2009-01-03 13:12:22 +08:00
my $dir = tempdir(CLEANUP => 1);
chdir $dir;
# print join(' ', '+', $ar, 'x', sort keys %extract), "\n";
my $res = system $ar, 'x', $libdll, sort keys %extract;
die "$0: $ar extraction exited with non-zero status\n" if $res;
unlink $lib;
$res = system $ar, 'crus', $lib, sort keys %extract;
die "$0: $ar creation exited with non-zero status\n" if $res;
open my $lib_fd, '<', $lib or die "$0: couldn't open $lib for input - $!\n";
binmode $lib_fd;
my $libname = dllname($lib, 'lib');
my $pad = length($libdllname) - length($libname);
die "$0: library name too long (" . length($libname) . ")\n" if $pad < 0;
$libname .= "\0" x $pad;
$res = sysread($lib_fd, $_, -s $lib);
close $lib_fd;
die "$0: couldn't read $lib - $!\n" if $res != -s _;
0 while s/$libdllname/$libname/sog;
open $lib_fd, '>', $lib or die "$0: couldn't open $lib for output - $!\n";
syswrite($lib_fd, $_) == length($_) or die "$0: write to $lib failed - $!\n";
close $lib_fd;
exit 0;
sub dllname($;$) {
my $x = basename($_[0], '.a');
$x =~ s/^lib//o;
return '__head_' . $_[1] . $x;
}