From: Eric Engestrom Date: Thu, 1 Aug 2019 13:48:26 +0000 (+0100) Subject: util: introduce detect_os.h X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=362e9d8682a5eb3808fd574d4a21982a58ecafa7;p=mesa.git util: introduce detect_os.h Mostly copied from src/gallium/include/pipe/p_config.h, so I kept its copyright and authorship. Other than the obvious rename, the big difference is that these are always defined, to be used as `#if DETECT_OS_LINUX`. Signed-off-by: Eric Engestrom Reviewed-by: Matt Turner --- diff --git a/src/util/detect_os.h b/src/util/detect_os.h new file mode 100644 index 00000000000..6506948e035 --- /dev/null +++ b/src/util/detect_os.h @@ -0,0 +1,131 @@ +/* SPDX-License-Identifier: MIT */ +/* Copyright 2008 VMware, Inc. */ + +/** + * Auto-detect the operating system family. + * + * See also: + * - http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html + * - echo | gcc -dM -E - | sort + * - http://msdn.microsoft.com/en-us/library/b0084kay.aspx + * + * @author José Fonseca + */ + +#ifndef DETECT_OS_H +#define DETECT_OS_H + +#if defined(__linux__) +#define DETECT_OS_LINUX 1 +#define DETECT_OS_UNIX 1 +#endif + +/* + * Android defines __linux__, so DETECT_OS_LINUX and DETECT_OS_UNIX will + * also be defined. + */ +#if defined(ANDROID) +#define DETECT_OS_ANDROID 1 +#endif + +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#define DETECT_OS_FREEBSD 1 +#define DETECT_OS_BSD 1 +#define DETECT_OS_UNIX 1 +#endif + +#if defined(__OpenBSD__) +#define DETECT_OS_OPENBSD 1 +#define DETECT_OS_BSD 1 +#define DETECT_OS_UNIX 1 +#endif + +#if defined(__NetBSD__) +#define DETECT_OS_NETBSD 1 +#define DETECT_OS_BSD 1 +#define DETECT_OS_UNIX 1 +#endif + +#if defined(__DragonFly__) +#define DETECT_OS_DRAGONFLY 1 +#define DETECT_OS_BSD 1 +#define DETECT_OS_UNIX 1 +#endif + +#if defined(__GNU__) +#define DETECT_OS_HURD 1 +#define DETECT_OS_UNIX 1 +#endif + +#if defined(__sun) +#define DETECT_OS_SOLARIS 1 +#define DETECT_OS_UNIX 1 +#endif + +#if defined(__APPLE__) +#define DETECT_OS_APPLE 1 +#define DETECT_OS_UNIX 1 +#endif + +#if defined(_WIN32) || defined(WIN32) +#define DETECT_OS_WINDOWS 1 +#endif + +#if defined(__HAIKU__) +#define DETECT_OS_HAIKU 1 +#define DETECT_OS_UNIX 1 +#endif + +#if defined(__CYGWIN__) +#define DETECT_OS_CYGWIN 1 +#define DETECT_OS_UNIX 1 +#endif + + +/* + * Make sure DETECT_OS_* are always defined, so that they can be used with #if + */ +#ifndef DETECT_OS_ANDROID +#define DETECT_OS_ANDROID 0 +#endif +#ifndef DETECT_OS_APPLE +#define DETECT_OS_APPLE 0 +#endif +#ifndef DETECT_OS_BSD +#define DETECT_OS_BSD 0 +#endif +#ifndef DETECT_OS_CYGWIN +#define DETECT_OS_CYGWIN 0 +#endif +#ifndef DETECT_OS_DRAGONFLY +#define DETECT_OS_DRAGONFLY 0 +#endif +#ifndef DETECT_OS_FREEBSD +#define DETECT_OS_FREEBSD 0 +#endif +#ifndef DETECT_OS_HAIKU +#define DETECT_OS_HAIKU 0 +#endif +#ifndef DETECT_OS_HURD +#define DETECT_OS_HURD 0 +#endif +#ifndef DETECT_OS_LINUX +#define DETECT_OS_LINUX 0 +#endif +#ifndef DETECT_OS_NETBSD +#define DETECT_OS_NETBSD 0 +#endif +#ifndef DETECT_OS_OPENBSD +#define DETECT_OS_OPENBSD 0 +#endif +#ifndef DETECT_OS_SOLARIS +#define DETECT_OS_SOLARIS 0 +#endif +#ifndef DETECT_OS_UNIX +#define DETECT_OS_UNIX 0 +#endif +#ifndef DETECT_OS_WINDOWS +#define DETECT_OS_WINDOWS 0 +#endif + +#endif /* DETECT_OS_H */