github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/src/pkg/syscall/mkall.sh (about)

     1  #!/usr/bin/env bash
     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  # The syscall package provides access to the raw system call
     7  # interface of the underlying operating system.  Porting Go to
     8  # a new architecture/operating system combination requires
     9  # some manual effort, though there are tools that automate
    10  # much of the process.  The auto-generated files have names
    11  # beginning with z.
    12  #
    13  # This script runs or (given -n) prints suggested commands to generate z files
    14  # for the current system.  Running those commands is not automatic.
    15  # This script is documentation more than anything else.
    16  #
    17  # * asm_${GOOS}_${GOARCH}.s
    18  #
    19  # This hand-written assembly file implements system call dispatch.
    20  # There are three entry points:
    21  #
    22  # 	func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
    23  # 	func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
    24  # 	func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
    25  #
    26  # The first and second are the standard ones; they differ only in
    27  # how many arguments can be passed to the kernel.
    28  # The third is for low-level use by the ForkExec wrapper;
    29  # unlike the first two, it does not call into the scheduler to
    30  # let it know that a system call is running.
    31  #
    32  # * syscall_${GOOS}.go
    33  #
    34  # This hand-written Go file implements system calls that need
    35  # special handling and lists "//sys" comments giving prototypes
    36  # for ones that can be auto-generated.  Mksyscall reads those
    37  # comments to generate the stubs.
    38  #
    39  # * syscall_${GOOS}_${GOARCH}.go
    40  #
    41  # Same as syscall_${GOOS}.go except that it contains code specific
    42  # to ${GOOS} on one particular architecture.
    43  #
    44  # * types_${GOOS}.c
    45  #
    46  # This hand-written C file includes standard C headers and then
    47  # creates typedef or enum names beginning with a dollar sign
    48  # (use of $ in variable names is a gcc extension).  The hardest
    49  # part about preparing this file is figuring out which headers to
    50  # include and which symbols need to be #defined to get the
    51  # actual data structures that pass through to the kernel system calls.
    52  # Some C libraries present alternate versions for binary compatibility
    53  # and translate them on the way in and out of system calls, but
    54  # there is almost always a #define that can get the real ones.
    55  # See types_darwin.c and types_linux.c for examples.
    56  #
    57  # * zerror_${GOOS}_${GOARCH}.go
    58  #
    59  # This machine-generated file defines the system's error numbers,
    60  # error strings, and signal numbers.  The generator is "mkerrors.sh".
    61  # Usually no arguments are needed, but mkerrors.sh will pass its
    62  # arguments on to godefs.
    63  #
    64  # * zsyscall_${GOOS}_${GOARCH}.go
    65  #
    66  # Generated by mksyscall.pl; see syscall_${GOOS}.go above.
    67  #
    68  # * zsysnum_${GOOS}_${GOARCH}.go
    69  #
    70  # Generated by mksysnum_${GOOS}.
    71  #
    72  # * ztypes_${GOOS}_${GOARCH}.go
    73  #
    74  # Generated by godefs; see types_${GOOS}.c above.
    75  
    76  GOOSARCH="${GOOS}_${GOARCH}"
    77  
    78  # defaults
    79  mksyscall="./mksyscall.pl"
    80  mkerrors="./mkerrors.sh"
    81  zerrors="zerrors_$GOOSARCH.go"
    82  mksysctl=""
    83  zsysctl="zsysctl_$GOOSARCH.go"
    84  run="sh"
    85  
    86  case "$1" in
    87  -syscalls)
    88  	for i in zsyscall*go
    89  	do
    90  		sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
    91  		rm _$i
    92  	done
    93  	exit 0
    94  	;;
    95  -n)
    96  	run="cat"
    97  	shift
    98  esac
    99  
   100  case "$#" in
   101  0)
   102  	;;
   103  *)
   104  	echo 'usage: mkall.sh [-n]' 1>&2
   105  	exit 2
   106  esac
   107  
   108  case "$GOOSARCH" in
   109  _* | *_ | _)
   110  	echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
   111  	exit 1
   112  	;;
   113  darwin_386)
   114  	mkerrors="$mkerrors -m32"
   115  	mksyscall="./mksyscall.pl -l32"
   116  	mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
   117  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   118  	;;
   119  darwin_amd64)
   120  	mkerrors="$mkerrors -m64"
   121  	mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
   122  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   123  	;;
   124  dragonfly_386)
   125  	mkerrors="$mkerrors -m32"
   126  	mksyscall="./mksyscall.pl -l32 -dragonfly"
   127  	mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
   128  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   129  	;;
   130  dragonfly_amd64)
   131  	mkerrors="$mkerrors -m64"
   132  	mksyscall="./mksyscall.pl -dragonfly"
   133  	mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
   134  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   135  	;;
   136  freebsd_386)
   137  	mkerrors="$mkerrors -m32"
   138  	mksyscall="./mksyscall.pl -l32"
   139  	mksysnum="curl -s 'http://svn.freebsd.org/base/head/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
   140  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   141  	;;
   142  freebsd_amd64)
   143  	mkerrors="$mkerrors -m64"
   144  	mksysnum="curl -s 'http://svn.freebsd.org/base/head/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
   145  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   146  	;;
   147  freebsd_arm)
   148  	mkerrors="$mkerrors"
   149  	mksyscall="./mksyscall.pl -l32 -arm"
   150  	mksysnum="curl -s 'http://svn.freebsd.org/base/head/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
   151  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   152  	;;
   153  linux_386)
   154  	mkerrors="$mkerrors -m32"
   155  	mksyscall="./mksyscall.pl -l32"
   156  	mksysnum="./mksysnum_linux.pl /usr/include/asm/unistd_32.h"
   157  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   158  	;;
   159  linux_amd64)
   160  	unistd_h=$(ls -1 /usr/include/asm/unistd_64.h /usr/include/x86_64-linux-gnu/asm/unistd_64.h 2>/dev/null | head -1)
   161  	if [ "$unistd_h" = "" ]; then
   162  		echo >&2 cannot find unistd_64.h
   163  		exit 1
   164  	fi
   165  	mkerrors="$mkerrors -m64"
   166  	mksysnum="./mksysnum_linux.pl $unistd_h"
   167  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   168  	;;
   169  linux_arm)
   170  	mkerrors="$mkerrors"
   171  	mksyscall="./mksyscall.pl -l32 -arm"
   172  	mksysnum="curl -s 'http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/arch/arm/include/uapi/asm/unistd.h' | ./mksysnum_linux.pl"
   173  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   174  	;;
   175  netbsd_386)
   176  	mkerrors="$mkerrors -m32"
   177  	mksyscall="./mksyscall.pl -l32 -netbsd"
   178  	mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
   179  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   180  	;;
   181  netbsd_amd64)
   182  	mkerrors="$mkerrors -m64"
   183  	mksyscall="./mksyscall.pl -netbsd"
   184  	mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
   185  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   186  	;;
   187  openbsd_386)
   188  	mkerrors="$mkerrors -m32"
   189  	mksyscall="./mksyscall.pl -l32 -openbsd"
   190  	mksysctl="./mksysctl_openbsd.pl"
   191  	zsysctl="zsysctl_openbsd.go"
   192  	mksysnum="curl -s 'http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
   193  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   194  	;;
   195  openbsd_amd64)
   196  	mkerrors="$mkerrors -m64"
   197  	mksyscall="./mksyscall.pl -openbsd"
   198  	mksysctl="./mksysctl_openbsd.pl"
   199  	zsysctl="zsysctl_openbsd.go"
   200  	mksysnum="curl -s 'http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
   201  	mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   202  	;;
   203  plan9_386)
   204  	mkerrors=
   205  	mksyscall="./mksyscall.pl -l32 -plan9"
   206  	mksysnum="./mksysnum_plan9.sh /n/sources/plan9/sys/src/libc/9syscall/sys.h"
   207  	mktypes="XXX"
   208  	;;
   209  windows_386)
   210  	mksyscall="./mksyscall_windows.pl -l32"
   211  	mksysnum=
   212  	mktypes=
   213  	mkerrors="./mkerrors_windows.sh -m32"
   214  	zerrors="zerrors_windows.go"
   215  	;;
   216  windows_amd64)
   217  	mksyscall="./mksyscall_windows.pl"
   218  	mksysnum=
   219  	mktypes=
   220  	mkerrors="./mkerrors_windows.sh -m32"
   221  	zerrors="zerrors_windows.go"
   222  	;;
   223  *)
   224  	echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
   225  	exit 1
   226  	;;
   227  esac
   228  
   229  (
   230  	if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
   231  	syscall_goos="syscall_$GOOS.go"
   232  	case "$GOOS" in
   233  	darwin | dragonfly | freebsd | netbsd | openbsd)
   234  		syscall_goos="syscall_bsd.go $syscall_goos"
   235  		;;
   236  	windows)
   237  		syscall_goos="$syscall_goos security_windows.go"
   238  		;;
   239  	esac
   240  	if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
   241  	if [ -n "$mksyscall" ]; then echo "$mksyscall $syscall_goos syscall_$GOOSARCH.go |gofmt >zsyscall_$GOOSARCH.go"; fi
   242  	if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
   243  	if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go |gofmt >ztypes_$GOOSARCH.go"; fi
   244  ) | $run