Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6543037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:17:53+00:00 2026-05-25T11:17:53+00:00

In a GNU makefile, I would like to set an output variable to one

  • 0

In a GNU makefile, I would like to set an output variable to one value (let’s say “true”) if an input variable is equal to one of two values and to another value (“false”) when it is not.

Thanks to this SO answer I’ve learned about the and and the or functions and soon after that I have found the if function. These functions seem to be available in my version of make, so I would like to use them. I would like to write something like that:

TEST_INPUT = `hostname`
TEST_OUTPUT = $(if $(or $(eq $(TEST_INPUT),hal9000),
                        $(eq $(TEST_INPUT),pipboy)),true,false)

Unfortunately I can’t, because I couldn’t find any obvious form of the expected eq function. I am able to achieve what I want using the filter function:

TRUE_HOSTS = hal9000 pipboy
TEST_OUTPUT = $(if $(filter $(TEST_INPUT),$(TRUE_HOSTS)),true,false)

or the subst function:

TEST_OUTPUT = $(if $(and $(subst hal9000,,$(TEST_INPUT)),
                         $(subst pipboy,,$(TEST_INPUT))),
                   false,true)

but for me it isn’t a nice looking nor readable code. Are there solutions closer to the first example (the one using not existing eq function)? Maybe I don’t catch the purpose of the if, and and or functions at all?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:17:54+00:00Added an answer on May 25, 2026 at 11:17 am

    The thing that is odd about GNUmake conditionals is that there is no boolean type in make — everything is a string. So the conditionals all work with the empty string for ‘false’ and all non-empty strings (including strings like false and 0) as being ‘true’.

    That being said, the fact that eq is missing is an annoyonace albeit a minor one. Generally you can get what you want from filter or findstring, and filter often allows you to search a whole list of strings to match as in your second example.

    If you really need it, you can define your own eq function:

    eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
    

    Which you unfortunately have to use as $(call eq,…,…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to build a rule like this one in my Makefile: log:
I'm using (GNU) Make in my project. I'm currently putting one makefile per directory
I use CMake with GNU Make and would like to see all commands exactly
Can ruby lookup path to a binary like in bash or gnu makefile? Makefile
I would like to have the same Makefile for building on Linux and on
Possible Duplicate: What is the difference between the GNU Makefile variable assignments =, ?=,
What does $+ in a GNU makefile mean? Also, please give me some good
I'm using GNU Make 3.81, and I have the following rule in my Makefile:
GNU sed version 4.1.5 seems to fail with International chars. Here is my input
What GNU/Linux command-line tool would I use for performing a search and replace on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.