user3226932
user3226932

Reputation: 2222

makefile: ignore dependency when running target

I have this setup in my Makefile.

action1:
  does something

action2: action1
  does something else

I want to keep my configuration in case I want to use action1 as a dependency for action2, but sometimes I'd like to ignore action1 when running make action2 (e.g. I'd like to run make action2 without having to include action1). Can I setup some kind of flag to pass in to ignore the dependency when running target and how can I go about doing that?

Upvotes: 9

Views: 6879

Answers (2)

Jeffrey Benjamin Brown
Jeffrey Benjamin Brown

Reputation: 3709

make -o <name of dependency> lets you ignore a dependency and all its implications. From the man page:

-o file, --old-file=file, --assume-old=file
     Do not  remake the file file  even if it is  older than
     its dependencies, and do not remake anything on account
     of changes in file.  Essentially the file is treated as
    very old and its rules are ignored.

Upvotes: 21

MadScientist
MadScientist

Reputation: 100781

You can do it like this:

ACTION1 = action1

action1:
        does something

action2: $(ACTION1)
        does something else

Now if you run make then both will be built. If you run make ACTION1= then that variable will be empty and action2 will not depend on action1. Of course you can call that variable whatever you want.

Upvotes: 3

Related Questions