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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:23:18+00:00 2026-05-31T12:23:18+00:00

I want to do immediate expansion of a shell command within a Makefile, but

  • 0

I want to do immediate expansion of a shell command within a Makefile, but I want the shell command to have access to the environment variables within the Makefile. If I use the $(shell …), it expands immediately, but there is no access to the variables. If I use the backquotes, the expansion is not immediate, and it causes problems for me later in the Makefile. I’m wondering if there is any way to make the backquotes expand immediately, or to pass the current environment to a $(shell) command.

For example, the following makefile:

SOME_VAR := some_val
export SOME_VAR

VAR1 := `echo $$SOME_VAR`
export VAR1
VAR2 := `echo $$VAR1`

all:
      @echo VAR1=$(VAR1)
      @echo VAR2=$(VAR2)

Will output:

~/tmp/t2> make
VAR1=some_val
VAR2=`echo $SOME_VAR`

Where I want it to print “VAR2=some_val”. The real example is a bit more complicated (environment variables are inherited from parent makefiles, and I’m trying to use a perl script to edit the variables), but the principle is the same.

Any help is appreciated.

  • 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-31T12:23:20+00:00Added an answer on May 31, 2026 at 12:23 pm

    As I mentioned in some of the comments, my actual goal was to make the script generate filenames based on the settings the object was being compiled with. I then need another script to generate a specially formatted list of all the filenames generated (the target is an embedded system which doesn’t have a JIT compiler on it). At any given time, there are over thirty settings which can potentially effect the binary, and this may be used on more than one module in the future, so I’d like something scalable.

    My solution is as follows. Instead of passing the variables in, I modified my script to output a makefile-parsable string based on the settings:

    -include $(SOME_MK_FILE)
    
    $(SOME_MK_FILE) : .phony
        script.pl $(SETTINGS_OF_INTEREST_LIST) > $(SOME_MK_FILE)
    
    someFilename := $(shell script2.pl $(VAR1))
    

    script.pl outputs a string that looks something like:

    VAR1 := CONFIG_X1=$(CONFIG_X1) CONFIG_X2=$(CONFIG_X2) CONFIG_X33=$(CONFIG_X33)
    

    and script2 outputs a filename that looks something like ‘someFilename.X1_y.X2_n.elf’

    and then, later on, in another rule, I have:

    someobj: somedep
        script3.pl $(someFilename) >> builtfiles.txt
    

    which properly builds builtfiles.txt (which in turn is the input for yet another script…). In the end this is a workaround to the fact that make cannot pass its environement to $(shell). It’s not overly pretty but it works.

    John

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

Sidebar

Related Questions

I want to drop a database. I have used the following code, but to
What if I want to do something with my formset other than immediately saving
After creating a child process and exiting it immediately (_exit()), I want to perform
want to have a Hyperlink-Button in a gridView in which I can display a
Want the function to sort the table by HP but if duplicate HPs then
For an XDocument descendants operation how can only return immediate child nodes? I have
i want to make sure all table's immediate child is tbody.... how can i
I want to select list items that are immediate children of #nav, that do
I want to do something like this: $(#container).otherBind(foo-content-loaded, function() {alert(immediate or later!);}); foo-content-loaded is
I want to create temporary table in stored procedure and access it in the

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.