diff --git a/README.txt b/README.txt index 49a3eda..bd797be 100644 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ INSTALL: go get github.com/akavel/rsrc USAGE: -rsrc.exe [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso +rsrc.exe [-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. @@ -20,7 +20,7 @@ OPTIONS: -manifest string path to a Windows manifest file to embed -o string - name of output COFF (.res or .syso) file (default "rsrc.syso") + name of output COFF (.res or .syso) file; if set to empty, will default to 'rsrc_windows_{arch}.syso' Based on ideas presented by Minux. diff --git a/rsrc.go b/rsrc.go index 73681c0..5c3d44f 100644 --- a/rsrc.go +++ b/rsrc.go @@ -10,7 +10,7 @@ import ( var usage = `USAGE: -%s [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso +%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. @@ -28,17 +28,20 @@ func main() { 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", "rsrc.syso", "name of output COFF (.res or .syso) file") + 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", "386", "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 fnameout == "" || (fnamein == "" && fnameico == "") { + 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 { diff --git a/rsrc_test.go b/rsrc_test.go index d59997f..498e280 100644 --- a/rsrc_test.go +++ b/rsrc_test.go @@ -8,7 +8,7 @@ import ( "testing" ) -const name = "rsrc.syso" +const name = "rsrc_windows_amd64.syso" func TestBuildSucceeds(t *testing.T) { tests := []struct { @@ -35,7 +35,7 @@ func TestBuildSucceeds(t *testing.T) { // Compile icon/manifest in testdata/ dir os.Stdout.Write([]byte("-- compiling resource(s)...\n")) defer os.Remove(filepath.Join(dir, name)) - cmd := exec.Command("go", "run", "../rsrc.go", "-arch", "amd64", "-o", name) + cmd := exec.Command("go", "run", "../rsrc.go", "-arch", "amd64") cmd.Args = append(cmd.Args, tt.args...) cmd.Dir = dir cmd.Stdout = os.Stdout @@ -45,6 +45,12 @@ func TestBuildSucceeds(t *testing.T) { t.Fatal(err) } + // Verify if a .syso file with default name was created + _, err = os.Stat(filepath.Join(dir, name)) + if err != nil { + t.Fatal(err) + } + defer os.Setenv("GOOS", os.Getenv("GOOS")) defer os.Setenv("GOARCH", os.Getenv("GOARCH")) os.Setenv("GOOS", "windows")