1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
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 canonical_arch (const string & arch);
115 //---------------------------------------------------------------------------
116 // architecture stuff
119 canonical_arch (const string & arch)
121 typedef struct { char *from; char *to; } canonical;
122 // convert machine string to known_arch
123 static canonical canonical_archs[] = {
124 { "noarch", "noarch" },
125 { "unknown", "unknown" },
129 { "ix86", "i386" }, /* OpenPKG uses this */
133 { "x86_64", "x86_64" },
134 { "ia32e", "ia32e" },
135 { "athlon", "athlon" },
137 { "ppc64", "ppc64" },
139 { "s390x", "s390x" },
141 { "sparc", "sparc" },
142 { "sun4c", "sparc" },
143 { "sun4d", "sparc" },
144 { "sun4m", "sparc" },
145 { "sparc64", "sparc64" },
146 { "sun4u", "sparc64" },
147 { "sparcv9", "sparc64" },
151 for (canonical *ptr = canonical_archs; ptr->from; ptr++) {
152 if (arch == ptr->from) {
160 //---------------------------------------------------------------------------
162 ///////////////////////////////////////////////////////////////////
164 ///////////////////////////////////////////////////////////////////
166 // METHOD NAME : Arch::Arch
167 // METHOD TYPE : Ctor
169 Arch::Arch( const std::string & rhs )
173 static map<string,int> arch_scores;
174 if (arch_scores.empty()) {
175 arch_scores["noarch"] = 0;
176 arch_scores["src"] = 0;
177 arch_scores["i386"] = 1;
178 arch_scores["i486"] = 2;
179 arch_scores["i586"] = 3;
180 arch_scores["i686"] = 4;
181 arch_scores["athlon"] = 4;
182 arch_scores["x86_64"] = 5;
183 arch_scores["ia64"] = 1;
184 arch_scores["ppc"] = 1;
185 arch_scores["ppc64"] = 2;
186 arch_scores["s390"] = 1;
187 arch_scores["s390x"] = 2;
189 map<string,int>::const_iterator it = arch_scores.find( rhs );
190 if (it != arch_scores.end())
194 ///////////////////////////////////////////////////////////////////
196 // METHOD NAME : Arch::compatibleWith
197 // METHOD TYPE : bool
199 bool Arch::compatibleWith( const Arch & rhs ) const
201 return _value.empty()
203 || CompatTable::compatible( *this, rhs );
206 /////////////////////////////////////////////////////////////////
208 ///////////////////////////////////////////////////////////////////