diff --git a/cross-compile-xgo.rb b/cross-compile-xgo.rb new file mode 100755 index 0000000..0da6b00 --- /dev/null +++ b/cross-compile-xgo.rb @@ -0,0 +1,41 @@ +#!/usr/bin/env ruby + +targets = "darwin/amd64, + dragonfly/amd64, + freebsd/*, + linux/*, + netbsd/*, + openbsd/*, + windows/*" + +targets.gsub!(" ","").gsub!("\n","") + +version = `git describe --abbrev=0 --tags`.chomp +diff = `git diff`.chomp + +#unless diff.empty? +# puts "Forgot to git reset --hard?" +# exit if gets.chomp != "n" +#end + +vars = "GO386=387" +ldflags = "-w -X main.Version=#{version}" +build = "#{vars} xgo -v --targets=#{targets} -ldflags '#{ldflags}' ." +puts "Running #{build}" +#`#{build}` + +Dir.glob("syncthing-inotify-*").each do |file| + next unless File.file?(file) + next if file.include?(".tar.gz") + name = "syncthing-inotify" + if file.include?("windows") + name = "syncthing-inotify.exe" + end + move = "cp #{file} #{name}" + package = "tar -czf #{file}-#{version}.tar.gz #{name}" + rm = "rm -f syncthing-inotify" + #rm = "rm -f syncthing-inotify #{name}" + puts "Packaging #{file}" + `#{move} && #{package} + & #{rm}` +end diff --git a/cross-compile.rb b/cross-compile.rb index f31758a..3334903 100755 --- a/cross-compile.rb +++ b/cross-compile.rb @@ -15,7 +15,7 @@ diff = `git diff`.chomp unless diff.empty? - puts "Forgot to git reset --hard?" + puts "Forgot to git reset --hard? (Y/n)" exit if gets.chomp != "n" end @@ -39,9 +39,14 @@ vars += " GOARM=5" end ldflags = "-w -X main.Version=#{version}" - build = "#{vars} go build -ldflags '#{ldflags}'" + if os.include?("darwin") + build = "xgo --targets=darwin/amd64 -ldflags '#{ldflags}' ." + build += " && mv syncthing-inotify-darwin-10.6-amd64 #{name}" + else + build = "#{vars} go build -ldflags '#{ldflags}'" + end package = "tar -czf syncthing-inotify-#{os}-#{arch}-#{version}.tar.gz #{name}" - remove = "rm #{name}" + remove = "rm -f #{name}" output = `#{build} 2>&1 && #{package} && #{remove}` puts output unless output.empty? if output.include?("must be bootstrapped") || output.include?("no such tool")