1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
14 #include <sys/utsname.h>
16 #include "zypp/Arch.h"
20 ///////////////////////////////////////////////////////////////////
22 { /////////////////////////////////////////////////////////////////
24 /** Dumb Arch compat table
29 static set<string> _compatTable;
31 /** \return Whether \a lhs is compatible with \a rhs. */
32 static bool compatible( const zypp::Arch & lhs, const zypp::Arch & rhs )
34 if ( lhs == zypp::Arch_noarch )
37 if ( _compatTable.empty() )
40 #define DEF_COMPAT(L,R) _compatTable.insert( #L "|" #R )
41 DEF_COMPAT( noarch, i386 );
42 DEF_COMPAT( noarch, i486 );
43 DEF_COMPAT( i386, i486 );
44 DEF_COMPAT( noarch, i586 );
45 DEF_COMPAT( i386, i586 );
46 DEF_COMPAT( i486, i586 );
47 DEF_COMPAT( noarch, i686 );
48 DEF_COMPAT( i386, i686 );
49 DEF_COMPAT( i486, i686 );
50 DEF_COMPAT( i586, i686 );
51 DEF_COMPAT( noarch, athlon );
52 DEF_COMPAT( i386, athlon );
53 DEF_COMPAT( i486, athlon );
54 DEF_COMPAT( i586, athlon );
55 DEF_COMPAT( i686, athlon );
56 DEF_COMPAT( noarch, x86_64 );
57 DEF_COMPAT( i386, x86_64 );
58 DEF_COMPAT( i486, x86_64 );
59 DEF_COMPAT( i586, x86_64 );
60 DEF_COMPAT( i686, x86_64 );
61 DEF_COMPAT( athlon, x86_64 );
63 DEF_COMPAT( noarch, s390 );
64 DEF_COMPAT( noarch, s390x );
65 DEF_COMPAT( s390, s390x );
67 DEF_COMPAT( noarch, ppc );
68 DEF_COMPAT( noarch, ppc64 );
69 DEF_COMPAT( ppc, ppc64 );
71 DEF_COMPAT( noarch, ia64 );
75 return _compatTable.find( lhs.asString()+"|"+rhs.asString() )
76 != _compatTable.end();
80 set<string> CompatTable::_compatTable;
82 /////////////////////////////////////////////////////////////////
84 ///////////////////////////////////////////////////////////////////
86 ///////////////////////////////////////////////////////////////////
88 { /////////////////////////////////////////////////////////////////
90 ///////////////////////////////////////////////////////////////////
91 #define DEF_BUILTIN(A) const Arch Arch_##A( #A )
93 DEF_BUILTIN( noarch );
96 DEF_BUILTIN( x86_64 );
97 DEF_BUILTIN( athlon );
103 DEF_BUILTIN( s390x );
106 DEF_BUILTIN( ppc64 );
113 static const string system_arch (void);
114 static const string canonical_arch (const string & arch);
117 const Arch Arch::System = Arch(system_arch ());
119 //---------------------------------------------------------------------------
120 // architecture stuff
123 canonical_arch (const string & arch)
125 typedef struct { char *from; char *to; } canonical;
126 // convert machine string to known_arch
127 static canonical canonical_archs[] = {
128 { "noarch", "noarch" },
129 { "unknown", "unknown" },
133 { "ix86", "i386" }, /* OpenPKG uses this */
137 { "x86_64", "x86_64" },
138 { "ia32e", "ia32e" },
139 { "athlon", "athlon" },
141 { "ppc64", "ppc64" },
143 { "s390x", "s390x" },
145 { "sparc", "sparc" },
146 { "sun4c", "sparc" },
147 { "sun4d", "sparc" },
148 { "sun4m", "sparc" },
149 { "sparc64", "sparc64" },
150 { "sun4u", "sparc64" },
151 { "sparcv9", "sparc64" },
155 for (canonical *ptr = canonical_archs; ptr->from; ptr++) {
156 if (arch == ptr->from) {
168 static struct utsname buf;
169 static bool checked = false;
172 if (uname (&buf) < 0) {
178 return string (buf.machine);
182 //---------------------------------------------------------------------------
186 ///////////////////////////////////////////////////////////////////
188 ///////////////////////////////////////////////////////////////////
190 // METHOD NAME : Arch::Arch
191 // METHOD TYPE : Ctor
193 Arch::Arch( const std::string & rhs )
197 ///////////////////////////////////////////////////////////////////
199 // METHOD NAME : Arch::compatibleWith
200 // METHOD TYPE : bool
202 bool Arch::compatibleWith( const Arch & rhs ) const
204 return CompatTable::compatible( *this, rhs );
207 /////////////////////////////////////////////////////////////////
209 ///////////////////////////////////////////////////////////////////