Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile with two targets with the same name

Tags:

makefile

I have a makefile containing an include statement. I have no control over the content of the included makefile. Still, I want to be able to add some pre-processing steps before "some" (not all) of the targets. Consider the following example:

install:
      @echo "install target"

include othermakefile.mk

othermakefile.mk contains install target as well. If I run this script, make gives a warning and ignores the first install target.

like image 455
Javad Avatar asked Dec 28 '25 21:12

Javad


1 Answers

Nothing easier:

install: pre_install

.PHONY: pre_install
pre_install:
    do preinstallation things

include othermakefile.mk

EDIT:
If you want to run pre_install before install or any of its preqs, here is a way. It's crude and ugly, but it does the job:

install: pre_install
    $(MAKE) -f othermakefile.mk $@

.PHONY: pre_install
pre_install:
    do preinstallation things

Note that this will not necessarily rebuild all prerequisites of install, so some of them may remain in their old states and not reflect the effects of pre_install. If that's not good enough, and you want pre_install before all of the other prerequisites, you can add an option flag:

install: pre_install
    $(MAKE) --always-make -f othermakefile.mk $@

Now Make will assume that all targets are out of date, and rebuild from the ground up (after pre_install).

like image 71
Beta Avatar answered Dec 31 '25 00:12

Beta