How can I introduce git SHA1 in gnu make?

I have compiled tarball'd software releases that include output from several different projects. These archives themselves are considered a release. Released tarball includes a specification (material specification), which lists all the projects in it and the associated SHA1 (git) signatures.

To make it easy to re-create these tarballs, I put together a make system that parses the BOM one by one, cloning the repository into a subdirectory, checking the specified version, and then building. Say the line in my specification:

prog-a b5286f27d65ef20eb4508f76de5a1c57d8b21d85 git+ssh:// git-user@localhost /~/prog-a 

the repository, if it has not already been cloned, will be placed in repos/prog-a , then check ( cd repos/prog-a; git checkout b5286f27d6 ) and finally make ( make -C repos/prog-a ) will be performed.

I did not understand how to let gnu decide if the verified version of the code already has the binary that I built. Currently, each individual subproject is forced to check and restore.

How can I introduce git repo SHA1 in GNU make so that it can decide if the project is outdated and needs to be updated (by doing a git checkout )?

[EDIT] This is my template file:

 REPO_DIR=materials BOM=$(shell sed -r 's/([^ ]+).+/\1/' bom) BOM_DIR=$(shell sed -r 's_([^ ]+).+_$(REPO_DIR)/\1_' bom) BOM_BLD=$(shell sed -r 's_([^ ]+).+_$(REPO_DIR)/\1/\1_' bom) .PHONY: clean dist-clean all: $(BOM) clean: @rm $(BOM) $(BOM_BLD) -rf dist-clean: clean @rm $(REPO_DIR) .SECONDEXPANSION: $(BOM): % : $(REPO_DIR)/$$*/$$* @echo " CP $< $@ " @cp $< $@ $(BOM_BLD): % : $$(*D) @echo " GIT CHECKOUT" @cd $<; git checkout -q $(shell sed -rn '/$(shell echo $@ | sed -r 's_.+/__')/ s/.+ (.+) .+ .+ .+/\1/p' bom) @echo " MAKE $@ " @make -w -C $< $(@F) $(BOM_DIR): | materials @echo " GIT CLONE $@ " @cd $(REPO_DIR); git clone $(shell sed -rn '/$(shell echo $@ | sed -r 's_.+/__')/ s/.+ (.+) .+ .+/\1/p' bom) materials: @echo " MKDIR $@ " @mkdir $@ 
+6
source share
2 answers

I finished the unconditional check and just took a hit on time if in fact he had to manipulate things in the working directory of the bom element.

0
source

This will be my model:

 TARGETS=prog-a prog-b prog-c all: $(TARGETS) prog-a: SHA1=123fa prog-b: SHA1=234ab prog-c: SHA1=345bc $(TARGETS): make -C " $@ " -e PARAM=$(SHA1) 

In your subdir makefile, imagine something like this:

 all: git checkout $(PARAM) -- ./ # ... other build rules 

assuming make files in subdirectories; you can, of course, do whatever you want in the make rule.

For even more dynamic scripts, at least see .SECONDEXPANSION , .PHONY , .PRECIOUS

+1
source

Source: https://habr.com/ru/post/896369/


All Articles