I've got a server, comprised of a Go package (foo.go) that implements
the logic, plus a separate 'package main' server.go that imports foo
and runs as a daemon. I suspect this is a fairly common structure.
Right now it is pretty awkward to run and use. I can do a standard
'make' to build foo, but have to manually 8g/8l the server.go.
Is there a way to structure the Makefile to handle everything
automatically? That is, generate both the library and the executable?
I guess this is all predicated on the assumption that goinstall only
really handles libraries. Is that assumption correct, or can I finagle
goinstall to work with this somehow?
Or is there some totally different and superior way to package,
distribute and build this sort of thing?
So you would include from the $GOROOT/src/Make.pkg Makefile for those
packages, with TARG=foo/bar, etc.
To build and install your main package, set up a Makefile that
includes from $GOROOT/src/Make.cmd (see $GOROOT/src/cmd/godoc/Makefile
for an example).
Then to build your whole project, you could write a simple bash script
to call make for each of the packages, followed by the main package.
The Go Makefiles were written for the core Go code-base, not really
with 3rd-party stuff in mind. You can use them (as I've just
described), but you may also choose write your own.
It would be nice to have a tool to manage this more simply, though.
Andrew
Aha! This was the example I was looking for. Thanks; if I come up with
something elegant that combines this + Make.pkg, I'll post it to the
list for review.
There is an implicit implication here that Go mandates the use of Make
as the build tool. Is this the case or is use of SCons or Waf going to
be feasible?
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@russel.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
All implications are implicit. ;-)
When I said "or you could write your own," what I actually _meant_ was
that you can build them however you like. As long as GOARCH, GOOS, and
GOROOT are set, that should be enough for any build tool to know how
to invoke the go compiler and linker.
I personally use a little shell script to build most small programs as
I don't grok make as well as I should.
Andrew
(cd reqhandler && make clean && make install)
>
>
> On Jun 2, 10:25 am, Gustavo Hexsel <ghex...@gmail.com> wrote:
>> The reason why it may be ugly is because there's no support for versioning
>> and the recommended namespaces are fairly small (packages named "math" and
>> "server" and things like that).
>>
>
> Can't I use something like "myorganization/mypackage"?
That's the intent. Google-internal libraries, for instance, are all imported from a path beginning "google".
-rob
On Wed, 2010-06-02 at 10:12 -0700, David Leimbach wrote:
>
> On Jun 2, 9:44 am, David Nesting <da...@fastolfe.net> wrote:
> > On Wed, Jun 2, 2010 at 09:28, David Leimbach <leim...@gmail.com> wrote:
> > > (cd reqhandler && make clean && make install)
> >
> > This will install your packages beneath $GOROOT, right?
>
> Yes, read on to see why I think that's actually a good thing. Someone
> feel free to smack me if they can find an obvious (hopefully a non-
> obvious) hole in my thinking.
[ . . . ]
I guess the problem will come when things start to be packaged for
operating system distributions. There is then a conflict between
distribution and local variation. Python and Emacs handle this by
defining a special directory and requiring all installation to be done
by root. This is a sys admin nightmare.
The current structure works fine if the one and only method of
distributing Go is via Mercurial, but then many organization won't
accept its presence as they only allow things that can be handled by
operating system packages.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
The trouble is that it makes things very complicated if you want to
have two different versions of your code, e.g. in two different
directories. I very often want to go back and test my code using
older versions, and that's pretty hard if the build process involves
installing packages into the global location. One answer is to not
use packages (just put everything in package main, or a single
package), and maybe we don't often need packages, since the go
compiler is so fast, but that really just sidesteps the question.
Personally, I'm not satisfied with a build process that won't let me
isolate the code that I'm working on in this way. But fortunately,
it's quite easy to achieve by avoiding creating my own packages.
David
> The trouble is that it makes things very complicated if you want to
> have two different versions of your code, e.g. in two different
> directories. I very often want to go back and test my code using
> older versions, and that's pretty hard if the build process involves
> installing packages into the global location.
I practically always have multiple go installations:
o my current "everything" version ($HOME/go, $HOME/gobin)
o the current top of tree, unchanged (in case I suspect a Go bug)
o the current release (ditto)
o one for each CL I'm working on, originally so that it could
be stable and independent of other work during the review
process; now I think I could manage all my CLs in one tree
with Mercurial Queues, but it's simpler and allows faster
context switching to keep them separate
o one for each independent project that won't become a CL
All I have to remember to do is run . ./set_env when I change
directory to work on a different project, which sets $GOROOT
and $GOBIN. This is no harder than setting e.g. a library
search path.
If I'm not going to work on something for a while, clean.bash
will reduce the footprint. If I give up on something I can
just save the diffs ... which still gives me the chance to
go back but saves the space of the whole tree.
One of the reasons distributed source code management has
taken off is because disk space is now cheap. My _notebook_
has 500GB. (Come to that, it's likely all my go trees would
fit on a USB stick.)
The days where only people who'd bought *lots* of disk space
could compile, say, X11 and whole software teams worked on a
single system with say 1.2GB (GB, not TB) are _over_.
Giles
> I see no advantage in using anything but Make with Go when
> the include files make the work you have to do so incredibly
> minimal to play nice with the Go system.
Once you start using cgo, it becomes very difficult not to go
with the standard Makefiles, I found.
(If someone has figured an easy way, that might be
interesting: right now you need the Go source tree installed
to get those Makefiles, not just $GOBIN and packages under
$GOROOT.)
But perhaps it doesn't matter: the Makefiles are BSD licensed
and the source tree isn't that big v. current disk sizes, and
once a binary is built it's staticly linked. It's mostly that
it feels odd to be writing code under a different license yet
which has Makefiles with "include $(GOROOT)/src/Make.pkg" in
them.
Giles
> First off, my comments below are just to contrast my
> development style with that of Giles. Neither or both of us
> might be right, only you can decide what's best for you.
Thanks Kyle. Always good to see alternatives. Indeed I
cheat a little and some projects share a build, where I'm not
hitting language or package instabilities (which I'm not as
much lately as I was a couple of months back).
> In fact, as in the makefile example I posted earlier (
> http://pastie.org/989808 ), the only thing I ever use the
> $GOROOT/ src/ makefiles for is getting the
> architecture-dependent stuff (6g/ 8g, .6/.8, etc), I don't
> use its targets for most anything. Even those could
> reasonably be derived from the settings for $(GOARCH)
> without needing to consult the files, it just makes life
> easier.
You don't use cgo? cgo is pretty hard wired to use the src/
Makefile bits, or else such a close copy of them that it'd be
cut&paste and a derivative work I suspect.
Also, testing? Is that picked up too?
> Sadly, I have never met the harddrive I can't fill.
I think it was Ken Thompson who said that the steady state
of disks is full.
These days I usually manage some headroom, but hit the limit
and upgraded my MacBook Pro last week from 200GB to 500GB. I
suspect I'd have had a less miserable time upgrading if the
machine hadn't taken a knock early on in its life which has
left one corner visibly bent. :-/
Giles
> As far as cgo goes:
> http://pastebin.com/FQhErr5T
Hey, thanks! Dare I presume we're free to pick this up and
use it?
> I haven't fooled around with testing yet, but I labor under
> the belief that when I need it it will be WAY easier to
> simplify into my own Makefile than the CGO stuff.
It should be. And I'd encourage you to get into testing;
the Go test support is reasonably basic, but it works very
well.
I know it has helped me a lot when working on a large
library: I can start some parts top down and test them,
and other parts bottom up and test them, while I'm still
working on how they'll end up glued together.
(And when I say it's helped me a lot, I mean that it's not
just confirmed for me that something works, but (ahem) found
a bug or two.)
> Maybe when I get this working with test, I should post the
> makefile somewhere, as it should ideally work with *any*
> local project layout. I also still need to update my
> godepgen and GoClipse to generate the above makefile. All
> things in time, I suppose.
If you're willing, and are relaxed enough in your licensing,
I'd be appreciative. I've nothing against the makefiles
included in the Go tree, but given most Linux distributions'
tendancies to separate out "-devel" bits _and_ with the gcc Go
frontend coming along, it would be nice to have a self
contained source tree for a package that doesn't need Go
compiler source present and unpacked to build the package.
Perhaps I'm being overly fussy and sticking with "old think",
but Go presently breaks a number of conventions about what the
OS provides, what the compiler provides, and what third party
libraries provide. (This shouldn't be construed as support
for those divisions, but they exist, and Go is "different".)
In the Go team's place I'd have made the same or similar
shortcuts I am sure; philosophically I regard a system without
a working compiler as "broken"; and having the compiler source
is a benefit, but I doubt the whole world will agree. While
I'm reasonable and rational, there's always _someone_ in the
world who most unreasonably and illogically disagrees. :-) :-)
Giles
Pay no attention to the man behind the curtain... and by that, I mean the 11-deep nesting about halfway in. Lol. Check the doc comments at the top for brief explanations about how it works. Take special note that if you're using it for cgo, you need to make some changes to the Make.* files for your GOOS and GOARCH, as I didn't want to pollute the makefile with error-prone and ugly grepping of Make.pkg.
As far as I know, and I haven't tested this with any major cgo stuff, this should be able to generate a makefile for pretty much any well-structured go source directory with at most one destination binary.
~Kyle