2024-03-14 23:44:36 +01:00
|
|
|
.ONESHELL:
|
2023-10-16 21:14:54 +03:30
|
|
|
PRODUCT_NAME=libcore
|
2024-02-02 15:44:33 +01:00
|
|
|
BASENAME=$(PRODUCT_NAME)
|
2023-08-16 15:16:02 +03:30
|
|
|
BINDIR=bin
|
2024-02-02 15:44:33 +01:00
|
|
|
LIBNAME=$(PRODUCT_NAME)
|
2024-03-09 15:49:09 +01:00
|
|
|
CLINAME=HiddifyCli
|
2023-08-16 15:16:02 +03:30
|
|
|
|
2023-09-11 15:20:19 +03:30
|
|
|
BRANCH=$(shell git branch --show-current)
|
|
|
|
|
VERSION=$(shell git describe --tags || echo "unknown version")
|
2024-02-08 11:31:39 +01:00
|
|
|
ifeq ($(OS),Windows_NT)
|
|
|
|
|
Not available for Windows! use bash in WSL
|
|
|
|
|
endif
|
2023-09-11 15:20:19 +03:30
|
|
|
|
2023-10-27 17:44:18 +03:30
|
|
|
TAGS=with_gvisor,with_quic,with_wireguard,with_ech,with_utls,with_clash_api,with_grpc
|
2024-02-09 00:52:35 +01:00
|
|
|
IOS_ADD_TAGS=with_dhcp,with_low_memory,with_conntrack
|
2024-02-02 15:44:33 +01:00
|
|
|
GOBUILDLIB=CGO_ENABLED=1 go build -trimpath -tags $(TAGS) -ldflags="-w -s" -buildmode=c-shared
|
2024-03-09 21:07:15 +01:00
|
|
|
GOBUILDSRV=CGO_ENABLED=1 go build -trimpath -tags $(TAGS)
|
2023-08-16 15:16:02 +03:30
|
|
|
|
|
|
|
|
lib_install:
|
2023-12-21 11:10:14 +03:30
|
|
|
go install -v github.com/sagernet/gomobile/cmd/gomobile@v0.1.1
|
|
|
|
|
go install -v github.com/sagernet/gomobile/cmd/gobind@v0.1.1
|
2023-08-16 15:16:02 +03:30
|
|
|
|
2023-08-19 14:10:13 +03:30
|
|
|
headers:
|
2024-02-02 15:44:33 +01:00
|
|
|
go build -buildmode=c-archive -o $(BINDIR)/$(LIBNAME).h ./custom
|
2023-08-19 14:10:13 +03:30
|
|
|
|
2023-08-22 20:06:38 +00:00
|
|
|
android: lib_install
|
2024-02-02 15:44:33 +01:00
|
|
|
gomobile bind -v -androidapi=21 -javapkg=io.nekohasekai -libname=box -tags=$(TAGS) -trimpath -target=android -o $(BINDIR)/$(LIBNAME).aar github.com/sagernet/sing-box/experimental/libbox ./mobile
|
2023-08-16 15:16:02 +03:30
|
|
|
|
2023-08-22 20:06:38 +00:00
|
|
|
ios-full: lib_install
|
2024-02-09 00:52:35 +01:00
|
|
|
gomobile bind -v -target ios,iossimulator,tvos,tvossimulator,macos -libname=box -tags=$(TAGS),$(IOS_ADD_TAGS) -trimpath -ldflags="-w -s" -o $(BINDIR)/$(PRODUCT_NAME).xcframework github.com/sagernet/sing-box/experimental/libbox ./mobile
|
2024-02-02 16:15:21 +01:00
|
|
|
mv $(BINDIR)/$(PRODUCT_NAME).xcframework $(BINDIR)/$(LIBNAME).xcframework
|
2024-02-02 15:44:33 +01:00
|
|
|
cp Libcore.podspec $(BINDIR)/$(LIBNAME).xcframework/
|
2024-01-03 16:23:11 +00:00
|
|
|
|
2023-08-22 20:06:38 +00:00
|
|
|
ios: lib_install
|
2024-02-09 00:52:35 +01:00
|
|
|
gomobile bind -v -target ios -libname=box -tags=$(TAGS),$(IOS_ADD_TAGS) -trimpath -ldflags="-w -s" -o $(BINDIR)/Libcore.xcframework github.com/sagernet/sing-box/experimental/libbox ./mobile
|
2024-02-02 16:15:21 +01:00
|
|
|
cp Info.plist $(BINDIR)/Libcore.xcframework/
|
2024-01-10 16:42:14 +00:00
|
|
|
|
2023-10-24 06:47:32 +00:00
|
|
|
|
2024-03-09 15:49:09 +01:00
|
|
|
webui:
|
|
|
|
|
curl -L -o webui.zip https://github.com/hiddify/Yacd-meta/archive/gh-pages.zip
|
|
|
|
|
unzip -d ./ -q webui.zip
|
|
|
|
|
rm webui.zip
|
|
|
|
|
rm -rf bin/webui
|
|
|
|
|
mv Yacd-meta-gh-pages bin/webui
|
|
|
|
|
|
2024-03-09 21:07:15 +01:00
|
|
|
.PHONY: build
|
2023-08-16 15:16:02 +03:30
|
|
|
windows-amd64:
|
2024-02-03 15:55:59 +01:00
|
|
|
curl http://localhost:18020/exit || echo "exited"
|
2024-02-02 15:44:33 +01:00
|
|
|
env GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc $(GOBUILDLIB) -o $(BINDIR)/$(LIBNAME).dll ./custom
|
2024-03-09 21:07:15 +01:00
|
|
|
go install -mod=readonly github.com/akavel/rsrc@latest ||echo "rsrc error in installation"
|
2024-02-02 17:56:24 +01:00
|
|
|
cp $(BINDIR)/$(LIBNAME).dll ./$(LIBNAME).dll
|
2024-03-09 21:07:15 +01:00
|
|
|
$$(go env GOPATH)/bin/rsrc -ico ./assets/hiddify-cli.ico -o ./cli/bydll/cli.syso ||echo "rsrc error in syso"
|
2024-03-09 15:49:09 +01:00
|
|
|
env GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CGO_LDFLAGS="$(LIBNAME).dll" $(GOBUILDSRV) -o $(BINDIR)/$(CLINAME).exe ./cli/bydll
|
2024-02-02 17:56:24 +01:00
|
|
|
rm ./$(LIBNAME).dll
|
2024-03-09 15:49:09 +01:00
|
|
|
make webui
|
|
|
|
|
|
2023-08-16 15:16:02 +03:30
|
|
|
|
2023-08-19 14:10:13 +03:30
|
|
|
linux-amd64:
|
2024-03-10 01:23:34 +01:00
|
|
|
mkdir -p $(BINDIR)/lib
|
|
|
|
|
env GOOS=linux GOARCH=amd64 $(GOBUILDLIB) -o $(BINDIR)/lib/$(LIBNAME).so ./custom
|
2024-03-09 23:35:16 +01:00
|
|
|
mkdir lib
|
2024-03-10 01:23:34 +01:00
|
|
|
cp $(BINDIR)/lib/$(LIBNAME).so ./lib/$(LIBNAME).so
|
2024-03-09 23:35:16 +01:00
|
|
|
env GOOS=linux GOARCH=amd64 CGO_LDFLAGS="./lib/$(LIBNAME).so" $(GOBUILDSRV) -o $(BINDIR)/$(CLINAME) ./cli/bydll
|
|
|
|
|
rm -rf ./lib
|
|
|
|
|
chmod +x $(BINDIR)/$(CLINAME)
|
|
|
|
|
make webui
|
2024-03-09 23:04:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
linux-custom:
|
2024-03-09 23:35:16 +01:00
|
|
|
mkdir -p $(BINDIR)/
|
2024-03-09 23:48:41 +01:00
|
|
|
#env GOARCH=mips $(GOBUILDSRV) -o $(BINDIR)/$(CLINAME) ./cli/
|
|
|
|
|
go build -trimpath -tags $(TAGS) -o $(BINDIR)/$(CLINAME) ./cli/
|
2024-03-09 15:49:09 +01:00
|
|
|
chmod +x $(BINDIR)/$(CLINAME)
|
|
|
|
|
make webui
|
2023-08-19 14:10:13 +03:30
|
|
|
|
2023-08-20 08:21:08 +00:00
|
|
|
macos-amd64:
|
2024-02-09 00:52:35 +01:00
|
|
|
env GOOS=darwin GOARCH=amd64 CGO_CFLAGS="-mmacosx-version-min=10.11" CGO_LDFLAGS="-mmacosx-version-min=10.11" CGO_ENABLED=1 go build -trimpath -tags $(TAGS),$(IOS_ADD_TAGS) -buildmode=c-shared -o $(BINDIR)/$(LIBNAME)-amd64.dylib ./custom
|
2023-08-20 08:21:08 +00:00
|
|
|
macos-arm64:
|
2024-02-09 00:52:35 +01:00
|
|
|
env GOOS=darwin GOARCH=arm64 CGO_CFLAGS="-mmacosx-version-min=10.11" CGO_LDFLAGS="-mmacosx-version-min=10.11" CGO_ENABLED=1 go build -trimpath -tags $(TAGS),$(IOS_ADD_TAGS) -buildmode=c-shared -o $(BINDIR)/$(LIBNAME)-arm64.dylib ./custom
|
2024-02-02 13:47:41 +01:00
|
|
|
|
2023-08-20 08:28:11 +00:00
|
|
|
macos-universal: macos-amd64 macos-arm64
|
2024-02-02 15:59:03 +01:00
|
|
|
lipo -create $(BINDIR)/$(LIBNAME)-amd64.dylib $(BINDIR)/$(LIBNAME)-arm64.dylib -output $(BINDIR)/$(LIBNAME).dylib
|
2024-02-02 17:56:24 +01:00
|
|
|
cp $(BINDIR)/$(LIBNAME).dylib ./$(LIBNAME).dylib
|
2024-03-09 16:38:52 +01:00
|
|
|
env GOOS=darwin GOARCH=amd64 CGO_CFLAGS="-mmacosx-version-min=10.11" CGO_LDFLAGS="-mmacosx-version-min=10.11" CGO_LDFLAGS="bin/$(LIBNAME).dylib" CGO_ENABLED=1 $(GOBUILDSRV) -o $(BINDIR)/$(CLINAME) ./cli/bydll
|
2024-02-02 17:56:24 +01:00
|
|
|
rm ./$(LIBNAME).dylib
|
2024-03-09 15:49:09 +01:00
|
|
|
chmod +x $(BINDIR)/$(CLINAME)
|
2023-08-20 08:21:08 +00:00
|
|
|
|
2023-08-16 15:16:02 +03:30
|
|
|
clean:
|
2023-10-16 21:14:54 +03:30
|
|
|
rm $(BINDIR)/*
|
2024-01-03 16:23:11 +00:00
|
|
|
|
2024-03-03 04:15:19 +01:00
|
|
|
build_protobuf:
|
|
|
|
|
protoc --go_out=. --go-grpc_out=. hiddifyrpc/hiddify.proto
|
|
|
|
|
|
2024-01-03 16:23:11 +00:00
|
|
|
|
2024-03-09 15:49:09 +01:00
|
|
|
|
2024-01-03 16:23:11 +00:00
|
|
|
release: # Create a new tag for release.
|
|
|
|
|
@echo "previous version was $$(git describe --tags $$(git rev-list --tags --max-count=1))"
|
|
|
|
|
@echo "WARNING: This operation will creates version tag and push to github"
|
|
|
|
|
@bash -c '\
|
|
|
|
|
read -p "Version? (provide the next x.y.z semver) : " TAG && \
|
|
|
|
|
echo $$TAG &&\
|
|
|
|
|
[[ "$$TAG" =~ ^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}(\.dev)?$$ ]] || { echo "Incorrect tag. e.g., 1.2.3 or 1.2.3.dev"; exit 1; } && \
|
|
|
|
|
IFS="." read -r -a VERSION_ARRAY <<< "$$TAG" && \
|
|
|
|
|
VERSION_STR="$${VERSION_ARRAY[0]}.$${VERSION_ARRAY[1]}.$${VERSION_ARRAY[2]}" && \
|
|
|
|
|
BUILD_NUMBER=$$(( $${VERSION_ARRAY[0]} * 10000 + $${VERSION_ARRAY[1]} * 100 + $${VERSION_ARRAY[2]} )) && \
|
|
|
|
|
echo "version: $${VERSION_STR}+$${BUILD_NUMBER}" && \
|
2024-01-10 16:42:14 +00:00
|
|
|
sed -i -e "s|<key>CFBundleVersion</key>\s*<string>[^<]*</string>|<key>CFBundleVersion</key><string>$${VERSION_STR}</string>|" Info.plist &&\
|
|
|
|
|
sed -i -e "s|<key>CFBundleShortVersionString</key>\s*<string>[^<]*</string>|<key>CFBundleShortVersionString</key><string>$${VERSION_STR}</string>|" Info.plist &&\
|
2024-03-14 23:44:36 +01:00
|
|
|
sed -i "s|ENV VERSION=.*|ENV VERSION=v$${TAG}|g" docker/Dockerfile && \
|
2024-01-17 12:56:18 +00:00
|
|
|
git add Info.plist && \
|
2024-01-03 16:23:11 +00:00
|
|
|
git commit -m "release: version $${TAG}" && \
|
|
|
|
|
echo "creating git tag : v$${TAG}" && \
|
2024-01-26 14:13:58 +01:00
|
|
|
git push && \
|
2024-01-26 14:49:22 +01:00
|
|
|
git tag v$${TAG} && \
|
2024-01-03 16:23:11 +00:00
|
|
|
git push -u origin HEAD --tags && \
|
|
|
|
|
echo "Github Actions will detect the new tag and release the new version."'
|
2024-02-02 13:47:41 +01:00
|
|
|
|
|
|
|
|
|