| 16 | ) |
| 17 | |
| 18 | func build(baseDir string, releaseMode string, targetOS, targetArch string) { |
| 19 | |
| 20 | fmt.Println(`< Beginning build to "` + baseDir + `" for ` + targetOS + `. >`) |
| 21 | |
| 22 | forWin := strings.Contains(targetOS, "windows") |
| 23 | forMac := strings.Contains(targetOS, "darwin") |
| 24 | |
| 25 | copyTo := func(src, dest string) { |
| 26 | if err := copy.Copy(src, dest); err != nil { |
| 27 | panic(err) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // Note that this script is meant to be run from a terminal at the project root. |
| 32 | // It is specifically NOT meant to be built into an executable and run by double-clicking in |
| 33 | // Finder, on Mac OS. |
| 34 | |
| 35 | // We always remove any pre-existing platform directory before building to ensure it's fresh. |
| 36 | if err := os.RemoveAll(baseDir); err != nil { |
| 37 | panic(err) |
| 38 | } |
| 39 | |
| 40 | copyTo("changelog.md", filepath.Join(baseDir, "changelog.md")) |
| 41 | |
| 42 | if forMac { |
| 43 | baseDir = filepath.Join(baseDir, "MasterPlan.app", "Contents", "MacOS") |
| 44 | } |
| 45 | |
| 46 | // Copy the assets folder to the bin directory |
| 47 | |
| 48 | copyTo("assets", filepath.Join(baseDir, "assets")) |
| 49 | |
| 50 | fmt.Println("<Assets copied.>") |
| 51 | |
| 52 | outputFilepath := filepath.Join(baseDir, "MasterPlan") |
| 53 | |
| 54 | if forWin { |
| 55 | |
| 56 | outputFilepath += ".exe" |
| 57 | |
| 58 | // Copy the resources.syso so the executable has the generated icon and executable properties compiled in. |
| 59 | // This is done using go generate with goversioninfo downloaded and "// go:generate goversioninfo -64=true" in main.go. |
| 60 | copyTo(filepath.Join("other_sources", "resource.syso"), filepath.Join("..", "resource.syso")) |
| 61 | |
| 62 | // Copy in the SDL requirements (.dll files) |
| 63 | filepath.Walk(filepath.Join("other_sources"), func(path string, info fs.FileInfo, err error) error { |
| 64 | _, filename := filepath.Split(path) |
| 65 | if filepath.Ext(path) == ".dll" { |
| 66 | copyTo(path, filepath.Join(baseDir, filename)) |
| 67 | } |
| 68 | return nil |
| 69 | }) |
| 70 | |
| 71 | } |
| 72 | |
| 73 | // We should compile statically at some point, but it's broken currently, it seems? See: https://github.com/veandco/go-sdl2/issues/507 |
| 74 | // So for the meantime, we'll just build dynamically and bundle the dependencies on Windows and Mac. On Linux, usually users have the dependencies (SDL2, basically) installed already. |
| 75 | |