Ramesh Babu
Ramesh Babu

Reputation: 21

how to define integer variable inside make file

I am able to define build=1 as command line argument. For example:

make build=1

But not able to definebuild=1 inside the make file. For example, I have added

build=1
ifdef build
echo 'defined'
endif 

But the ifdef part is not executing.

Upvotes: 2

Views: 1525

Answers (1)

Reinier Torenbeek
Reinier Torenbeek

Reputation: 17383

You were on the right track and had the assignment to the build variable correct. However, you can not just execute a command like echo on a random line in a makefile. See 3.1 What Makefiles Contain to understand what a makefile looks like.

The following demonstrates what you could do, for example using the $(info ...) function. In this case, echo is additionally executed inside a recipe, which is where it is used most of the time.

build:=1
ifdef build
$(info build has been defined)
endif

all:
        @echo build has the value $(build)

Note the usage of := as opposed to =. Although not too important in this example, it is useful to understand the difference. You can find an explanation in the section 6.2 The Two Flavors of Variables.

If you want to learn how to use make, keep that manual under your pillow. It is complete and readable and contains quite a few examples.

Upvotes: 1

Related Questions