2 * pkgrebuild - recognize required package rebuilds in OpenADK
4 * Copyright (C) 2010,2011 Waldemar Brodkorb <wbx@openadk.org>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include <sys/types.h>
32 StrMap
*configmap
, *configoldmap
, *pkgmap
;
35 static void iter(const char *key, const char *value, const void *obj) {
36 fprintf(stderr, "key: %s value: %s\n", key, value);
40 static void iter_disabled(const char *key
, const char *value
, const void *obj
) {
46 memset(hvalue
, 0, 256);
47 if (strmap_exists(configmap
, key
) == 0) {
48 //fprintf(stderr, "disabled variables: %s\n", key);
49 if (strmap_get(pkgmap
, key
, hvalue
, sizeof(hvalue
)) == 1) {
50 //fprintf(stderr, "Symbol is a flavour/choice: %s\n", hvalue);
51 if (snprintf(tfile
, 256, ".rebuild.%s", hvalue
) < 0)
52 perror("can not create file variable.");
53 fd
= open(tfile
, O_RDWR
| O_CREAT
, S_IRUSR
| S_IWUSR
);
60 static void iter_enabled(const char *key
, const char *value
, const void *obj
) {
66 memset(hvalue
, 0, 256);
67 if (strmap_exists(configoldmap
, key
) == 0) {
68 //fprintf(stderr, "enabled variables: %s\n", key);
69 if (strmap_get(pkgmap
, key
, hvalue
, sizeof(hvalue
)) == 1) {
70 //fprintf(stderr, "Symbol is a flavour/choice\n");
71 if (snprintf(tfile
, 256, ".rebuild.%s", hvalue
) < 0)
72 perror("can not create file variable.");
73 fd
= open(tfile
, O_RDWR
| O_CREAT
, S_IRUSR
| S_IWUSR
);
79 static char *toupperstr(char *string
) {
84 /* transform to uppercase variable name */
86 for (i
=0; i
<(int)strlen(str
); i
++) {
91 str
[i
] = toupper(str
[i
]);
100 FILE *config
, *configold
, *pkg
;
101 char *key
, *value
, *string
, *token
, *check
;
102 char *pkg_name
, *keystr
, *realpkgname
;
107 struct dirent
*pkgdirp
;
110 /* read Makefile's for all packages */
111 pkgmap
= strmap_new(1024);
112 pkgdir
= opendir("package");
113 while ((pkgdirp
= readdir(pkgdir
)) != NULL
) {
115 if (strncmp(pkgdirp
->d_name
, ".", 1) > 0) {
116 if (snprintf(path
, 320, "package/%s/Makefile", pkgdirp
->d_name
) < 0)
117 perror("can not create path variable.");
118 pkg
= fopen(path
, "r");
122 while (fgets(pbuf
, 320, pkg
) != NULL
) {
123 if (strncmp(pbuf
, "PKG", 3) == 0) {
124 string
= strstr(pbuf
, "PKG_NAME:=");
125 if (string
!= NULL
) {
126 string
[strlen(string
)-1] = '\0';
127 key
= strtok(string
, ":=");
128 value
= strtok(NULL
, "=\t");
130 pkg_name
= strdup(value
);
132 string
= strstr(pbuf
, "PKG_SUBPKGS:=");
133 if (string
!= NULL
) {
134 string
[strlen(string
)-1] = '\0';
135 key
= strtok(string
, ":=");
136 value
= strtok(NULL
, "=\t");
137 token
= strtok(value
, " ");
138 while (token
!= NULL
) {
139 keystr
= malloc(256);
140 memset(keystr
, 0, 256);
141 strncat(keystr
, "ADK_PACKAGE_", 12);
142 strncat(keystr
, token
, strlen(token
));
143 strmap_put(pkgmap
, keystr
, pkgdirp
->d_name
);
144 token
= strtok(NULL
, " ");
149 string
= strstr(pbuf
, "PKG_SUBPKGS+=");
150 if (string
!= NULL
) {
151 string
[strlen(string
)-1] = '\0';
152 key
= strtok(string
, "+=");
153 value
= strtok(NULL
, "=\t");
154 token
= strtok(value
, " ");
155 while (token
!= NULL
) {
156 keystr
= malloc(256);
157 memset(keystr
, 0, 256);
158 strncat(keystr
, "ADK_PACKAGE_", 12);
159 strncat(keystr
, token
, strlen(token
));
160 strmap_put(pkgmap
, keystr
, pkgdirp
->d_name
);
161 token
= strtok(NULL
, " ");
166 string
= strstr(pbuf
, "PKG_FLAVOURS_");
167 if (string
!= NULL
) {
168 check
= strstr(pbuf
, ":=");
170 string
[strlen(string
)-1] = '\0';
171 key
= strtok(string
, ":=");
172 realpkgname
= strdup(key
+13);
173 value
= strtok(NULL
, "=\t");
174 token
= strtok(value
, " ");
175 while (token
!= NULL
) {
176 keystr
= malloc(256);
177 memset(keystr
, 0, 256);
178 strncat(keystr
, "ADK_PACKAGE_", 12);
179 strncat(keystr
, realpkgname
, strlen(realpkgname
));
180 strncat(keystr
, "_", 1);
181 strncat(keystr
, token
, strlen(token
));
182 strmap_put(pkgmap
, keystr
, pkgdirp
->d_name
);
183 token
= strtok(NULL
, " ");
188 string
[strlen(string
)-1] = '\0';
189 key
= strtok(string
, "+=");
190 realpkgname
= strdup(key
+13);
191 value
= strtok(NULL
, "=\t");
192 token
= strtok(value
, " ");
193 while (token
!= NULL
) {
194 keystr
= malloc(256);
195 memset(keystr
, 0, 256);
196 strncat(keystr
, "ADK_PACKAGE_", 12);
197 strncat(keystr
, realpkgname
, strlen(realpkgname
));
198 strncat(keystr
, "_", 1);
199 strncat(keystr
, token
, strlen(token
));
200 strmap_put(pkgmap
, keystr
, pkgdirp
->d_name
);
201 token
= strtok(NULL
, " ");
207 string
= strstr(pbuf
, "PKG_CHOICES_");
208 if (string
!= NULL
) {
209 string
[strlen(string
)-1] = '\0';
210 key
= strtok(string
, ":=");
211 value
= strtok(NULL
, "=\t");
212 token
= strtok(value
, " ");
213 while (token
!= NULL
) {
214 keystr
= malloc(256);
215 memset(keystr
, 0, 256);
216 strncat(keystr
, "ADK_PACKAGE_", 12);
217 strncat(keystr
, toupperstr(pkg_name
), strlen(pkg_name
));
218 strncat(keystr
, "_", 1);
219 strncat(keystr
, token
, strlen(token
));
220 strmap_put(pkgmap
, keystr
, pkgdirp
->d_name
);
221 token
= strtok(NULL
, " ");
233 config
= fopen(".config", "r");
234 if (config
== NULL
) {
235 perror(".config is missing.");
239 configmap
= strmap_new(1024);
240 while (fgets(buf
, 128, config
) != NULL
) {
241 if (strncmp(buf
, "ADK_PACKAGE", 11) == 0) {
242 key
= strtok(buf
, "=");
243 value
= strtok(NULL
, "=");
244 strmap_put(configmap
, key
, value
);
249 configold
= fopen(".config.old", "r");
250 if (configold
== NULL
) {
251 perror(".config.old is missing.");
255 configoldmap
= strmap_new(1024);
256 while (fgets(buf
, 128, configold
) != NULL
) {
257 if (strncmp(buf
, "ADK_PACKAGE", 11) == 0) {
258 key
= strtok(buf
, "=");
259 value
= strtok(NULL
, "=");
260 strmap_put(configoldmap
, key
, value
);
265 //fprintf(stdout, "Config Count: %d\n", strmap_get_count(configmap));
266 //fprintf(stdout, "Config Old Count: %d\n", strmap_get_count(configoldmap));
268 strmap_enum(configoldmap
, iter_disabled
, NULL
);
269 strmap_enum(configmap
, iter_enabled
, NULL
);
270 //strmap_enum(pkgmap, iter, NULL);
272 strmap_delete(pkgmap
);
273 strmap_delete(configmap
);
274 strmap_delete(configoldmap
);