chiark / gitweb /
util: rework rm_rf() logic
[elogind.git] / src / shared / architecture.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2014 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <endian.h>
25
26 #include "util.h"
27
28 /* A cleaned up architecture definition. We don't want to get lost in
29  * processor features, models, generations or even ABIs. Hence we
30  * focus on general family, and distuignish word width and
31  * endianness. */
32
33 enum {
34         ARCHITECTURE_X86 = 0,
35         ARCHITECTURE_X86_64,
36         ARCHITECTURE_PPC,
37         ARCHITECTURE_PPC_LE,
38         ARCHITECTURE_PPC64,
39         ARCHITECTURE_PPC64_LE,
40         ARCHITECTURE_IA64,
41         ARCHITECTURE_PARISC,
42         ARCHITECTURE_PARISC64,
43         ARCHITECTURE_S390,
44         ARCHITECTURE_S390X,
45         ARCHITECTURE_SPARC,
46         ARCHITECTURE_SPARC64,
47         ARCHITECTURE_MIPS,
48         ARCHITECTURE_MIPS_LE,
49         ARCHITECTURE_MIPS64,
50         ARCHITECTURE_MIPS64_LE,
51         ARCHITECTURE_ALPHA,
52         ARCHITECTURE_ARM,
53         ARCHITECTURE_ARM_BE,
54         ARCHITECTURE_ARM64,
55         ARCHITECTURE_ARM64_BE,
56         ARCHITECTURE_SH,
57         ARCHITECTURE_SH64,
58         ARCHITECTURE_M68K,
59         ARCHITECTURE_TILEGX,
60         ARCHITECTURE_CRIS,
61         _ARCHITECTURE_MAX,
62         _ARCHITECTURE_INVALID = -1
63 };
64
65 int uname_architecture(void);
66
67 /*
68  * LIB_ARCH_TUPLE should resolve to the local library path
69  * architecture tuple systemd is built for, according to the Debian
70  * tuple list:
71  *
72  * https://wiki.debian.org/Multiarch/Tuples
73  *
74  * This is used in library search paths that should understand
75  * Debian's paths on all distributions.
76  */
77
78 #if defined(__x86_64__)
79 #  define native_architecture() ARCHITECTURE_X86_64
80 #  define LIB_ARCH_TUPLE "x86_64-linux-gnu"
81 #elif defined(__i386__)
82 #  define native_architecture() ARCHITECTURE_X86
83 #  define LIB_ARCH_TUPLE "i386-linux-gnu"
84 #elif defined(__powerpc64__)
85 #  if __BYTE_ORDER == __BIG_ENDIAN
86 #    define native_architecture() ARCHITECTURE_PPC64
87 #    define LIB_ARCH_TUPLE "ppc64-linux-gnu"
88 #  else
89 #    define native_architecture() ARCHITECTURE_PPC64_LE
90 #    define LIB_ARCH_TUPLE  "powerpc64le-linux-gnu"
91 #  endif
92 #elif defined(__powerpc__)
93 #  if __BYTE_ORDER == __BIG_ENDIAN
94 #    define native_architecture() ARCHITECTURE_PPC
95 #    define LIB_ARCH_TUPLE "powerpc-linux-gnu"
96 #  else
97 #    define native_architecture() ARCHITECTURE_PPC_LE
98 #    error "Missing LIB_ARCH_TUPLE for PPCLE"
99 #  endif
100 #elif defined(__ia64__)
101 #  define native_architecture() ARCHITECTURE_IA64
102 #  define LIB_ARCH_TUPLE "ia64-linux-gnu"
103 #elif defined(__hppa64__)
104 #  define native_architecture() ARCHITECTURE_PARISC64
105 #  error "Missing LIB_ARCH_TUPLE for HPPA64"
106 #elif defined(__hppa__)
107 #  define native_architecture() ARCHITECTURE_PARISC
108 #  define LIB_ARCH_TUPLE "hppa‑linux‑gnu"
109 #elif defined(__s390x__)
110 #  define native_architecture() ARCHITECTURE_S390X
111 #  define LIB_ARCH_TUPLE "s390x-linux-gnu"
112 #elif defined(__s390__)
113 #  define native_architecture() ARCHITECTURE_S390
114 #  define LIB_ARCH_TUPLE "s390-linux-gnu"
115 #elif defined(__sparc64__)
116 #  define native_architecture() ARCHITECTURE_SPARC64
117 #  define LIB_ARCH_TUPLE "sparc64-linux-gnu"
118 #elif defined(__sparc__)
119 #  define native_architecture() ARCHITECTURE_SPARC
120 #  define LIB_ARCH_TUPLE "sparc-linux-gnu"
121 #elif defined(__mips64__)
122 #  if __BYTE_ORDER == __BIG_ENDIAN
123 #    define native_architecture() ARCHITECTURE_MIPS64
124 #    error "Missing LIB_ARCH_TUPLE for MIPS64"
125 #  else
126 #    define native_architecture() ARCHITECTURE_MIPS64_LE
127 #    error "Missing LIB_ARCH_TUPLE for MIPS64_LE"
128 #  endif
129 #elif defined(__mips__)
130 #  if __BYTE_ORDER == __BIG_ENDIAN
131 #    define native_architecture() ARCHITECTURE_MIPS
132 #    define LIB_ARCH_TUPLE "mips-linux-gnu"
133 #  else
134 #    define native_architecture() ARCHITECTURE_MIPS_LE
135 #    define LIB_ARCH_TUPLE "mipsel-linux-gnu"
136 #  endif
137 #elif defined(__alpha__)
138 #  define native_architecture() ARCHITECTURE_ALPHA
139 #  define LIB_ARCH_TUPLE "alpha-linux-gnu"
140 #elif defined(__aarch64__)
141 #  if __BYTE_ORDER == __BIG_ENDIAN
142 #    define native_architecture() ARCHITECTURE_ARM64_BE
143 #    define LIB_ARCH_TUPLE "aarch64_be-linux-gnu"
144 #  else
145 #    define native_architecture() ARCHITECTURE_ARM64
146 #    define LIB_ARCH_TUPLE "aarch64-linux-gnu"
147 #  endif
148 #elif defined(__arm__)
149 #  if __BYTE_ORDER == __BIG_ENDIAN
150 #    define native_architecture() ARCHITECTURE_ARM_BE
151 #    if defined(__ARM_EABI__)
152 #      if defined(__ARM_PCS_VFP)
153 #        define LIB_ARCH_TUPLE "armeb-linux-gnueabihf"
154 #      else
155 #        define LIB_ARCH_TUPLE "armeb-linux-gnueabi"
156 #      endif
157 #    else
158 #      define LIB_ARCH_TUPLE "armeb-linux-gnu"
159 #    endif
160 #  else
161 #    define native_architecture() ARCHITECTURE_ARM
162 #    if defined(__ARM_EABI__)
163 #      if defined(__ARM_PCS_VFP)
164 #        define LIB_ARCH_TUPLE "arm-linux-gnueabihf"
165 #      else
166 #        define LIB_ARCH_TUPLE "arm-linux-gnueabi"
167 #      endif
168 #    else
169 #      define LIB_ARCH_TUPLE "arm-linux-gnu"
170 #    endif
171 #  endif
172 #elif defined(__sh64__)
173 #  define native_architecture() ARCHITECTURE_SH64
174 #  error "Missing LIB_ARCH_TUPLE for SH64"
175 #elif defined(__sh__)
176 #  define native_architecture() ARCHITECTURE_SH
177 #  define LIB_ARCH_TUPLE "sh4-linux-gnu"
178 #elif defined(__m68k__)
179 #  define native_architecture() ARCHITECTURE_M68K
180 #  define LIB_ARCH_TUPLE "m68k-linux-gnu"
181 #elif defined(__tilegx__)
182 #  define native_architecture() ARCHITECTURE_TILEGX
183 #  error "Missing LIB_ARCH_TUPLE for TILEGX"
184 #elif defined(__cris__)
185 #  define native_architecture() ARCHITECTURE_CRIS
186 #  error "Missing LIB_ARCH_TUPLE for CRIS"
187 #else
188 #  error "Please register your architecture here!"
189 #endif
190
191 const char *architecture_to_string(int a) _const_;
192 int architecture_from_string(const char *s) _pure_;