How can I determine in the Makefile under which OS the program is compiled? It is advisable to know, at least, within IOS / Android / Windows / Linux. I would like to have a common file in which libraries will be connected depending on the OS.

  • one
    It is worth creating a separate topic for each question. Why it may be necessary to determine the presence of defines? In the world of gnu / linux, they implemented the idea of ​​detecting the presence of certain features in the environment by means of automated tests before assembly (in autotools), but it brought nothing but slowing down the assembly and juggling crutches. - VTT
  • one
    in short, it is possible, but not practical ... usually other configuration systems are used for configuration, most of which are actually add-ons over make , such as autotools / cmake / qmake , etc. - Fat-Zer

1 answer 1

The question is turned upside down. you specify it, under what platform it is necessary to compile the program. and indicate this first to the compiler , not to the make interpreter.

Of course, if you do this through environment variables, you can add some processing to the program intended for the make interpreter.

the make interpreter understands various kinds of conditional constructs:

for example, write this program in the makefile :

 цель: ifeq ($(собираемся-под),супер-ось) @echo 'ура! собираемся под нашу супер-ось' else @echo 'собираемся под фигню какую-то' endif 

examples of output (only for gnu / make ):

 $ make собираемся под фигню какую-то $ make собираемся-под=супер-ось ура! собираемся под нашу супер-ось 
  • one
    I think it's worth mentioning that ifeq is an extension of GNU Make. Native Make some * BSD will not understand you. There it is necessary to hide the conditions in sh. - Ainar-G