Are these macros defined in Makefile or by some environment which can
detect the platform types?
/* common code here */
#ifdef LINUX
/* other os spefic code */
#elif defined VXWORKS
/* other os spefic code */
#elif defined MACOSX
/* other os spefic code */
#elif defined WIN32
/* other os spefic code */
#endif
/* common code here */
There is no one answer to that. They can be defined in user code. Most
compilers provide some mechanism for pre-defining some identifiers
before the code is processed. For instance, all of the compilers I use
would accept a "-DLINUX" option which has the same effect as
#define LINUX
or a "-DLINUX=1' option which has the same effect as
#define LINUX 1
However, it often happens that make files will set these options as part
of the build script for your program. POSIX make files (I'm not familiar
with non-POSIX make files, if there are such things) allow you to define
make variables, which are often used to store such options, and any such
variable that is not explicitly set by the make file is implicitly
filled in by using the value of an environment variable of the same
name. Therefore, while the environment and the make file do not set
these macros, they both typically play a role in getting them set.
In short, there's no simple answer to your question. About the only
possibility that does not exist is that a fully conforming C compiler
would pre-define any of these macros itself. Those names all are from
the name space reserved for users, so a conforming implementation can't
predefine them.