Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile for pulling and building projects

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?

like image 253
fakedrake Avatar asked Aug 08 '13 00:08

fakedrake


2 Answers

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
like image 168
Etan Reisner Avatar answered Nov 05 '22 03:11

Etan Reisner


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
like image 21
Jesusaur Avatar answered Nov 05 '22 02:11

Jesusaur