1
0

Makefile.cross-compiles 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  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:7 linux:arm:5 linux:arm64 windows:amd64 windows:arm64 linux:mips64 linux:mips64le linux:mips:softfloat linux:mipsle:softfloat linux:riscv64 linux:loong64 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. if [ "$${extra}" = "7" ]; then \
  16. flags=GOARM=7; \
  17. target_suffix=$${os}_arm_hf; \
  18. elif [ "$${extra}" = "5" ]; then \
  19. flags=GOARM=5; \
  20. target_suffix=$${os}_arm; \
  21. fi; \
  22. elif [ "$${os}" = "linux" ] && ([ "$${arch}" = "mips" ] || [ "$${arch}" = "mipsle" ]) && [ "$${extra}" != "" ] ; then \
  23. flags=GOMIPS=$${extra}; \
  24. fi; \
  25. echo "Build $${os}-$${arch}$${extra:+ ($${extra})}..."; \
  26. env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} $${flags} go build -trimpath -ldflags "$(LDFLAGS)" -tags frpc -o ./release/frpc_$${target_suffix} ./cmd/frpc; \
  27. env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} $${flags} go build -trimpath -ldflags "$(LDFLAGS)" -tags frps -o ./release/frps_$${target_suffix} ./cmd/frps; \
  28. echo "Build $${os}-$${arch}$${extra:+ ($${extra})} done"; \
  29. )
  30. @mv ./release/frpc_windows_amd64 ./release/frpc_windows_amd64.exe
  31. @mv ./release/frps_windows_amd64 ./release/frps_windows_amd64.exe
  32. @mv ./release/frpc_windows_arm64 ./release/frpc_windows_arm64.exe
  33. @mv ./release/frps_windows_arm64 ./release/frps_windows_arm64.exe