tannerman
tannerman

Reputation: 578

makefile: second dependency not execute

Second dependency in goal first-deploy not executed.

if I execute make first-deploy, make execute only first dependence - build-proxy-base with success result and exit.

Makefile:


UID=`id -u`
GID=`id -g`

NODE_N=node
PROXY_N=proxy
PY_N=py

DOCKER_D=docker
PROXY_D=skif-proxy
NODE_D=skif
PY_D=skif-proxy/template-service

# first is default
default: first-deploy docker-compose-up

docker-compose-up:
    cd $(DOCKER_D) && \
        docker-compose up --build && \
        cd ..

build-docker-base:
    docker build \
        --build-arg UID=${UID} \
        --build-arg GID=${GID} \
        -f ${D}/Dockerfile.base \
        --rm \
        -t skif-${SERV_N}-base ${D}

build-node-base: D := ${NODE_D}
build-node-base: SERV_N := ${NODE_N}
build-node-base: build-docker-base

build-proxy-base:D=${PROXY_D}
build-proxy-base:SERV_N=${PROXY_N}
build-proxy-base: build-docker-base

build-py-base: D=${PY_D}
build-py-base: SERV_N=${PY_N}
build-py-base: build-docker-base

first-deploy: build-proxy-base build-py-base build-node-base

UPD I understand that build-docker-base build only once, but how I can reuse it code in 2 goals with other paramethers?

Upvotes: 0

Views: 130

Answers (2)

MadScientist
MadScientist

Reputation: 100781

Make definitely considered the second dependency. If it didn't "execute" then it means make decided nothing needed to be done to execute it.

I can see this:

build-proxy-base: build-docker-base
  ...
build-node-base: build-docker-base

Both of these targets list the same target as a prerequisite, and they don't do anything else. In make, a given target (like build-docker-base) will only ever be built one time by make per invocation. Once make builds it once, it will be considered up to date no matter how many other targets may depend on it.

So make considers build-node-base, sees that it was already brought up to date due to build-proxy-base, and decides there's nothing else to do.

Since you don't actually show us to build-node-base rule or explain what you're trying to do, there's not much more we can say for sure.

ETA Based on your updated makefile, it seems like you're trying to think of targets as if they were functions, that can be called by listing them as prerequisites. They are not, and they cannot.

It looks to me like you just want to run the same recipe multiple times with different parameters. I think you should just write it like this:

build-node-base build-proxy-base build-py-base:
        docker build \
            --build-arg UID=${UID} \
            --build-arg GID=${GID} \
            -f ${D}/Dockerfile.base \
            --rm \
            -t skif-${SERV_N}-base ${D}

build-node-base: D := ${NODE_D}
build-node-base: SERV_N := ${NODE_N}

build-proxy-base:D=${PROXY_D}
build-proxy-base:SERV_N=${PROXY_N}

build-py-base: D=${PY_D}
build-py-base: SERV_N=${PY_N}

Upvotes: 3

John Bollinger
John Bollinger

Reputation: 180048

Since there is no recipe for either build-proxy-base or build-node-base, and both are effectively phony, it's unclear how you are concluding that build-node-base is not, in fact, built.

I suspect that the actual observation is that target build-docker-base is built only once per make run, and that that build reflects the values of variables D and SERV_N set while building build-proxy-base. That has little to do with whether target build-node-base is built, and a lot to do with the fact that make builds each target at most once per run.

Upvotes: 1

Related Questions