1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <dp_platform.hxx>
23 #include <rtl/ustring.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <rtl/instance.hxx>
26 #include <rtl/bootstrap.hxx>
27 #include <osl/diagnose.h>
29 #define PLATFORM_ALL "all"
36 struct StrOperatingSystem
:
37 public rtl::StaticWithInit
<OUString
, StrOperatingSystem
> {
38 OUString
operator () () {
39 OUString
os( "$_OS" );
40 ::rtl::Bootstrap::expandMacros( os
);
46 public rtl::StaticWithInit
<OUString
, StrCPU
> {
47 OUString
operator () () {
48 OUString
arch( "$_ARCH" );
49 ::rtl::Bootstrap::expandMacros( arch
);
55 struct StrPlatform
: public rtl::StaticWithInit
<
56 OUString
, StrPlatform
> {
57 OUString
operator () () {
59 buf
.append( StrOperatingSystem::get() );
61 buf
.append( StrCPU::get() );
62 return buf
.makeStringAndClear();
66 bool checkOSandCPU(OUString
const & os
, OUString
const & cpu
)
68 return (os
== StrOperatingSystem::get())
69 && (cpu
== StrCPU::get());
72 bool isPlatformSupported( OUString
const & token
)
75 if (token
== PLATFORM_ALL
)
77 else if (token
== "windows_x86")
78 ret
= checkOSandCPU("Windows", "x86");
79 else if (token
== "windows_x86_64")
80 ret
= checkOSandCPU("Windows", "X86_64");
81 else if (token
== "solaris_sparc")
82 ret
= checkOSandCPU("Solaris", "SPARC");
83 else if (token
== "solaris_sparc64")
84 ret
= checkOSandCPU("Solaris", "SPARC64");
85 else if (token
== "solaris_x86")
86 ret
= checkOSandCPU("Solaris", "x86");
87 else if (token
== "aix_powerpc")
88 ret
= checkOSandCPU("AIX", "PowerPC");
89 else if (token
== "macosx_x86_64")
90 ret
= checkOSandCPU("MacOSX", "X86_64");
91 else if (token
== "linux_x86")
92 ret
= checkOSandCPU("Linux", "x86");
93 else if (token
== "linux_x86_64")
94 ret
= checkOSandCPU("Linux", "X86_64");
95 else if (token
== "linux_sparc")
96 ret
= checkOSandCPU("Linux", "SPARC");
97 else if (token
== "linux_sparc64")
98 ret
= checkOSandCPU("Linux", "SPARC64");
99 else if (token
== "linux_powerpc")
100 ret
= checkOSandCPU("Linux", "PowerPC");
101 else if (token
== "linux_powerpc64")
102 ret
= checkOSandCPU("Linux", "PowerPC_64");
103 else if (token
== "linux_powerpc64_le")
104 ret
= checkOSandCPU("Linux", "PowerPC_64_LE");
105 else if (token
== "linux_arm_eabi")
106 ret
= checkOSandCPU("Linux", "ARM_EABI");
107 else if (token
== "linux_arm_oabi")
108 ret
= checkOSandCPU("Linux", "ARM_OABI");
109 else if (token
== "linux_mips_el")
110 ret
= checkOSandCPU("Linux", "MIPS_EL");
111 else if (token
== "linux_mips64_el")
112 ret
= checkOSandCPU("Linux", "MIPS64_EL");
113 else if (token
== "linux_mips_eb")
114 ret
= checkOSandCPU("Linux", "MIPS_EB");
115 else if (token
== "linux_mips64_eb")
116 ret
= checkOSandCPU("Linux", "MIPS64_EB");
117 else if (token
== "linux_ia64")
118 ret
= checkOSandCPU("Linux", "IA64");
119 else if (token
== "linux_m68k")
120 ret
= checkOSandCPU("Linux", "M68K");
121 else if (token
== "linux_s390")
122 ret
= checkOSandCPU("Linux", "S390");
123 else if (token
== "linux_s390x")
124 ret
= checkOSandCPU("Linux", "S390x");
125 else if (token
== "linux_hppa")
126 ret
= checkOSandCPU("Linux", "HPPA");
127 else if (token
== "linux_alpha")
128 ret
= checkOSandCPU("Linux", "ALPHA");
129 else if (token
== "linux_aarch64")
130 ret
= checkOSandCPU("Linux", "AARCH64");
131 else if (token
== "freebsd_x86")
132 ret
= checkOSandCPU("FreeBSD", "x86");
133 else if (token
== "freebsd_x86_64")
134 ret
= checkOSandCPU("FreeBSD", "X86_64");
135 else if (token
== "freebsd_powerpc")
136 ret
= checkOSandCPU("FreeBSD", "PowerPC");
137 else if (token
== "kfreebsd_x86")
138 ret
= checkOSandCPU("kFreeBSD", "x86");
139 else if (token
== "kfreebsd_x86_64")
140 ret
= checkOSandCPU("kFreeBSD", "X86_64");
141 else if (token
== "netbsd_x86")
142 ret
= checkOSandCPU("NetBSD", "x86");
143 else if (token
== "netbsd_x86_64")
144 ret
= checkOSandCPU("NetBSD", "X86_64");
145 else if (token
== "openbsd_x86")
146 ret
= checkOSandCPU("OpenBSD", "x86");
147 else if (token
== "openbsd_x86_64")
148 ret
= checkOSandCPU("OpenBSD", "X86_64");
149 else if (token
== "dragonfly_x86")
150 ret
= checkOSandCPU("DragonFly", "x86");
151 else if (token
== "dragonfly_x86_64")
152 ret
= checkOSandCPU("DragonFly", "X86_64");
155 OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
156 "Check the platform in the description.xml");
165 OUString
const & getPlatformString()
167 return StrPlatform::get();
170 bool platform_fits( OUString
const & platform_string
)
175 const OUString
token(
176 platform_string
.getToken( 0, ',', index
).trim() );
177 // check if this platform:
178 if (token
.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
179 (token
.indexOf( '_' ) < 0 && /* check OS part only */
180 token
.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
190 bool hasValidPlatform( css::uno::Sequence
<OUString
> const & platformStrings
)
193 for (sal_Int32 i
= 0; i
< platformStrings
.getLength(); i
++)
195 if ( isPlatformSupported( platformStrings
[i
] ))
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */