mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
rewrite macos build
This commit is contained in:
parent
4420f3a8ae
commit
34bf9e5160
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
/_output
|
/_output
|
||||||
|
/out
|
||||||
/yarr
|
/yarr
|
||||||
*.db
|
*.db
|
||||||
*.db-shm
|
*.db-shm
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>yarr</string>
|
|
||||||
<key>CFBundleDisplayName</key>
|
|
||||||
<string>yarr</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>nkanaev.yarr</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>VERSION</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>APPL</string>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>yarr</string>
|
|
||||||
|
|
||||||
<key>CFBundleIconFile</key>
|
|
||||||
<string>icon</string>
|
|
||||||
<key>LSApplicationCategoryType</key>
|
|
||||||
<string>public.app-category.news</string>
|
|
||||||
|
|
||||||
<key>NSHighResolutionCapable</key>
|
|
||||||
<string>True</string>
|
|
||||||
|
|
||||||
<key>LSMinimumSystemVersion</key>
|
|
||||||
<string>10.13</string>
|
|
||||||
<key>LSUIElement</key>
|
|
||||||
<true/>
|
|
||||||
<key>NSHumanReadableCopyright</key>
|
|
||||||
<string>Copyright © 2020 nkanaev. All rights reserved.</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
`
|
|
||||||
|
|
||||||
func run(cmd ...string) {
|
|
||||||
fmt.Println(cmd)
|
|
||||||
err := exec.Command(cmd[0], cmd[1:]...).Run()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
var version, outdir string
|
|
||||||
flag.StringVar(&version, "version", "0.0", "")
|
|
||||||
flag.StringVar(&outdir, "outdir", "", "")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
outfile := "yarr"
|
|
||||||
|
|
||||||
binDir := path.Join(outdir, "yarr.app", "Contents/MacOS")
|
|
||||||
resDir := path.Join(outdir, "yarr.app", "Contents/Resources")
|
|
||||||
|
|
||||||
plistFile := path.Join(outdir, "yarr.app", "Contents/Info.plist")
|
|
||||||
pkginfoFile := path.Join(outdir, "yarr.app", "Contents/PkgInfo")
|
|
||||||
|
|
||||||
os.MkdirAll(binDir, 0700)
|
|
||||||
os.MkdirAll(resDir, 0700)
|
|
||||||
|
|
||||||
f, _ := ioutil.ReadFile(path.Join(outdir, outfile))
|
|
||||||
ioutil.WriteFile(path.Join(binDir, outfile), f, 0755)
|
|
||||||
|
|
||||||
ioutil.WriteFile(plistFile, []byte(strings.Replace(plist, "VERSION", version, 1)), 0644)
|
|
||||||
ioutil.WriteFile(pkginfoFile, []byte("APPL????"), 0644)
|
|
||||||
|
|
||||||
iconFile := path.Join(outdir, "icon.png")
|
|
||||||
iconsetDir := path.Join(outdir, "icon.iconset")
|
|
||||||
os.Mkdir(iconsetDir, 0700)
|
|
||||||
|
|
||||||
for _, res := range []int{1024, 512, 256, 128, 64, 32, 16} {
|
|
||||||
outfile := fmt.Sprintf("icon_%dx%d.png", res, res)
|
|
||||||
if res == 1024 || res == 64 {
|
|
||||||
outfile = fmt.Sprintf("icon_%dx%d@2x.png", res/2, res/2)
|
|
||||||
}
|
|
||||||
cmd := []string{
|
|
||||||
"sips", "-s", "format", "png", "--resampleWidth", strconv.Itoa(res),
|
|
||||||
iconFile, "--out", path.Join(iconsetDir, outfile),
|
|
||||||
}
|
|
||||||
run(cmd...)
|
|
||||||
}
|
|
||||||
|
|
||||||
icnsFile := path.Join(resDir, "icon.icns")
|
|
||||||
run("iconutil", "-c", "icns", iconsetDir, "-o", icnsFile)
|
|
||||||
}
|
|
BIN
etc/icon.icns
Normal file
BIN
etc/icon.icns
Normal file
Binary file not shown.
BIN
etc/icon_macos.png
Normal file
BIN
etc/icon_macos.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
62
etc/macos_package.sh
Executable file
62
etc/macos_package.sh
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
#/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "usage: $0 VERSION path/to/icon.icns path/to/binary output/dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION=$1
|
||||||
|
ICNFILE=$2
|
||||||
|
BINFILE=$3
|
||||||
|
OUTPATH=$4
|
||||||
|
|
||||||
|
mkdir -p $OUTPATH/yarr.app/Contents/MacOS
|
||||||
|
mkdir -p $OUTPATH/yarr.app/Contents/Resources
|
||||||
|
|
||||||
|
mv $BINFILE $OUTPATH/yarr.app/Contents/MacOS/yarr
|
||||||
|
cp $ICNFILE $OUTPATH/yarr.app/Contents/Resources/icon.icns
|
||||||
|
|
||||||
|
chmod u+x $OUTPATH/yarr.app/Contents/MacOS/yarr
|
||||||
|
|
||||||
|
echo -n 'APPL????' >$OUTPATH/yarr.app/Contents/PkgInfo
|
||||||
|
cat <<EOF >$OUTPATH/yarr.app/Contents/Info.plist
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>yarr</string>
|
||||||
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>yarr</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>nkanaev.yarr</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>$VERSION</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>yarr</string>
|
||||||
|
|
||||||
|
<key>CFBundleIconFile</key>
|
||||||
|
<string>icon</string>
|
||||||
|
<key>LSApplicationCategoryType</key>
|
||||||
|
<string>public.app-category.news</string>
|
||||||
|
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<string>True</string>
|
||||||
|
|
||||||
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
<string>10.13</string>
|
||||||
|
<key>LSUIElement</key>
|
||||||
|
<true/>
|
||||||
|
<key>NSHumanReadableCopyright</key>
|
||||||
|
<string>Copyright © 2020 nkanaev. All rights reserved.</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
EOF
|
35
makefile
35
makefile
@ -4,8 +4,10 @@ GITHASH=$(shell git rev-parse --short=8 HEAD)
|
|||||||
GO_TAGS = sqlite_foreign_keys sqlite_json
|
GO_TAGS = sqlite_foreign_keys sqlite_json
|
||||||
GO_LDFLAGS = -s -w -X 'main.Version=$(VERSION)' -X 'main.GitHash=$(GITHASH)'
|
GO_LDFLAGS = -s -w -X 'main.Version=$(VERSION)' -X 'main.GitHash=$(GITHASH)'
|
||||||
|
|
||||||
export GOARCH ?= amd64
|
GO_FLAGS = -tags "$(GO_TAGS)" -ldflags="$(GO_LDFLAGS)"
|
||||||
export CGO_ENABLED = 1
|
GO_FLAGS_GUI = -tags "$(GO_TAGS) gui" -ldflags="$(GO_LDFLAGS)"
|
||||||
|
|
||||||
|
export CGO_ENABLED=1
|
||||||
|
|
||||||
build_default:
|
build_default:
|
||||||
mkdir -p _output
|
mkdir -p _output
|
||||||
@ -27,8 +29,33 @@ build_windows:
|
|||||||
windres -i src/platform/versioninfo.rc -O coff -o src/platform/versioninfo.syso
|
windres -i src/platform/versioninfo.rc -O coff -o src/platform/versioninfo.syso
|
||||||
GOOS=windows go build -tags "$(GO_TAGS) windows" -ldflags="$(GO_LDFLAGS) -H windowsgui" -o _output/windows/yarr.exe ./cmd/yarr
|
GOOS=windows go build -tags "$(GO_TAGS) windows" -ldflags="$(GO_LDFLAGS) -H windowsgui" -o _output/windows/yarr.exe ./cmd/yarr
|
||||||
|
|
||||||
|
etc/icon.icns: etc/icon_macos.png
|
||||||
|
mkdir -p etc/icon.iconset
|
||||||
|
sips -s format png --resampleWidth 1024 etc/icon_macos.png --out etc/icon.iconset/icon_512x512@2x.png
|
||||||
|
sips -s format png --resampleWidth 512 etc/icon_macos.png --out etc/icon.iconset/icon_512x512.png
|
||||||
|
sips -s format png --resampleWidth 256 etc/icon_macos.png --out etc/icon.iconset/icon_256x256.png
|
||||||
|
sips -s format png --resampleWidth 128 etc/icon_macos.png --out etc/icon.iconset/icon_128x128.png
|
||||||
|
sips -s format png --resampleWidth 64 etc/icon_macos.png --out etc/icon.iconset/icon_32x32@2x.png
|
||||||
|
sips -s format png --resampleWidth 32 etc/icon_macos.png --out etc/icon.iconset/icon_32x32.png
|
||||||
|
sips -s format png --resampleWidth 16 etc/icon_macos.png --out etc/icon.iconset/icon_16x16.png
|
||||||
|
iconutil -c icns etc/icon.iconset -o etc/icon.icns
|
||||||
|
|
||||||
|
darwin_arm64_gui: etc/icon.icns
|
||||||
|
mkdir -p out/$@
|
||||||
|
CGOGOOS=darwin GOARCH=arm64 go build $(GO_FLAGS_GUI) -o out/$@/yarr ./cmd/yarr
|
||||||
|
./etc/macos_package.sh $(VERSION) etc/icon.icns out/$@/yarr out/$@
|
||||||
|
|
||||||
|
darwin_amd64_gui: etc/icon.icns
|
||||||
|
mkdir -p out/$@
|
||||||
|
GOOS=darwin GOARCH=amd64 go build $(GO_FLAGS_GUI) -o out/$@/yarr ./cmd/yarr
|
||||||
|
./etc/macos_package.sh $(VERSION) etc/icon.icns out/$@/yarr out/$@
|
||||||
|
|
||||||
serve:
|
serve:
|
||||||
go run -tags "$(GO_TAGS)" ./cmd/yarr -db local.db
|
go run $(GO_FLAGS) ./cmd/yarr -db local.db
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -tags "$(GO_TAGS)" ./...
|
go test $(GO_FLAGS) ./...
|
||||||
|
|
||||||
|
.PHONY: serve test \
|
||||||
|
mac_amd64_gui \
|
||||||
|
mac_arm64_gui
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//go:build !windows
|
//go:build !windows
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//go:build macos || windows
|
//go:build (darwin || windows) && gui
|
||||||
// +build macos windows
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//go:build !windows && !macos
|
//go:build !gui
|
||||||
// +build !windows,!macos
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//go:build macos
|
//go:build darwin && gui
|
||||||
// +build macos
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//go:build windows
|
//go:build windows && gui
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//go:build !windows && !darwin
|
//go:build linux
|
||||||
// +build !windows,!darwin
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//go:build darwin
|
//go:build darwin
|
||||||
// +build darwin
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
//go:build windows
|
//go:build windows
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user