Makefile.cross-compiles 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. export PATH := $(PATH):`go env GOPATH`/bin
  2. export GO111MODULE=on
  3. LDFLAGS := -s -w
  4. os-archs=darwin:amd64 darwin:arm64 freebsd:amd64 linux:amd64 linux:arm linux:arm:6 linux:arm64 windows:amd64 windows:arm64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat linux:riscv64 android:arm64
  5. all: build
  6. build: app
  7. app:
  8. @$(foreach n, $(os-archs), \
  9. os=$(shell echo "$(n)" | cut -d : -f 1); \
  10. arch=$(shell echo "$(n)" | cut -d : -f 2); \
  11. extra=$(shell echo "$(n)" | cut -d : -f 3); \
  12. flags=''; \
  13. target_suffix=$${os}_$${arch}; \
  14. if [ "$${os}" = "linux" ] && [ "$${arch}" = "arm" ] && [ "$${extra}" != "" ] ; then \
  15. flags=GOARM=$${extra}; \
  16. target_suffix=$${os}_$${arch}_$${extra}; \
  17. elif [ "$${os}" = "linux" ] && [ "$${arch}" = "mips" ] && [ "$${extra}" != "" ] ; then \
  18. flags=GOMIPS=$${extra}; \
  19. fi; \
  20. echo "Build $${os}-$${arch}$${extra:+ ($${extra})}..."; \
  21. env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} $${flags} go build -trimpath -ldflags "$(LDFLAGS)" -tags frpc -o ./release/frpc_$${target_suffix} ./cmd/frpc; \
  22. env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} $${flags} go build -trimpath -ldflags "$(LDFLAGS)" -tags frps -o ./release/frps_$${target_suffix} ./cmd/frps; \
  23. echo "Build $${os}-$${arch}$${extra:+ ($${extra})} done"; \
  24. )
  25. @mv ./release/frpc_windows_amd64 ./release/frpc_windows_amd64.exe
  26. @mv ./release/frps_windows_amd64 ./release/frps_windows_amd64.exe
  27. @mv ./release/frpc_windows_arm64 ./release/frpc_windows_arm64.exe
  28. @mv ./release/frps_windows_arm64 ./release/frps_windows_arm64.exe