Question: Does GCC (or alternatively Clang) defines any macro when it is compiled for the Arch Linux OS?

I need to check that my software restricts itself from compiling under anything but Arch Linux (the reason behind this is off-topic). I couldn't find any relevant resources on the internet.

Does anyone know how to guarantee through GCC preprocessor directives that my binaries are only compilable under Arch Linux?

Of course I can always

```c
#ifdef __linux__
  ...
#endif

```

But this is not precise enough.

Edit: This **must** be done through C source code and not by any building systems, so, for example, doing this through CMake is completely discarded.

Edit 2: Users faking this behaviour is not a problem since the software is distributed to selected clients and thus, actively trying to "misuse" our source code is "their decision".

Answer: 
You can list the predefined preprocessor macros with

```
gcc -dM -E - /dev/null
clang -dM -E - /dev/null

```

None of those indicate what operating system the compiler is running under. So not only you can't tell whether the program is compiled under Arch Linux, you can't even tell whether the program is compiled under Linux. The macros `__linux__` and friends indicate that the program is being compiler *for* Linux. They are defined when cross-compiling from another system to Linux, and not defined when cross-compiling from Linux to another system.

You can artificially make your program more difficult to compile by specifying absolute paths for system headers and relying on non-portable headers (e.g. `/usr/include/bits/foo.h`). That can make cross-compilation or compilation for anything other than Linux practically impossible without modifying the source code. However, most Linux distributions install headers in the same location, so you're unlikely to pinpoint a specific distribution.

You're very likely [asking the wrong question](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Instead of asking *how* to restrict compilation to Arch Linux, start from *why* you want to restrict compilation to Arch Linux. If the answer is “because the resulting program wouldn't be what I want under another distribution”, then start from there and make sure that the difference results in a compilation error rather than incorrect execution. If the answer to “why” is something else, then you're probably looking for a technical solution to a social problem, and that rarely ends well.
No, it doesn't. And even if it did, it wouldn't stop anyone from compiling the code on an Arch Linux distro and then running it on a different Linux.

If you need to prevent your software from "from running under anything but Arch Linux", you'll need to insert a run-time check. Although, to be honest, I have no idea what that check might consist of, since linux distros are not monolithic products. The actual check would probably have to do with your reasons for imposing the restriction.