Exporting environment variables to Makefile shell

后端 未结 5 1464
梦毁少年i
梦毁少年i 2021-01-04 18:01

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 us

5条回答
  •  难免孤独
    2021-01-04 18:40

    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

提交回复
热议问题