-
Notifications
You must be signed in to change notification settings - Fork 122
/
rsrc.go
51 lines (43 loc) · 1.58 KB
/
rsrc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"flag"
"fmt"
"os"
"github.com/akavel/rsrc/rsrc"
)
var usage = `USAGE:
%s [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] [OPTIONS...]
Generates a .syso file with specified resources embedded in .rsrc section,
aimed for consumption by Go linker when building Win32 excecutables.
The generated *.syso files should get automatically recognized by 'go build'
command and linked into an executable/library, as long as there are any *.go
files in the same directory.
OPTIONS:
`
func main() {
//TODO: allow in options advanced specification of multiple resources, as a tree (json?)
//FIXME: verify that data file size doesn't exceed uint32 max value
var fnamein, fnameico, fnameout, arch string
flags := flag.NewFlagSet("", flag.ExitOnError)
flags.StringVar(&fnamein, "manifest", "", "path to a Windows manifest file to embed")
flags.StringVar(&fnameico, "ico", "", "comma-separated list of paths to .ico files to embed")
flags.StringVar(&fnameout, "o", "", "name of output COFF (.res or .syso) file; if set to empty, will default to 'rsrc_windows_{arch}.syso'")
flags.StringVar(&arch, "arch", "amd64", "architecture of output file - one of: 386, amd64, [EXPERIMENTAL: arm, arm64]")
flags.Usage = func() {
fmt.Fprintf(os.Stderr, usage, os.Args[0])
flags.PrintDefaults()
}
_ = flags.Parse(os.Args[1:])
if fnamein == "" && fnameico == "" {
flags.Usage()
os.Exit(1)
}
if fnameout == "" {
fnameout = "rsrc_windows_" + arch + ".syso"
}
err := rsrc.Embed(fnameout, arch, fnamein, fnameico)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}