Add arch arvm7tnhl and armv7thl
[platform/upstream/libsolv.git] / src / poolarch.c
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * poolarch.c
10  *
11  * create architecture policies
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17
18 #include "pool.h"
19 #include "poolid.h"
20 #include "poolarch.h"
21 #include "util.h"
22
23 static const char *archpolicies[] = {
24   "x86_64",     "x86_64:i686:i586:i486:i386",
25   "i686",       "i686:i586:i486:i386",
26   "i586",       "i586:i486:i386",
27   "i486",       "i486:i386",
28   "i386",       "i386",
29   "s390x",      "s390x:s390",
30   "s390",       "s390",
31   "ia64",       "ia64:i686:i586:i486:i386",
32   "ppc64",      "ppc64:ppc",
33   "ppc",        "ppc",
34   "armv7tnhl",  "arvm7tnhl:armv7thl:armv7nhl:armv7hl",
35   "armv7thl",   "armv7thl:armv7hl",
36   "armv7nhl",   "armv7nhl:armv7hl",
37   "armv7hl",    "armv7hl",
38   "armv7l",     "armv7l:armv6l:armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l",
39   "armv6l",     "armv6l:armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l",
40   "armv5tejl",  "armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l",
41   "armv5tel",   "armv5tel:armv5l:armv4tl:armv4l:armv3l",
42   "armv5l",     "armv5l:armv4tl:armv4l:armv3l",
43   "armv4tl",    "armv4tl:armv4l:armv3l",
44   "armv4l",     "armv4l:armv3l",
45   "armv3l",     "armv3l",
46   "sh3",        "sh3",
47   "sh4",        "sh4",
48   "sh4a",       "sh4a:sh4",
49   "sparc64v",   "sparc64v:sparc64:sparcv9v:sparcv9:sparcv8:sparc",
50   "sparc64",    "sparc64:sparcv9:sparcv8:sparc",
51   "sparcv9v",   "sparcv9v:sparcv9:sparcv8:sparc",
52   "sparcv9",    "sparcv9:sparcv8:sparc",
53   "sparcv8",    "sparcv8:sparc",
54   "sparc",      "sparc",
55   0
56 };
57
58 void
59 pool_setarch(Pool *pool, const char *arch)
60 {
61   if (arch)
62     {
63       int i;
64
65       /* convert arch to known policy */
66       for (i = 0; archpolicies[i]; i += 2)
67         if (!strcmp(archpolicies[i], arch))
68           break;
69       if (archpolicies[i])
70         arch = archpolicies[i + 1];
71       else
72         arch = "";
73     }
74   pool_setarchpolicy(pool, arch);
75 }
76
77 /*
78  * we support three relations:
79  *
80  * a = b   both architectures a and b are treated as equivalent
81  * a > b   a is considered a "better" architecture, the solver
82  *         should change from a to b, but must not change from b to a
83  * a : b   a is considered a "better" architecture, the solver
84  *         must not change the architecture from a to b or b to a
85  */
86 void
87 pool_setarchpolicy(Pool *pool, const char *arch)
88 {
89   unsigned int score = 0x10001;
90   size_t l;
91   char d;
92   Id *id2arch;
93   Id id, lastarch;
94
95   pool->id2arch = solv_free(pool->id2arch);
96   pool->id2color = solv_free(pool->id2color);
97   if (!arch)
98     {
99       pool->lastarch = 0;
100       return;
101     }
102 #ifndef DEBIAN_SEMANTICS
103   id = ARCH_NOARCH;
104 #else
105   id = ARCH_ALL;
106 #endif
107   lastarch = id + 255;
108   id2arch = solv_calloc(lastarch + 1, sizeof(Id));
109   id2arch[id] = 1;      /* the "noarch" class */
110
111   d = 0;
112   while (*arch)
113     {
114       l = strcspn(arch, ":=>");
115       if (l)
116         {
117           id = pool_strn2id(pool, arch, l, 1);
118           if (id > lastarch)
119             {
120               id2arch = solv_realloc2(id2arch, (id + 255 + 1), sizeof(Id));
121               memset(id2arch + lastarch + 1, 0, (id + 255 - lastarch) * sizeof(Id));
122               lastarch = id + 255;
123             }
124           if (id2arch[id] == 0)
125             {
126               if (d == ':')
127                 score += 0x10000;
128               else if (d == '>')
129                 score += 0x00001;
130               id2arch[id] = score;
131             }
132         }
133       arch += l;
134       if ((d = *arch++) == 0)
135         break;
136     }
137   pool->id2arch = id2arch;
138   pool->lastarch = lastarch;
139 }
140
141 unsigned char
142 pool_arch2color_slow(Pool *pool, Id arch)
143 {
144   const char *s;
145   unsigned char color;
146
147   if (arch > pool->lastarch)
148     return ARCHCOLOR_ALL;
149   if (!pool->id2color)
150     pool->id2color = solv_calloc(pool->lastarch + 1, 1);
151   s = pool_id2str(pool, arch);
152   if (arch == ARCH_NOARCH || arch == ARCH_ALL)
153     color = ARCHCOLOR_ALL;
154   else if (!strcmp(s, "s390x") || strstr(s, "64"))
155     color = ARCHCOLOR_64;
156   else
157     color = ARCHCOLOR_32;
158   return color;
159 }
160