1#!/bin/bash 2 3# Copyright The containerd Authors. 4 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8 9# http://www.apache.org/licenses/LICENSE-2.0 10 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17 18set -e 19 20mksyscall="$(go env GOROOT)/src/syscall/mksyscall.pl" 21 22fix() { 23 sed 's,^package syscall$,package sysx,' \ 24 | sed 's,^import "unsafe"$,import (\n\t"syscall"\n\t"unsafe"\n),' \ 25 | gofmt -r='BytePtrFromString -> syscall.BytePtrFromString' \ 26 | gofmt -r='Syscall6 -> syscall.Syscall6' \ 27 | gofmt -r='Syscall -> syscall.Syscall' \ 28 | gofmt -r='SYS_GETXATTR -> syscall.SYS_GETXATTR' \ 29 | gofmt -r='SYS_LISTXATTR -> syscall.SYS_LISTXATTR' \ 30 | gofmt -r='SYS_SETXATTR -> syscall.SYS_SETXATTR' \ 31 | gofmt -r='SYS_REMOVEXATTR -> syscall.SYS_REMOVEXATTR' \ 32 | gofmt -r='SYS_LGETXATTR -> syscall.SYS_LGETXATTR' \ 33 | gofmt -r='SYS_LLISTXATTR -> syscall.SYS_LLISTXATTR' \ 34 | gofmt -r='SYS_LSETXATTR -> syscall.SYS_LSETXATTR' \ 35 | gofmt -r='SYS_LREMOVEXATTR -> syscall.SYS_LREMOVEXATTR' 36} 37 38if [ "$GOARCH" == "" ] || [ "$GOOS" == "" ]; then 39 echo "Must specify \$GOARCH and \$GOOS" 40 exit 1 41fi 42 43mkargs="" 44 45if [ "$GOARCH" == "386" ] || [ "$GOARCH" == "arm" ]; then 46 mkargs="-l32" 47fi 48 49for f in "$@"; do 50 $mksyscall $mkargs "${f}_${GOOS}.go" | fix > "${f}_${GOOS}_${GOARCH}.go" 51done 52 53