OS detecting makefile

There are many good answers here already, but I wanted to share a more complete example that both: doesn’t assume uname exists on Windows also detects the processor The CCFLAGS defined here aren’t necessarily recommended or ideal; they’re just what the project to which I was adding OS/CPU auto-detection happened to be using. ifeq ($(OS),Windows_NT) … Read more

How to detect the OS from a Bash script?

I think the following should work. I’m not sure about win32 though. if [[ “$OSTYPE” == “linux-gnu”* ]]; then # … elif [[ “$OSTYPE” == “darwin”* ]]; then # Mac OSX elif [[ “$OSTYPE” == “cygwin” ]]; then # POSIX compatibility layer and Linux environment emulation for Windows elif [[ “$OSTYPE” == “msys” ]]; then … Read more

How to detect reliably Mac OS X, iOS, Linux, Windows in C preprocessor? [duplicate]

There are predefined macros that are used by most compilers, you can find the list here. GCC compiler predefined macros can be found here. Here is an example for gcc: #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) //define something for Windows (32-bit and 64-bit, this part is common) #ifdef _WIN64 //define something for Windows … Read more