I am building a project that requires an ecosystem of projects (linux, qemu, uboot etc) most of which are in git repositories. I used to manage them all with a script but I find myself implementing stuff that is better done with make. So I decided to migrate my script to a makefile.
The problem is I want to projects to be cloned if not present and pulled if present. Is there a way to do that without repeaing myself too much?
Something like this would work I think. It doesn't have make do the work because without depending on something inside the project directories I'm not sure you could only conditionally run the clone.
force: ;
proj%: force
@echo [ -d $@ ] || git clone srv:$@
@cd $@ && git pull
If you wanted to list something like proj1/.git/config
as your entry-point prereq you could split the clone up as an order-only prereq on those with a clone for the project directory. Though you would still need the force on the config prereq to force the pull to happen.
Something like this perhaps:
proj%:
git clone srv:$@
proj%/.git/config: force | proj%
git pull
I've been working on a Makefile for building docker images with PHONY targets and came up with this pattern:
.PHONY all
all: foo-docker
foo:
git clone https://example.org/foo-project.git $@
.PHONY: foo-update
foo-update: foo
@cd foo && git pull
.PHONY: foo-docker
foo-docker: foo-update
@cd foo && docker build
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With