diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-01-17 13:29:59 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-01-17 14:06:56 +0100 |
commit | 0f97b92f29d05247151920c6fc14eebe87d0a9bb (patch) | |
tree | 3ff05d8f3fb2fd08836d18e4ef7ea6c4f73e3cc4 | |
parent | cd25750b52d03962220663e5c29d2a336a5fceaa (diff) | |
download | vala-wip/arch-defines.tar.gz |
vala: Add define VALA_ARCH_* to allow buildtime architecture checkwip/arch-defines
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/parser/preprocessor-arch.vala | 55 | ||||
-rw-r--r-- | vala/valacodecontext.vala | 2 | ||||
-rw-r--r-- | vapi/config.vapi | 1 |
5 files changed, 63 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index cd036c78e..7887ecd39 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,7 @@ AC_PROG_INSTALL AC_PROG_MKDIR_P AC_CANONICAL_HOST +AC_CANONICAL_CPU_ARCH # Detect the target system build_linux=no @@ -56,6 +57,9 @@ case "${host_os}" in esac AM_CONDITIONAL([HAVE_LINUX], [test "$build_linux" = "yes"]) +AC_SUBST(PACKAGE_TARGET_CPU_ARCH) +AC_DEFINE_UNQUOTED(PACKAGE_TARGET_CPU_ARCH, "$target_cpu_arch", [Define to the target architecture]) + LT_PREREQ([2.2.6]) LT_INIT([disable-static]) PKG_PROG_PKG_CONFIG([0.21]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 5156172d2..be96cf7ec 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -934,6 +934,7 @@ TESTS = \ parser/namespaces.vala \ parser/namespace-missing-bracket.test \ parser/preprocessor.vala \ + parser/preprocessor-arch.vala \ parser/preprocessor-glib.vala \ parser/preprocessor-vala.vala \ parser/property-default-redefined.test \ diff --git a/tests/parser/preprocessor-arch.vala b/tests/parser/preprocessor-arch.vala new file mode 100644 index 000000000..198ed4345 --- /dev/null +++ b/tests/parser/preprocessor-arch.vala @@ -0,0 +1,55 @@ +/* + x86_64 + i386 + ppc64el + ppc + aarch64 + arm + sparc64 + sparc + mips64 + mips + alpha + hppa1 + hppa2 + m68k + s390x +*/ +void main () { +#if VALA_ARCH_X86_64 + assert (sizeof (void*) == 8); + assert (sizeof (int) == 4); + assert (sizeof (uint8) == 1); + assert (sizeof (uint16) == 2); + assert (sizeof (uint32) == 4); + assert (sizeof (size_t) == 8); + assert (sizeof (ssize_t) == 8); + assert (sizeof (uint64) == 8); + assert (sizeof (int64) == 8); +#elif VALA_ARCH_I386 + assert (sizeof (void*) == 4); + assert (sizeof (int) == 4); + assert (sizeof (uint8) == 1); + assert (sizeof (uint16) == 2); + assert (sizeof (uint32) == 4); + assert (sizeof (size_t) == 4); + assert (sizeof (ssize_t) == 4); + assert (sizeof (uint64) == 8); + assert (sizeof (int64) == 8); +#elif VALA_ARCH_PPC64EL +#elif VALA_ARCH_PPC +#elif VALA_ARCH_AARCH64 +#elif VALA_ARCH_ARM +#elif VALA_ARCH_SPARC64 +#elif VALA_ARCH_SPARC +#elif VALA_ARCH_MIPS64 +#elif VALA_ARCH_MIPS +#elif VALA_ARCH_ALPHA +#elif VALA_ARCH_HPPA1 +#elif VALA_ARCH_HPPA2 +#elif VALA_ARCH_M68K +#elif VALA_ARCH_S390X +#else + message ("Targeting an unkown arch"); +#endif +} diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 9fc211f7a..707f69d67 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -582,6 +582,8 @@ public class Vala.CodeContext { for (int i = 16; i <= target_glib_minor; i += 2) { defines.add ("GLIB_2_%d".printf (i)); } + + defines.add ("VALA_ARCH_%s".printf (Config.PACKAGE_TARGET_CPU_ARCH.ascii_up ().replace ("-", "_"))); } /** diff --git a/vapi/config.vapi b/vapi/config.vapi index c8b5d58a1..b67b67160 100644 --- a/vapi/config.vapi +++ b/vapi/config.vapi @@ -24,6 +24,7 @@ namespace Config { public const string PACKAGE_DATADIR; public const string PACKAGE_SUFFIX; + public const string PACKAGE_TARGET_CPU_ARCH; public const string PACKAGE_VALADOC_LIBDIR; public const string PACKAGE_VALADOC_ICONDIR; } |