github.com/fanux/shipyard@v0.0.0-20161009071005-6515ce223235/Godeps/_workspace/src/golang.org/x/sys/unix/mksysnum_linux.pl (about) 1 #!/usr/bin/env perl 2 # Copyright 2009 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 use strict; 7 8 if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") { 9 print STDERR "GOARCH or GOOS not defined in environment\n"; 10 exit 1; 11 } 12 13 my $command = "mksysnum_linux.pl ". join(' ', @ARGV); 14 15 print <<EOF; 16 // $command 17 // MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT 18 19 // +build $ENV{'GOARCH'},$ENV{'GOOS'} 20 21 package unix 22 23 const( 24 EOF 25 26 sub fmt { 27 my ($name, $num) = @_; 28 if($num > 999){ 29 # ignore deprecated syscalls that are no longer implemented 30 # https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716 31 return; 32 } 33 $name =~ y/a-z/A-Z/; 34 print " SYS_$name = $num;\n"; 35 } 36 37 my $prev; 38 open(GCC, "gcc -E -dD $ARGV[0] |") || die "can't run gcc"; 39 while(<GCC>){ 40 if(/^#define __NR_syscalls\s+/) { 41 # ignore redefinitions of __NR_syscalls 42 } 43 elsif(/^#define __NR_(\w+)\s+([0-9]+)/){ 44 $prev = $2; 45 fmt($1, $2); 46 } 47 elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){ 48 $prev = $2; 49 fmt($1, $2); 50 } 51 elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){ 52 fmt($1, $prev+$2) 53 } 54 } 55 56 print <<EOF; 57 ) 58 EOF