Skip to content

Instantly share code, notes, and snippets.

@fudanchii
Last active December 19, 2020 22:58
Show Gist options
  • Save fudanchii/9bdbc0d94c29c57475cc5df37bc8387c to your computer and use it in GitHub Desktop.
Save fudanchii/9bdbc0d94c29c57475cc5df37bc8387c to your computer and use it in GitHub Desktop.
generic Makefile for Go cross compilation to ios/arm64 from linux
CC = $(IOS_TOOLCHAIN_BIN)/arm64-apple-darwin14-clang
CGO_ENABLED = 1
IOS_SDK_FLAGS = -isysroot $(IOS_SDK_PATH)/iPhoneOS11.2.sdk
USE_LD_FLAG = -fuse-ld=$(IOS_TOOLCHAIN_BIN)/arm64-apple-darwin14-ld
TARGET_ARCH = -arch arm64
CGO_CFLAGS = $(IOS_SDK_FLAGS) $(TARGET_ARCH)
CGO_LDFLAGS = $(USE_LD_FLAGS) $(IOS_SDK_FLAGS) $(TARGET_ARCH)
GOOS = ios
GOARCH = arm64
GO = go1.16beta1
.PHONY: check
$(notdir $(PWD)).ios: check
CGO_ENABLED="$(CGO_ENABLED)" CC="$(CC)" CGO_CFLAGS="$(CGO_CFLAGS)" \
CGO_LDFLAGS="$(CGO_LDFLAGS)" GOOS="$(GOOS)" GOARCH="$(GOARCH)" \
$(GO) build \
--ldflags "-extld '$(CC)' -extldflags '$(CGO_LDFLAGS)'" \
-o $@
check:
ifndef IOS_TOOLCHAIN_BIN
$(error IOS_TOOLCHAIN_BIN is not set)
endif
ifndef IOS_SDK_PATH
$(error IOS_SDK_PATH is not set)
endif
@fudanchii
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment