123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- /*
- * pkgrebuild - recognize required package rebuilds in OpenADK
- *
- * Copyright (C) 2010,2011 Waldemar Brodkorb <wbx@openadk.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <ctype.h>
- #include <dirent.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include "strmap.h"
- StrMap *configmap, *configoldmap, *pkgmap;
- /*
- static void iter(const char *key, const char *value, const void *obj) {
- fprintf(stderr, "key: %s value: %s\n", key, value);
- }
- */
- static void iter_disabled(const char *key, const char *value, const void *obj) {
- char hvalue[256];
- char tfile[256];
- int fd;
- memset(hvalue, 0, 256);
- if (strmap_exists(configmap, key) == 0) {
- //fprintf(stderr, "disabled variables: %s\n", key);
- if (strmap_get(pkgmap, key, hvalue, sizeof(hvalue)) == 1) {
- //fprintf(stderr, "Symbol is a flavour/choice: %s\n", hvalue);
- if (snprintf(tfile, 256, ".rebuild.%s", hvalue) < 0)
- perror("can not create file variable.");
- fd = open(tfile, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
- close(fd);
- }
- }
- }
- static void iter_enabled(const char *key, const char *value, const void *obj) {
- char hvalue[256];
- char tfile[256];
- int fd;
- memset(hvalue, 0, 256);
- if (strmap_exists(configoldmap, key) == 0) {
- //fprintf(stderr, "enabled variables: %s\n", key);
- if (strmap_get(pkgmap, key, hvalue, sizeof(hvalue)) == 1) {
- //fprintf(stderr, "Symbol is a flavour/choice\n");
- if (snprintf(tfile, 256, ".rebuild.%s", hvalue) < 0)
- perror("can not create file variable.");
- fd = open(tfile, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
- close(fd);
- }
- }
- }
- static char *toupperstr(char *string) {
- int i;
- char *str;
-
- /* transform to uppercase variable name */
- str = strdup(string);
- for (i=0; i<(int)strlen(str); i++) {
- if (str[i] == '+')
- str[i] = 'X';
- if (str[i] == '-')
- str[i] = '_';
- str[i] = toupper(str[i]);
- }
- return(str);
- }
- int main() {
- FILE *config, *configold, *pkg;
- char *key, *value, *string, *token, *check;
- char *pkg_name, *keystr, *realpkgname;
- char buf[128];
- char path[320];
- char pbuf[320];
- DIR *pkgdir;
- struct dirent *pkgdirp;
- pkg_name = NULL;
- /* read Makefile's for all packages */
- pkgmap = strmap_new(1024);
- pkgdir = opendir("package");
- while ((pkgdirp = readdir(pkgdir)) != NULL) {
- /* skip dotfiles */
- if (strncmp(pkgdirp->d_name, ".", 1) > 0) {
- if (snprintf(path, 320, "package/%s/Makefile", pkgdirp->d_name) < 0)
- perror("can not create path variable.");
- pkg = fopen(path, "r");
- if (pkg == NULL)
- continue;
- while (fgets(pbuf, 320, pkg) != NULL) {
- if (strncmp(pbuf, "PKG", 3) == 0) {
- string = strstr(pbuf, "PKG_NAME:=");
- if (string != NULL) {
- string[strlen(string)-1] = '\0';
- key = strtok(string, ":=");
- value = strtok(NULL, "=\t");
- if (value != NULL)
- pkg_name = strdup(value);
- }
- string = strstr(pbuf, "PKG_SUBPKGS:=");
- if (string != NULL) {
- string[strlen(string)-1] = '\0';
- key = strtok(string, ":=");
- value = strtok(NULL, "=\t");
- token = strtok(value, " ");
- while (token != NULL) {
- keystr = malloc(256);
- memset(keystr, 0, 256);
- strncat(keystr, "ADK_PACKAGE_", 12);
- strncat(keystr, token, strlen(token));
- strmap_put(pkgmap, keystr, pkgdirp->d_name);
- token = strtok(NULL, " ");
- free(keystr);
- keystr = NULL;
- }
- }
- string = strstr(pbuf, "PKG_SUBPKGS+=");
- if (string != NULL) {
- string[strlen(string)-1] = '\0';
- key = strtok(string, "+=");
- value = strtok(NULL, "=\t");
- token = strtok(value, " ");
- while (token != NULL) {
- keystr = malloc(256);
- memset(keystr, 0, 256);
- strncat(keystr, "ADK_PACKAGE_", 12);
- strncat(keystr, token, strlen(token));
- strmap_put(pkgmap, keystr, pkgdirp->d_name);
- token = strtok(NULL, " ");
- free(keystr);
- keystr = NULL;
- }
- }
- string = strstr(pbuf, "PKG_FLAVOURS_");
- if (string != NULL) {
- check = strstr(pbuf, ":=");
- if (check != NULL) {
- string[strlen(string)-1] = '\0';
- key = strtok(string, ":=");
- realpkgname = strdup(key+13);
- value = strtok(NULL, "=\t");
- token = strtok(value, " ");
- while (token != NULL) {
- keystr = malloc(256);
- memset(keystr, 0, 256);
- strncat(keystr, "ADK_PACKAGE_", 12);
- strncat(keystr, realpkgname, strlen(realpkgname));
- strncat(keystr, "_", 1);
- strncat(keystr, token, strlen(token));
- strmap_put(pkgmap, keystr, pkgdirp->d_name);
- token = strtok(NULL, " ");
- free(keystr);
- keystr = NULL;
- }
- } else {
- string[strlen(string)-1] = '\0';
- key = strtok(string, "+=");
- realpkgname = strdup(key+13);
- value = strtok(NULL, "=\t");
- token = strtok(value, " ");
- while (token != NULL) {
- keystr = malloc(256);
- memset(keystr, 0, 256);
- strncat(keystr, "ADK_PACKAGE_", 12);
- strncat(keystr, realpkgname, strlen(realpkgname));
- strncat(keystr, "_", 1);
- strncat(keystr, token, strlen(token));
- strmap_put(pkgmap, keystr, pkgdirp->d_name);
- token = strtok(NULL, " ");
- free(keystr);
- keystr = NULL;
- }
- }
- }
- string = strstr(pbuf, "PKG_CHOICES_");
- if (string != NULL) {
- string[strlen(string)-1] = '\0';
- key = strtok(string, ":=");
- value = strtok(NULL, "=\t");
- token = strtok(value, " ");
- while (token != NULL) {
- keystr = malloc(256);
- memset(keystr, 0, 256);
- strncat(keystr, "ADK_PACKAGE_", 12);
- strncat(keystr, toupperstr(pkg_name), strlen(pkg_name));
- strncat(keystr, "_", 1);
- strncat(keystr, token, strlen(token));
- strmap_put(pkgmap, keystr, pkgdirp->d_name);
- token = strtok(NULL, " ");
- free(keystr);
- keystr = NULL;
- }
- }
- }
- }
- fclose(pkg);
- }
- }
- closedir(pkgdir);
- config = fopen(".config", "r");
- if (config == NULL) {
- perror(".config is missing.");
- exit(1);
- }
-
- configmap = strmap_new(1024);
- while (fgets(buf, 128, config) != NULL) {
- if (strncmp(buf, "ADK_PACKAGE", 11) == 0) {
- key = strtok(buf, "=");
- value = strtok(NULL, "=");
- strmap_put(configmap, key, value);
- }
- }
- fclose(config);
- configold = fopen(".config.old", "r");
- if (configold == NULL) {
- perror(".config.old is missing.");
- exit(1);
- }
-
- configoldmap = strmap_new(1024);
- while (fgets(buf, 128, configold) != NULL) {
- if (strncmp(buf, "ADK_PACKAGE", 11) == 0) {
- key = strtok(buf, "=");
- value = strtok(NULL, "=");
- strmap_put(configoldmap, key, value);
- }
- }
- fclose(configold);
- //fprintf(stdout, "Config Count: %d\n", strmap_get_count(configmap));
- //fprintf(stdout, "Config Old Count: %d\n", strmap_get_count(configoldmap));
- strmap_enum(configoldmap, iter_disabled, NULL);
- strmap_enum(configmap, iter_enabled, NULL);
- //strmap_enum(pkgmap, iter, NULL);
- strmap_delete(pkgmap);
- strmap_delete(configmap);
- strmap_delete(configoldmap);
- return(0);
- }
|