I have a git project with several sub-modules (a choice I somewhat regret in retrospect). It uses gnu make
Currently I expect people to issue by hand a git submodule update --init
1 before building the project for the first time and also after pulling any change that updated a submodule reference.
However, I'd like for the Makefile to issue these commands automatically when they are needed. It's OK if they issue the commands sometimes when they aren't needed (spurious update) - but it shouldn't happen regularly.
For the initial init
it seems enough to have a rule like (for a submodule that lives in directory module1
:
module1/.git:
git submodule update --init
And here the choice of .git
as the file to "represent" the submodule is fairly arbitrary, it could be some other file instead.
However this doesn't work that well to update the submodule when the reference has been updated. I guess I could make the submodule depend on the root .gitmodules
file which I guess should change when a submodule reference gets updated, something like:
module1/.git: .gitmodules
git submodule update --init
Here the use of .git
seems wrong though: presumably that directly won't necessarily be updated when update
is run (especially if there was no update to this particular submodule), which will leave the update command running every time.
Looking for a cleaner solution here.
1 Or possibly use the --recursive
argument on the initial clone
, which has the same effect.
.git/modules/module1/HEAD
as a prerequisite to update "module1". Or to usegit submodule status
to create list of submodules to update (or you could also create a makefile that would update only changes submodules). – Hemp.git/modules/module1/HEAD
as the pre-req, what would be the target (presumably something inside the module)? – Springingmake
is the build system, and it is common in general for build systems to download external and perhaps build external artifacts, as necessary. In my case submodules are essentially external artifacts. So I don't see it as unusual thatmake
would update these modules as necessary. In the same way, I don't see it as weird thatmake
would generate source, as in many projects with source generation. I agree it is not desirable for make to "muck with your working copy", but in principle there is a line between the source for ... – Springingclone --recursive
. – Springingsubmodule
? – Springing