2023-02-21 20:31:49 +00:00
IOS_OUT := ./ios
.PHONY : all linux android windows macos clean ios
2023-03-18 17:59:38 +00:00
2023-02-21 20:31:49 +00:00
DEFAULT_GOAL : linux
all : linux android windows
2023-07-24 14:59:07 +00:00
ARCH := $( shell uname -m)
ARM_X_CC := aarch64-linux-gnu-gcc
# determine if the x64 cross arm64 compiler is available so we can add that target
LINUX_X_ARM =
i f n e q ( , $( shell which $ ( ARM_X_CC ) ) )
LINUX_X_ARM = libCwtch.x.so
e n d i f
2023-08-02 20:12:53 +00:00
linux : EXPERIMENTS ?= "serverExperiment "
2023-07-25 21:46:52 +00:00
linux : libCwtch .so $( LINUX_X_ARM )
2023-02-21 20:31:49 +00:00
2023-08-02 20:12:53 +00:00
macos : EXPERIMENTS ?= "serverExperiment "
2023-02-21 20:31:49 +00:00
macos : libCwtch .x 64.dylib libCwtch .arm 64.dylib
2023-08-02 20:12:53 +00:00
android : EXPERIMENTS ?= ""
2023-02-21 20:31:49 +00:00
android : cwtch .aar
2023-08-02 20:12:53 +00:00
windows : EXPERIMENTS ?= "serverExperiment "
2023-02-21 20:31:49 +00:00
windows : libCwtch .dll
2023-03-18 17:59:38 +00:00
lib.go : generate /generate_bindings .go spec
go run generate/generate_bindings.go --experiments " $( EXPERIMENTS) "
2023-07-24 14:59:07 +00:00
libCwtch.so : lib .go
2023-02-21 20:31:49 +00:00
./switch-ffi.sh
2023-07-24 14:59:07 +00:00
go build -trimpath -ldflags " -buildid=autobindings- $( shell git describe --tags) -X main.buildVer=autobindings- $( shell git describe --tags) -X main.buildDate= $( shell git log -1 --format= %cd --date= format:%G-%m-%d-%H-%M) " -buildmode c-shared -o libCwtch.so
2023-03-13 20:12:50 +00:00
mkdir -p build/linux
2023-07-24 14:59:07 +00:00
i f e q ( $( ARCH ) , x 8 6 _ 6 4 )
mv libCwtch.so build/linux/libCwtch.x64.so
e l s e i f e q ( $( ARCH ) , a a r c h 6 4 )
mv libCwtch.so build/linux/libCwtch.arm64.so
e n d i f
mv libCwtch.h build/linux/libCwtch.h
libCwtch.x.so : lib .go
2023-05-13 15:36:00 +00:00
./switch-ffi.sh
mkdir -p build/linux
2023-07-24 14:59:07 +00:00
i f e q ( $( ARCH ) , x 8 6 _ 6 4 )
2024-03-03 19:09:05 +00:00
env CGO_ENABLED = 1 CC = $( ARM_X_CC) GOARCH = arm64 go build -trimpath -ldflags " -buildid=autobindings- $( shell git describe --tags) -X main.buildVer=autobindings- $( shell git describe --tags) -X main.buildDate= $( shell git log -1 --format= %cd --date= format:%G-%m-%d-%H-%M) " -buildmode c-shared -o libCwtch.x.so
2023-07-24 14:59:07 +00:00
mv libCwtch.x.so build/linux/libCwtch.arm64.so
mv libCwtch.x.h build/linux/libCwtch.h
e n d i f
2023-02-21 20:31:49 +00:00
libCwtch.x64.dylib : lib .go
./switch-ffi.sh
2024-01-06 02:11:05 +00:00
env CGO_CFLAGS = "-mmacosx-version-min=10.12" CGO_LDFLAGS = "-mmacosx-version-min=10.12" GOARCH = amd64 GOOS = darwin CGO_ENABLED = 1 go build -trimpath -ldflags " -buildid=autobindings- $( shell git describe --tags) -X main.buildVer=autobindings- $( shell git describe --tags) -X main.buildDate= $( shell git log -1 --format= %cd --date= format:%G-%m-%d-%H-%M) " -buildmode c-shared -o libCwtch.x64.dylib
2023-03-13 20:12:50 +00:00
mkdir -p build/macos
mv libCwtch.x64.dylib build/macos/
2023-02-21 20:31:49 +00:00
libCwtch.arm64.dylib : lib .go
./switch-ffi.sh
2024-01-05 21:10:38 +00:00
env CGO_CFLAGS = "-mmacosx-version-min=10.12" CGO_LDFLAGS = "-mmacosx-version-min=10.12" GOARCH = arm64 GOOS = darwin CGO_ENABLED = 1 go build -trimpath -ldflags " -buildid= $( shell git describe --tags) -X main.buildVer= $( shell git describe --tags) -X main.buildDate= $( shell git log -1 --format= %cd --date= format:%G-%m-%d-%H-%M) " -buildmode c-shared -o libCwtch.arm64.dylib
2023-03-13 20:12:50 +00:00
mkdir -p build/macos
mv libCwtch.arm64.dylib build/macos/
2023-02-21 20:31:49 +00:00
cwtch.aar : lib .go
./switch-gomobile.sh
gomobile bind -trimpath -target android/arm,android/arm64,android/amd64 -ldflags= " -buildid= $( shell git describe --tags) -X cwtch.buildVer= $( shell git describe --tags) -X cwtch.buildDate= $( shell git log -1 --format= %cd --date= format:%G-%m-%d-%H-%M) "
2023-03-13 20:12:50 +00:00
mkdir -p build/android
mv cwtch.aar build/android/
mv cwtch-sources.jar build/android/
2023-02-21 20:31:49 +00:00
libCwtch.dll : lib .go
./switch-ffi.sh
# '-Xlinker --no-insert-timestamp` sets the output dll PE timestamp header to all zeros, instead of the actual time
# this is necessary for reproducible builds (see: https://wiki.debian.org/ReproducibleBuilds/TimestampsInPEBinaries for additional information)
# note: the above documentation also references an ability to set an optional timestamp - this behaviour seems to no longer be supported in more recent versions of mingw32-gcc (the help docs no longer reference that functionality)
# these flags have to be passed through to the underlying gcc process using the -extldflags option in the underlying go linker, note that the whole flag is quoted...this is necessary.
GOOS = windows GOARCH = amd64 CGO_ENABLED = 1 CC = x86_64-w64-mingw32-gcc-win32 go build -trimpath -ldflags " -buildid= $( shell git describe --tags) -X main.buildVer= $( shell git describe --tags) -X main.buildDate= $( shell git log -1 --format= %cd --date= format:%G-%m-%d-%H-%M) '-extldflags=-Xlinker --no-insert-timestamp' " -buildmode c-shared -o libCwtch.dll
2023-03-13 20:12:50 +00:00
mkdir -p build/windows
mv libCwtch.dll build/windows/
mv libCwtch.h build/windows/
2023-02-21 20:31:49 +00:00
2023-03-18 17:59:38 +00:00
clean-autobindings :
rm -f lib.go
2023-02-21 20:31:49 +00:00
clean :
2023-05-13 15:36:00 +00:00
rm -fr lib.go cwtch.aar cwtch_go.apk libCwtch.*.h libCwtch.*.so cwtch-sources.jar libCwtch.dll libCwtch.*.dylib build
2023-02-21 20:31:49 +00:00
# iOS - for testing purposes only for now, not officially supported
ios-arm64 :
CGO_ENABLED = 1 \
GOOS = darwin \
GOARCH = arm64 \
SDK = iphoneos \
CGO_CFLAGS = "-fembed-bitcode" \
CC = $( PWD) /clangwrap.sh \
go build -buildmode= c-archive -tags ios -o $( IOS_OUT) /arm64.a .
ios-x86_64 :
CGO_ENABLED = 1 \
GOOS = darwin \
GOARCH = amd64 \
SDK = iphonesimulator \
CC = $( PWD) /clangwrap.sh \
go build -buildmode= c-archive -tags ios -o $( IOS_OUT) /x86_64.a .
ios : ios -arm 64 ios -x 86_ 64
lipo $( IOS_OUT) /x86_64.a $( IOS_OUT) /arm64.a -create -output $( IOS_OUT) /cwtch.a
cp $( IOS_OUT) /arm64.h $( IOS_OUT) /cwtch.h