github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/Makefile (about)

     1  .DEFAULT_GOAL = all
     2  
     3  GO_VERSION ?= 1.22.0
     4  
     5  .PHONY: all
     6  all: sync remove fix fmt commit
     7  
     8  define ditto
     9  ditto ${GO_SRC}/${1} ${2}
    10  sed -i 's|package main|package $(shell basename ${2})|' ${2}/*.go || true
    11  endef
    12  
    13  .PHONY: sync
    14  sync:
    15  	go run golang.org/dl/go${GO_VERSION}@latest download
    16  	rm -rf $(shell find . -mindepth 1 -maxdepth 1 -type d -not -iwholename '**.git**' -not -iwholename '**_**' -not -iwholename '**assembler**' | sort)
    17  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/internal,.)
    18  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/internal,./cmd)
    19  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/api,./cmd/api)
    20  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/asm/internal,./cmd/asm)
    21  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/cgo,./cmd/cgo)
    22  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/compile/internal,./cmd/compile)
    23  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/covdata,./cmd/covdata)
    24  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/dist,./cmd/dist)
    25  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/doc,./cmd/doc)
    26  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/fix,./cmd/fix)
    27  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/go/internal,./cmd/go)
    28  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/gofmt,./cmd/gofmt)
    29  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/link/internal,./cmd/link)
    30  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/nm,./cmd/nm)
    31  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/objdump,./cmd/objdump)
    32  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/pack,./cmd/pack)
    33  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/pprof,./cmd/pprof)
    34  	$(call ditto,${HOME}/sdk/go${GO_VERSION}/src/cmd/trace,./cmd/trace)
    35  
    36  .PHONY: remove
    37  remove:
    38  	rm -f  abi/abi_test.go abi/abi_test.s abi/export_test.go
    39  	rm -f  bytealg/compare_amd64.s bytealg/compare_arm64.s bytealg/equal_amd64.s bytealg/equal_arm64.s
    40  	rm -fr cmd/cgo/internal/test/ cmd/cgo/internal cmd/cgo/internal/testcarchive/
    41  	rm -f  cmd/covdata/tool_test.go
    42  	rm -f  fuzz/trace.go
    43  	rm -f  syscall/unix/getentropy_darwin.go syscall/unix/pty_darwin.go syscall/unix/user_darwin.go syscall/unix/net_darwin.go testpty/pty_darwin.go
    44  
    45  define fix_linkname
    46  sed -i -E ':a;N;$$!ba;s|${1}|${2}|' ${3}
    47  endef
    48  
    49  .PHONY: fix
    50  fix: fix/linkname fix/import
    51  	sed -i -E 's|!(darwin)|\1|' testpty/pty_none.go
    52  
    53  .PHONY: fix/linkname
    54  fix/linkname:
    55  	$(call fix_linkname,(//go:noescape)\n(func Compare),\1\n//go:linkname Compare internal/bytealg.Compare\n\2,bytealg/compare_native.go)
    56  	$(call fix_linkname,import "sync/atomic",import (\n	"sync/atomic"\n	_ "unsafe" // for go:linkname\n),poll/fd_mutex.go)
    57  	$(call fix_linkname,\n(func runtime_Semacquire),\n\n//go:linkname runtime_Semacquire runtime.semacquire\n\1,poll/fd_mutex.go)
    58  	$(call fix_linkname,(func runtime_Semrelease),//go:linkname runtime_Semrelease runtime.semrelease\n\1,poll/fd_mutex.go)
    59  	$(call fix_linkname,\n(func runtime_pollServerInit),//go:linkname runtime_pollServerInit runtime.pollServerInit\n\1,poll/fd_poll_runtime.go)
    60  	$(call fix_linkname,\n(func runtime_pollOpen),\n//go:linkname runtime_pollOpen runtime.pollOpen\n\1,poll/fd_poll_runtime.go)
    61  	$(call fix_linkname,\n(func runtime_pollClose),\n//go:linkname runtime_pollClose runtime.pollClose\n\1,poll/fd_poll_runtime.go)
    62  	$(call fix_linkname,\n(func runtime_pollWait),\n//go:linkname runtime_pollWait runtime.pollWait\n\1,poll/fd_poll_runtime.go)
    63  	$(call fix_linkname,\n(func runtime_pollWaitCanceled),\n//go:linkname runtime_pollWaitCanceled runtime.pollWaitCanceled\n\1,poll/fd_poll_runtime.go)
    64  	$(call fix_linkname,\n(func runtime_pollReset),\n//go:linkname runtime_pollReset runtime.pollReset\n\1,poll/fd_poll_runtime.go)
    65  	$(call fix_linkname,\n(func runtime_pollSetDeadline),\n//go:linkname runtime_pollSetDeadline runtime.pollSetDeadline\n\1,poll/fd_poll_runtime.go)
    66  	$(call fix_linkname,\n(func runtime_pollUnblock),\n//go:linkname runtime_pollUnblock runtime.pollUnblock\n\1,poll/fd_poll_runtime.go)
    67  	$(call fix_linkname,\n(func runtime_isPollServerDescriptor),\n//go:linkname runtime_isPollServerDescriptor runtime.isPollServerDescriptor\n\1,poll/fd_poll_runtime.go)
    68  	sed -i -E ':a;N;$$!ba;s|func resolveNameOff\(ptrInModule unsafe.Pointer, off int32\) unsafe.Pointer|//go:linkname resolveNameOff internal/reflectlite.resolveTypeOff\nfunc resolveNameOff\(ptrInModule unsafe.Pointer, off int32\) unsafe.Pointer|' reflectlite/type.go
    69  	sed -i -E ':a;N;$$!ba;s|func resolveTypeOff\(rtype unsafe.Pointer, off int32\) unsafe.Pointer|//go:linkname resolveTypeOff internal/reflectlite.resolveTypeOff\nfunc resolveTypeOff\(rtype unsafe.Pointer, off int32\) unsafe.Pointer|' reflectlite/type.go
    70  	sed -i -E ':a;N;$$!ba;s|// implemented in package runtime\nfunc unsafe_New\(\*rtype\) unsafe.Pointer|// implemented in package runtime\n//go:linkname unsafe_New internal/reflectlite.unsafe_New\nfunc unsafe_New\(\*rtype\) unsafe.Pointer|' reflectlite/value.go
    71  	sed -i -E ':a;N;$$!ba;s|func ifaceE2I\(t \*rtype, src any, dst unsafe.Pointer\)|//go:linkname ifaceE2I internal/reflectlite.ifaceE2I\nfunc ifaceE2I\(t \*rtype, src any, dst unsafe.Pointer\)|' reflectlite/value.go
    72  	sed -i -E ':a;N;$$!ba;s|func typedmemmove\(t \*rtype, dst, src unsafe.Pointer\)|//go:linkname typedmemmove internal/reflectlite.typedmemmove\nfunc typedmemmove\(t \*rtype, dst, src unsafe.Pointer\)|' reflectlite/value.go
    73  	sed -i -E 's|block<ABIInternal>|block|g' chacha8rand/chacha8_amd64.s
    74  
    75  .PHONY: fix/import
    76  fix/import:
    77  	grep -rl 'cmd/internal/' ${CURDIR}/** | grep -v Makefile | xargs sed -i 's|cmd/internal/|github.com/go-asm/go/cmd/|g'
    78  	grep -rl 'internal/' ${CURDIR}/** | grep -v Makefile | xargs sed -i 's|internal/|github.com/go-asm/go/|g'
    79  	grep -rl 'cmd/.*/github.com/go-asm' ${CURDIR}/** | grep -v -e Makefile | xargs sed -i -E 's|cmd/(.*)/github.com/go-asm/go|github.com/go-asm/go/cmd/\1|g'
    80  	grep -rl 'github.com/go-asm/go/cmd/go/github.com/go-asm/go' ${CURDIR}/** | grep -v -e Makefile | xargs sed -i -E 's|github.com/go-asm/go/cmd/go/github.com/go-asm/go|github.com/go-asm/go/cmd/go|g'
    81  	grep -rl 'github.com/go-asm/go/cmd/go/lockedfile/filelock' ${CURDIR}/** | grep -v -e Makefile | xargs sed -i -E 's|github.com/go-asm/go/cmd/go/lockedfile/filelock|github.com/go-asm/go/cmd/go/lockedfile/internal/filelock|g'
    82  	grep -rl 'github.com/go-asm/go/cmd/go/test/genflags' ${CURDIR}/** | grep -v -e Makefile | xargs sed -i -E 's|github.com/go-asm/go/cmd/go/test/genflags|github.com/go-asm/go/cmd/go/test/internal/genflags|g'
    83  	grep -rl '"github.com/go-asm/go/cmd/compile/github.com/go-asm/go/pgo/graph"' ${CURDIR}/** | grep -v -e Makefile | xargs sed -i -E 's|"github.com/go-asm/go/cmd/compile/github.com/go-asm/go/pgo/graph"|"github.com/go-asm/go/cmd/compile/pgo/internal/graph"|g'
    84  	sed -i 's|../../github.com/go-asm/go/cmd/reflectdata/reflect.go|src/cmd/reflectdata/reflect.go|g' reflectlite/type.go
    85  
    86  .PHONY: fmt
    87  fmt:
    88  	@gofmt -w -s $(shell find . -type f -iwholename '*.go' -not -iwholename '*.git*' -not -iwholename '*testdata*')
    89  	@goimports -w -local=github.com/go-asm/go $(shell find . -type f -iwholename '*.go' -not -iwholename '*.git*' -not -iwholename '*testdata*')
    90  
    91  .PHONY: commit
    92  commit:
    93  	git add .
    94  	git commit --gpg-sign --signoff -m "all: sync to go${GO_VERSION}"
    95  	@rm -rf ${HOME}/sdk/go${GO_VERSION}
    96  
    97  .PHONY: check
    98  check:
    99  	@go build -o /dev/null ./...
   100  	@if go vet ./... 2>&1 | grep -E -v -e '#.*' -e 'missing Go declaration' -e 'possible misuse of unsafe.Pointer'; then exit 1; fi