Alias target name in Makefile

Okay, I needed something similar. The path to my output artifacts were quite long, but I wanted short target names and also benefit easily from bash-completion.

Here is what I’m came up with:

os := [arbitrary long path to an artifact]
platform := [arbitrary long path to a differ artifact]
packer := [common parts of my packer build command]

.PHONY: all
all: $(platform)

.PHONY: platform
platform: $(platform)

$(platform): platform.json  $(os)
    @$(packer) $<

.PHONY: os
os: $(os)

$(os): os.json
    @$(packer) $<

.PHONY: clean
clean:
    rm -fr build/

With the Makefile above you can say:

$ make os
$ make platform

Which will be aliases for the long artifact names. I’ve made the snippet above quite long, because it’s important to see the relationships between the .PHONY aliases and the real targets. I hope that works for you.

Note: I did not delete the clean target from the above example, because many people does not make that a .PHONY target. However, semantically it should be.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)