sys/unix/mkall.sh

232 строки
8.0 KiB
Bash
Исходник Постоянная ссылка Обычный вид История

#!/usr/bin/env bash
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
unix: generate all Linux go files from source Right now the process for adding in new constants, errors, or syscalls for Linux is a pain and unreliable. The scripts are designed to be run on the target architecture and use the header files installed on the user's system. This makes it hard to generate files for all the architectures or to have consistency between users. See golang/go#15282. This CL fixes this issue by making all of the files for the 11 supported architectures directly from source checkouts of Linux, glibc, and bluez. This is done using Docker, the gcc cross-compilers, and qemu emulation. Previously discussed here: https://go-review.googlesource.com/c/37589/ A README.md file is also added to explain how all the parts of the build system work. In order to get the build working for all the architectures, I made some changes to the other scripts called from mkall_linux.go: - Files only used for generating linux code, moved to linux/ - linux/mksysnum.pl supports a specified CC compiler. - The generated C code in mkerrors.sh changed to avoid a warning - mkerrors.sh headers changed to fix powerpc64 bug in sys/ioctl.h - linux/types.go no longer needs to export Ptrace structs in lowercase Build instructions: - Host system needs to be x86-64 Linux - Install Docker (https://docs.docker.com/engine/installation/) - ./mkall.sh (That's it!!!) Change-Id: I87067c14442ba12f8d51991349a43a9d73f38ae0 Reviewed-on: https://go-review.googlesource.com/37943 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-03-08 21:50:27 +03:00
# This script runs or (given -n) prints suggested commands to generate files for
# the Architecture/OS specified by the GOARCH and GOOS environment variables.
# See README.md for more information about how the build system works.
GOOSARCH="${GOOS}_${GOARCH}"
# defaults
mksyscall="go run mksyscall.go"
mkerrors="./mkerrors.sh"
zerrors="zerrors_$GOOSARCH.go"
mksysctl=""
zsysctl="zsysctl_$GOOSARCH.go"
mksysnum=
mktypes=
mkasm=
run="sh"
unix: generate all Linux go files from source Right now the process for adding in new constants, errors, or syscalls for Linux is a pain and unreliable. The scripts are designed to be run on the target architecture and use the header files installed on the user's system. This makes it hard to generate files for all the architectures or to have consistency between users. See golang/go#15282. This CL fixes this issue by making all of the files for the 11 supported architectures directly from source checkouts of Linux, glibc, and bluez. This is done using Docker, the gcc cross-compilers, and qemu emulation. Previously discussed here: https://go-review.googlesource.com/c/37589/ A README.md file is also added to explain how all the parts of the build system work. In order to get the build working for all the architectures, I made some changes to the other scripts called from mkall_linux.go: - Files only used for generating linux code, moved to linux/ - linux/mksysnum.pl supports a specified CC compiler. - The generated C code in mkerrors.sh changed to avoid a warning - mkerrors.sh headers changed to fix powerpc64 bug in sys/ioctl.h - linux/types.go no longer needs to export Ptrace structs in lowercase Build instructions: - Host system needs to be x86-64 Linux - Install Docker (https://docs.docker.com/engine/installation/) - ./mkall.sh (That's it!!!) Change-Id: I87067c14442ba12f8d51991349a43a9d73f38ae0 Reviewed-on: https://go-review.googlesource.com/37943 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-03-08 21:50:27 +03:00
cmd=""
case "$1" in
-syscalls)
for i in zsyscall*go
do
# Run the command line that appears in the first line
# of the generated file to regenerate it.
sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
rm _$i
done
exit 0
;;
-n)
run="cat"
unix: generate all Linux go files from source Right now the process for adding in new constants, errors, or syscalls for Linux is a pain and unreliable. The scripts are designed to be run on the target architecture and use the header files installed on the user's system. This makes it hard to generate files for all the architectures or to have consistency between users. See golang/go#15282. This CL fixes this issue by making all of the files for the 11 supported architectures directly from source checkouts of Linux, glibc, and bluez. This is done using Docker, the gcc cross-compilers, and qemu emulation. Previously discussed here: https://go-review.googlesource.com/c/37589/ A README.md file is also added to explain how all the parts of the build system work. In order to get the build working for all the architectures, I made some changes to the other scripts called from mkall_linux.go: - Files only used for generating linux code, moved to linux/ - linux/mksysnum.pl supports a specified CC compiler. - The generated C code in mkerrors.sh changed to avoid a warning - mkerrors.sh headers changed to fix powerpc64 bug in sys/ioctl.h - linux/types.go no longer needs to export Ptrace structs in lowercase Build instructions: - Host system needs to be x86-64 Linux - Install Docker (https://docs.docker.com/engine/installation/) - ./mkall.sh (That's it!!!) Change-Id: I87067c14442ba12f8d51991349a43a9d73f38ae0 Reviewed-on: https://go-review.googlesource.com/37943 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-03-08 21:50:27 +03:00
cmd="echo"
shift
esac
case "$#" in
0)
;;
*)
echo 'usage: mkall.sh [-n]' 1>&2
exit 2
esac
if [[ "$GOOS" = "linux" ]]; then
# Use the Docker-based build system
unix: generate all Linux go files from source Right now the process for adding in new constants, errors, or syscalls for Linux is a pain and unreliable. The scripts are designed to be run on the target architecture and use the header files installed on the user's system. This makes it hard to generate files for all the architectures or to have consistency between users. See golang/go#15282. This CL fixes this issue by making all of the files for the 11 supported architectures directly from source checkouts of Linux, glibc, and bluez. This is done using Docker, the gcc cross-compilers, and qemu emulation. Previously discussed here: https://go-review.googlesource.com/c/37589/ A README.md file is also added to explain how all the parts of the build system work. In order to get the build working for all the architectures, I made some changes to the other scripts called from mkall_linux.go: - Files only used for generating linux code, moved to linux/ - linux/mksysnum.pl supports a specified CC compiler. - The generated C code in mkerrors.sh changed to avoid a warning - mkerrors.sh headers changed to fix powerpc64 bug in sys/ioctl.h - linux/types.go no longer needs to export Ptrace structs in lowercase Build instructions: - Host system needs to be x86-64 Linux - Install Docker (https://docs.docker.com/engine/installation/) - ./mkall.sh (That's it!!!) Change-Id: I87067c14442ba12f8d51991349a43a9d73f38ae0 Reviewed-on: https://go-review.googlesource.com/37943 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-03-08 21:50:27 +03:00
# Files generated through docker (use $cmd so you can Ctl-C the build or run)
$cmd docker build --tag generate:$GOOS $GOOS
$cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")/.." && /bin/pwd):/build generate:$GOOS
unix: generate all Linux go files from source Right now the process for adding in new constants, errors, or syscalls for Linux is a pain and unreliable. The scripts are designed to be run on the target architecture and use the header files installed on the user's system. This makes it hard to generate files for all the architectures or to have consistency between users. See golang/go#15282. This CL fixes this issue by making all of the files for the 11 supported architectures directly from source checkouts of Linux, glibc, and bluez. This is done using Docker, the gcc cross-compilers, and qemu emulation. Previously discussed here: https://go-review.googlesource.com/c/37589/ A README.md file is also added to explain how all the parts of the build system work. In order to get the build working for all the architectures, I made some changes to the other scripts called from mkall_linux.go: - Files only used for generating linux code, moved to linux/ - linux/mksysnum.pl supports a specified CC compiler. - The generated C code in mkerrors.sh changed to avoid a warning - mkerrors.sh headers changed to fix powerpc64 bug in sys/ioctl.h - linux/types.go no longer needs to export Ptrace structs in lowercase Build instructions: - Host system needs to be x86-64 Linux - Install Docker (https://docs.docker.com/engine/installation/) - ./mkall.sh (That's it!!!) Change-Id: I87067c14442ba12f8d51991349a43a9d73f38ae0 Reviewed-on: https://go-review.googlesource.com/37943 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-03-08 21:50:27 +03:00
exit
fi
GOOSARCH_in=syscall_$GOOSARCH.go
case "$GOOSARCH" in
_* | *_ | _)
echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
exit 1
;;
aix_ppc)
mkerrors="$mkerrors -maix32"
mksyscall="go run mksyscall_aix_ppc.go -aix"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
aix_ppc64)
mkerrors="$mkerrors -maix64"
mksyscall="go run mksyscall_aix_ppc64.go -aix"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
darwin_amd64)
mkerrors="$mkerrors -m64"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
mkasm="go run mkasm_darwin.go"
;;
darwin_arm64)
mkerrors="$mkerrors -m64"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
mkasm="go run mkasm_darwin.go"
;;
dragonfly_amd64)
mkerrors="$mkerrors -m64"
mksyscall="go run mksyscall.go -dragonfly"
mksysnum="go run mksysnum.go 'https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
freebsd_386)
mkerrors="$mkerrors -m32"
mksyscall="go run mksyscall.go -l32"
mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
freebsd_amd64)
mkerrors="$mkerrors -m64"
mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
freebsd_arm)
mkerrors="$mkerrors"
mksyscall="go run mksyscall.go -l32 -arm"
mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
# Let the type of C char be signed for making the bare syscall
# API consistent across platforms.
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
;;
freebsd_arm64)
mkerrors="$mkerrors -m64"
mksysnum="go run mksysnum.go 'https://svn.freebsd.org/base/stable/11/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
;;
netbsd_386)
mkerrors="$mkerrors -m32"
mksyscall="go run mksyscall.go -l32 -netbsd"
mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
netbsd_amd64)
mkerrors="$mkerrors -m64"
mksyscall="go run mksyscall.go -netbsd"
mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
netbsd_arm)
mkerrors="$mkerrors"
mksyscall="go run mksyscall.go -l32 -netbsd -arm"
mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
# Let the type of C char be signed for making the bare syscall
# API consistent across platforms.
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
;;
netbsd_arm64)
mkerrors="$mkerrors -m64"
mksyscall="go run mksyscall.go -netbsd"
mksysnum="go run mksysnum.go 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
openbsd_386)
mkerrors="$mkerrors -m32"
mksyscall="go run mksyscall.go -l32 -openbsd"
mksysctl="go run mksysctl_openbsd.go"
mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
openbsd_amd64)
mkerrors="$mkerrors -m64"
mksyscall="go run mksyscall.go -openbsd"
mksysctl="go run mksysctl_openbsd.go"
mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
openbsd_arm)
mkerrors="$mkerrors"
mksyscall="go run mksyscall.go -l32 -openbsd -arm"
mksysctl="go run mksysctl_openbsd.go"
mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
# Let the type of C char be signed for making the bare syscall
# API consistent across platforms.
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
;;
openbsd_arm64)
mkerrors="$mkerrors -m64"
mksyscall="go run mksyscall.go -openbsd"
mksysctl="go run mksysctl_openbsd.go"
mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
# Let the type of C char be signed for making the bare syscall
# API consistent across platforms.
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
;;
openbsd_mips64)
mkerrors="$mkerrors -m64"
mksyscall="go run mksyscall.go -openbsd"
mksysctl="go run mksysctl_openbsd.go"
mksysnum="go run mksysnum.go 'https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master'"
# Let the type of C char be signed for making the bare syscall
# API consistent across platforms.
mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
;;
solaris_amd64)
mksyscall="go run mksyscall_solaris.go"
mkerrors="$mkerrors -m64"
mksysnum=
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
illumos_amd64)
mksyscall="go run mksyscall_solaris.go"
mkerrors=
mksysnum=
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
*)
echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
exit 1
;;
esac
(
if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
case "$GOOS" in
*)
syscall_goos="syscall_$GOOS.go"
case "$GOOS" in
darwin | dragonfly | freebsd | netbsd | openbsd)
syscall_goos="syscall_bsd.go $syscall_goos"
;;
esac
if [ -n "$mksyscall" ]; then
if [ "$GOOSARCH" == "aix_ppc64" ]; then
# aix/ppc64 script generates files instead of writing to stdin.
echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in && gofmt -w zsyscall_$GOOSARCH.go && gofmt -w zsyscall_"$GOOSARCH"_gccgo.go && gofmt -w zsyscall_"$GOOSARCH"_gc.go " ;
elif [ "$GOOS" == "darwin" ]; then
# 1.12 and later, syscalls via libSystem
echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
# 1.13 and later, syscalls via libSystem (including syscallPtr)
echo "$mksyscall -tags $GOOS,$GOARCH,go1.13 syscall_darwin.1_13.go |gofmt >zsyscall_$GOOSARCH.1_13.go";
elif [ "$GOOS" == "illumos" ]; then
# illumos code generation requires a --illumos switch
echo "$mksyscall -illumos -tags illumos,$GOARCH syscall_illumos.go |gofmt > zsyscall_illumos_$GOARCH.go";
# illumos implies solaris, so solaris code generation is also required
echo "$mksyscall -tags solaris,$GOARCH syscall_solaris.go syscall_solaris_$GOARCH.go |gofmt >zsyscall_solaris_$GOARCH.go";
else
echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
fi
fi
esac
if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go"; fi
if [ -n "$mkasm" ]; then echo "$mkasm $GOARCH"; fi
) | $run