#!perl use strict; use Config; use File::Temp; my $SYS_re = qr/\bSYS_\w+|\bNR_syscalls\b/; my @SYS_names; { my $tmp = File::Temp->new; print $tmp "#include \n"; my $cmd = "$Config{cpp} -dM $Config{cppflags} $tmp"; open my $pipe, "$cmd |" or die "failed: $cmd"; local $_; while (<$pipe>) { next unless s/^\s*#\s*define\s+//; my ($sym) = split; next unless $sym =~ $SYS_re; push @SYS_names, $sym; } close $pipe or die "failed: $cmd"; } die "No $SYS_re names in " unless @SYS_names; my $SYS_prefix = "PERL_syscall__"; my %SYS_kv; { my $tmp = File::Temp->new; print $tmp "#include \n"; for (@SYS_names) { print $tmp "$SYS_prefix$_ $_\n"; } my $cmd = "$Config{cpp} $Config{cppflags} $tmp"; open my $pipe, "$cmd |" or die "failed: $cmd"; local $_; while (<$pipe>) { next unless s/^$SYS_prefix//; /^($SYS_re)\s+(\S.*)/ or die "bad cpp output: $_\n"; $SYS_kv{$1} = $2; } close $pipe or die "failed: $cmd"; } die "No $SYS_re names in " unless %SYS_kv; unlink "sys_syscall.ph"; open my $fh, ">sys_syscall.ph" or die "Cannot open sys_syscall.ph: $!"; print $fh "# Automatically generated, do not edit.\n"; print $fh "use strict;\n"; for my $k (sort keys %SYS_kv) { my $v = $SYS_kv{$k}; print $fh "sub $k () { $v }\n"; } print $fh "1;\n"; close $fh or die "Cannot close sys_syscall.ph: $!"; require "./sys_syscall.ph";