{"id":77,"date":"2016-03-29T23:27:04","date_gmt":"2016-03-29T22:27:04","guid":{"rendered":"http:\/\/188.166.119.205\/?p=77"},"modified":"2026-11-10T05:52:02","modified_gmt":"2026-11-10T05:52:02","slug":"the-way-i-like-to-compile-my-go-programs-makefile","status":"publish","type":"post","link":"https:\/\/banyek.net\/?p=77&lang=en","title":{"rendered":"The way I like to compile my Go programs \u2013 Makefile"},"content":{"rendered":"<p>I was on the quest of searching the Holy Grail of Go programming, and I found something, which I doubt that it is, but close enough \u2013 for the first sight.<\/p>\n<p>I have several problems with GO, first, that I write my code on an OSX box, and I\u2019ll run the programs on Linux hosts, so I have to solve the cross compilation; my second problem with Go, that I don\u2019t really like the \u201cThere is a GO project folder, and all the GO projects are relying on\u201d approach. It makes using GitHub painful.<\/p>\n<p><!--more--><\/p>\n<p>The first problem of mine is easily achievable since GO 1.5: we only need a GOOS environment variable and we can compile to different OS-es (see more at Dave Cheney: http:\/\/dave.cheney.net\/2015\/08\/22\/cross-compilation-with-go-1-5) easily.<\/p>\n<p>The second problem is easily solvable too, just we have to start using the GOPATH variable for every GO project we have.<\/p>\n<p>I don\u2019t really want to use any external dependencies, so I decided to use \u2018Makefile\u2019 \u2013 it was proven good for decades. (I don\u2019t know if this applies to bigger projects, but the ones I wrote it is fairly good.)<\/p>\n<p>Let\u2019s check out the makefile of the <a href=\"http:\/\/188.166.119.205\/2015\/11\/16\/streaming-mysql-binary-logs-for-backup\/\">binlogstreamer<\/a>!<\/p>\n<p><script src=\"https:\/\/gist.github.com\/banyek\/39b5d0bf376c588ff6e2.js\"><\/script><\/p>\n<p>If you type \u2018make\u2019 in the checked out project folder, it will download all the dependencies and build the application there. You can run that locally, test it, etc. If you change the code, then you can compile it again, etc.<\/p>\n<p>On my OSX host, I can build for our Linux boxes as well I just type \u2018make Linux\u2019 and I\u2019ll have the binary which I can run on our servers. I can put the binary to the puppet repository, and it to GitHub.<\/p>\n<p>After I made my changes in the code, and I\u2019d like to push to git, then I just run \u2018make clean\u2019 which removes all the binaries, and all dependencies, and leaves just the code there. I can commit and push it when I want.<\/p>\n<p>So far this approach worked for me. Do you have any better?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was on the quest of searching the Holy Grail of Go programming, and I found something, which I doubt that it is, but close enough \u2013 for the first sight. I have several problems with GO, first, that I write my code on an OSX box, and I\u2019ll run the programs on Linux hosts, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[134],"tags":[186,148,188,190,126,130],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-tech-en","tag-cli-en","tag-coding-en","tag-command-line-en","tag-go-en","tag-oldblog-en","tag-work-env-en"],"_links":{"self":[{"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/banyek.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":1,"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"predecessor-version":[{"id":419,"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions\/419"}],"wp:attachment":[{"href":"https:\/\/banyek.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/banyek.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/banyek.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}