Good afternoon, is it possible to use environment variables in a makefile?

If possible, give an example.

    1 answer 1

    certainly possible .

    environment variables are converted to internal program variables, and their values ​​can be accessed in the form of $(имя) , as well as override these values ​​by standard means:

     имя=Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ 

    It is also worth adding that inside recipes :

     Ρ†Π΅Π»ΡŒ ...: ΠΏΡ€Π΅Ρ€Π΅ΠΊΠ²ΠΈΠ·ΠΈΡ‚ ... Ρ€Π΅Ρ†Π΅ΠΏΡ‚ ... 

    which are executed by the shell (as well as in the right part of the assignments имя=Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ , but not inside targets or prerequisites), environment variables, as well as variables of the shell itself, can be accessed in the same way as it proceeds inside shell programs . only the β€œdouble” $ character is required so that the make program can distinguish the reference to its internal variable from the reference to the shell variable:

     $(x) # ΠΎΠ±Ρ€Π°Ρ‰Π΅Π½ΠΈΠ΅ ΠΊ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΉ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ x ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ make $x # Π°Π»ΡŒΡ‚Π΅Ρ€Π½Π°Ρ‚ΠΈΠ²Π½Π°Ρ запись обращСния ΠΊ Ρ‚ΠΎΠΉ ΠΆΠ΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ, # допустимая Π² случаС, ΠΊΠΎΠ³Π΄Π° имя ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ состоит ΠΈΠ· ΠΎΠ΄Π½ΠΎΠ³ΠΎ символа $$x # ΠΎΠ±Ρ€Π°Ρ‰Π΅Π½ΠΈΠ΅ ΠΊ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΉ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΠΈ x $$xyz # ΠΎΠ±Ρ€Π°Ρ‰Π΅Π½ΠΈΠ΅ ΠΊ Π²Π½ΡƒΡ‚Ρ€Π΅Π½Π½Π΅ΠΉ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎΠΉ ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΠΈ xyz