summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2010-09-15 20:54:15 +0200
committerWaldemar Brodkorb <wbx@openadk.org>2010-09-15 20:54:15 +0200
commit4422cda575db22275b067e07ad4b585572d91756 (patch)
tree04557c9f49a6088540cdedc7c68e04dd61132531 /tools
parent30fc540d30f82c534a3bdfff265f8b62cb770551 (diff)
rebuild packages on flavour or choices change
add new target rebuild. make cpio and pacch quiet. Use bin/tools for cpio and mkcrypt.
Diffstat (limited to 'tools')
-rw-r--r--tools/adk/Makefile5
-rw-r--r--tools/adk/pkgrebuild.c234
-rw-r--r--tools/cpio/Makefile6
-rw-r--r--tools/cpio/src/cpio.c2
-rw-r--r--tools/mkcrypt/Makefile6
5 files changed, 245 insertions, 8 deletions
diff --git a/tools/adk/Makefile b/tools/adk/Makefile
index 28d8787ce..3f2048e68 100644
--- a/tools/adk/Makefile
+++ b/tools/adk/Makefile
@@ -6,6 +6,9 @@ include $(TOPDIR)/rules.mk
${TOPDIR}/bin/tools/depmaker:
$(HOSTCC) -o $(TOPDIR)/bin/tools/depmaker depmaker.c
-install: ${TOPDIR}/bin/tools/depmaker
+${TOPDIR}/bin/tools/pkgrebuild:
+ $(HOSTCC) -o $(TOPDIR)/bin/tools/pkgrebuild pkgrebuild.c strmap.c
+
+install: ${TOPDIR}/bin/tools/depmaker ${TOPDIR}/bin/tools/pkgrebuild
include $(TOPDIR)/mk/tools.mk
diff --git a/tools/adk/pkgrebuild.c b/tools/adk/pkgrebuild.c
new file mode 100644
index 000000000..5a8f438c1
--- /dev/null
+++ b/tools/adk/pkgrebuild.c
@@ -0,0 +1,234 @@
+/*
+ * pkgrebuild - recognize required package rebuilds in OpenADK
+ *
+ * Copyright (C) 2010 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);
+ 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);
+ 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;
+ char *pkg_name, *keystr;
+ 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_FLAVOURS:=");
+ 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;
+ }
+ }
+ 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;
+ }
+ }
+ string = strstr(pbuf, "PKG_FLAVOURS+=");
+ 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.");
+
+ 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.");
+
+ 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);
+}
diff --git a/tools/cpio/Makefile b/tools/cpio/Makefile
index d14fb56df..142f65b70 100644
--- a/tools/cpio/Makefile
+++ b/tools/cpio/Makefile
@@ -27,9 +27,9 @@ SRCS+= \
src/nonpax.c \
src/cpio.c
-${STAGING_TOOLS}/bin/cpio: ${SRCS}
- ${HOSTCC} ${HOSTCFLAGS} -D_GNU_SOURCE -Isrc -o $@ $^
+${TOPDIR}/bin/tools/cpio: ${SRCS}
+ @${HOSTCC} ${HOSTCFLAGS} -D_GNU_SOURCE -Isrc -o $@ $^
-install: ${STAGING_TOOLS}/bin/cpio
+install: ${TOPDIR}/bin/tools/cpio
include $(TOPDIR)/mk/tools.mk
diff --git a/tools/cpio/src/cpio.c b/tools/cpio/src/cpio.c
index d91f25dc1..cf9cb0ef8 100644
--- a/tools/cpio/src/cpio.c
+++ b/tools/cpio/src/cpio.c
@@ -1000,7 +1000,7 @@ main(int argc, char **argv)
prdot(1);
if (pax != PAX_TYPE_CPIO)
pax_onexit();
- fprintf(stderr, "%llu blocks\n", blocks + ((bytes + 0777) >> 9));
+ //fprintf(stderr, "%llu blocks\n", blocks + ((bytes + 0777) >> 9));
mclose();
if (errcnt && sysv3 == 0)
fprintf(stderr, "%llu error(s)\n", errcnt);
diff --git a/tools/mkcrypt/Makefile b/tools/mkcrypt/Makefile
index 3b1924c5b..4baf56c44 100644
--- a/tools/mkcrypt/Makefile
+++ b/tools/mkcrypt/Makefile
@@ -3,9 +3,9 @@
include $(TOPDIR)/rules.mk
-${STAGING_TOOLS}/bin/mkcrypt:
- $(HOSTCC) -o $(STAGING_TOOLS)/bin/mkcrypt mkcrypt.c
+${TOPDIR}/bin/tools/mkcrypt:
+ $(HOSTCC) -o $(TOPDIR)/bin/tools/mkcrypt mkcrypt.c
-install: ${STAGING_TOOLS}/bin/mkcrypt
+install: ${TOPDIR}/bin/tools/mkcrypt
include $(TOPDIR)/mk/tools.mk