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 7624733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:02:35+00:00 2026-05-31T05:02:35+00:00

In my makefile, I need to make a variable assignment based on a command

  • 0

In my makefile, I need to make a variable assignment based on a command line variable value. for example, I do:

make var_1=xxx

where var_1 can have one of say 100 possible values. Based on the value of var_1, I need to assign a value to var_2 in my makefile. I could do:

ifeq ($(var_1), a)
   var_2 = A
endif
ifeq ($(var_1), b)
   var_2 = B
endif

and so on for all 100 possible combinations of var_1, var_2. Here a,A,b,B represent some strings. How do I do this to avoid 100’s of if statements? I was thinking to define two variables:

var_1_values = a b c d     
var_2_values = A B C D

I can use $(findstring $(var_1),$(var_1_values)) to see if $(var_1) is among $(var_1_values), but how do I locate the position of $(var_1) among all $(var_1_values)? That position is then to be used to pick the corresponding word inside $(var_2_values).

  • 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-31T05:02:37+00:00Added an answer on May 31, 2026 at 5:02 am

    It’s a little kludgey, but if there’s a symbol you know won’t be in any of the values (such as “_”) you could do this:

    var_1_values = a b c d
    var_2_values = A B C D
    
    # This will be a_A b_B c_C d_D
    LIST1 = $(join $(addsuffix _,$(var_1_values)),$(var_2_values))
    
    var_1 := a
    
    # The filter gives a_A, the subst turns it into A
    var_2 = $(subst $(var_1)_,,$(filter $(var_1)_%, $(LIST1)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Make and I have a makefile which sets a variable with a
I have a function in my .profile which I need in a makefile (one
we have some C++ code that we need to create a make file in.
I have a Makefile building many C files with long long command lines and
In a makefile, I have the following line: helper.cpp: dtds.h Which ensures that helper.cpp
I need to have a makefile work under Windows and Cygwin. I having problems
I need to invoke make (build a makefile) in a directory different from the
I have a simple Makefile: default: @make build @make run build: @javac Test.java >
I am trying to parallelize an old Makefile. In fact I need to make
I have one set of source files from which I need to generate multiple

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.