Browse Source

rebuild packages on flavour or choices change

add new target rebuild.
make cpio and pacch quiet.
Use bin/tools for cpio and mkcrypt.
Waldemar Brodkorb 13 years ago
parent
commit
4422cda575

+ 3 - 2
mk/build.mk

@@ -64,8 +64,9 @@ noconfig_targets:=	menuconfig \
 			defconfig \
 			tags
 
-POSTCONFIG=		-@ \
+POSTCONFIG=		-@\
 	if [ -f .config.old ];then \
+		$(TOPDIR)/bin/tools/pkgrebuild;\
 		rebuild=0; \
 		if [ "$$(grep ^BUSYBOX .config|md5sum)" != "$$(grep ^BUSYBOX .config.old|md5sum)" ];then \
 			touch .rebuild.busybox;\
@@ -76,7 +77,7 @@ POSTCONFIG=		-@ \
 			rebuild=1;\
 		fi; \
 		if [ $$rebuild -eq 1 ];then \
-			cp .config .config.old; \
+			cp .config .config.old;\
 		fi; \
 	fi
 

+ 3 - 3
mk/buildhlp.mk

@@ -29,7 +29,7 @@ post-extract:
 ifeq ($(strip ${NO_DISTFILES}),1)
 ${WRKDIST}/.extract_done:
 	rm -rf ${WRKDIST} ${WRKSRC} ${WRKBUILD}
-	mkdir -p ${WRKDIR} ${WRKDIST}
+	@mkdir -p ${WRKDIR} ${WRKDIST}
 	${MAKE} do-extract
 	@${MAKE} post-extract
 	touch $@
@@ -57,9 +57,9 @@ ifeq ($(strip ${__use_generic_patch_target}),42)
 post-patch:
 ${WRKDIST}/.prepared: ${WRKDIST}/.extract_done
 	[ ! -d ./patches/${PKG_VERSION} ] || ${PREVENT_PATCH} ${PATCH} ${WRKDIST} ./patches \
-	    '{patch-!(*.orig),*.patch}'
+	    '{patch-!(*.orig),*.patch}' $(MAKE_TRACE)
 	[ ! -d ./patches ] || ${PREVENT_PATCH} ${PATCH} ${WRKDIST} ./patches \
-	    '{patch-!(*.orig),*.patch}'
+	    '{patch-!(*.orig),*.patch}' $(MAKE_TRACE)
 	[ ! -d ./src ] || (cd src; $(PREVENT_PATCH) cp -Rp . ${WRKDIST}/) \
 		$(MAKE_TRACE)
 	@${MAKE} post-patch $(MAKE_TRACE)

+ 2 - 2
mk/image.mk

@@ -51,7 +51,7 @@ ${BIN_DIR}/${ROOTFSUSERTARBALL}: ${TARGET_DIR}
 ${BIN_DIR}/${INITRAMFS}: ${TARGET_DIR}
 	cd ${TARGET_DIR}; find . | sed -n '/^\.\//s///p' | \
 		sed "s#\(.*\)#:0:0::::::\1#" | sort | \
-	    ${STAGING_TOOLS}/bin/cpio -o -C512 -Hnewc -P | \
+	    ${TOPDIR}/bin/tools/cpio -o -C512 -Hnewc -P | \
 		${ADK_COMPRESSION_TOOL} >$@ 2>/dev/null
 
 ${BUILD_DIR}/${INITRAMFS_PIGGYBACK}: ${TARGET_DIR}
@@ -59,7 +59,7 @@ ${BUILD_DIR}/${INITRAMFS_PIGGYBACK}: ${TARGET_DIR}
 		$(LINUX_DIR)/.config
 	cd ${TARGET_DIR}; find . | sed -n '/^\.\//s///p' | \
 		sed "s#\(.*\)#:0:0::::::\1#" | sort | \
-	    ${STAGING_TOOLS}/bin/cpio -o -C512 -Hnewc -P >$@ 2>/dev/null
+	    ${TOPDIR}/bin/tools/cpio -o -C512 -Hnewc -P >$@ 2>/dev/null
 
 ${BIN_DIR}/${ROOTFSSQUASHFS}: ${TARGET_DIR}
 	${STAGING_TOOLS}/bin/mksquashfs ${TARGET_DIR} \

+ 6 - 1
mk/package.mk

@@ -117,6 +117,11 @@ patch: ${_PATCH_COOKIE}
 configure: ${_CONFIGURE_COOKIE}
 build: ${_BUILD_COOKIE}
 fake: ${_FAKE_COOKIE}
+rebuild:
+	@if [ -f ${TOPDIR}/.rebuild.${PKG_NAME} ];then \
+		$(MAKE) clean; \
+		rm -f ${TOPDIR}/.rebuild.${PKG_NAME}; \
+	fi
 
 # our recursive build entry point
 build-all-pkgs: ${_IPKGS_COOKIE}
@@ -220,7 +225,7 @@ endif
 	    find usr ! -type d 2>/dev/null | \
 	    grep -v -e '^usr/share' -e '^usr/man' -e '^usr/info' -e '^usr/lib/libc.so' | \
 	    tee '$${STAGING_PARENT}/pkg/$(1)' | \
-	    cpio -padlmu '$${STAGING_DIR}'
+	    $(TOPDIR)/bin/tools/cpio -padlmu '$${STAGING_DIR}'
 	@cd '$${STAGING_DIR}'; grep 'usr/lib/.*\.la$$$$' \
 	    '$${STAGING_PARENT}/pkg/$(1)' | while read fn; do \
 		chmod u+w $$$$fn; \

+ 1 - 1
mk/pkg-bottom.mk

@@ -165,7 +165,7 @@ endif
 	    find usr ! -type d 2>/dev/null | \
 	    grep -v -e '^usr/share' -e '^usr/man' -e '^usr/info' -e '^usr/lib/libc.so' | \
 	    tee '${STAGING_PARENT}/pkg/${PKG_NAME}' | \
-	    cpio -padlmu '${STAGING_DIR}'
+	    $(TOPDIR)/bin/tools/cpio -padlmu '${STAGING_DIR}'
 	@cd '${STAGING_DIR}'; grep 'usr/lib/.*\.la$$' \
 	    '${STAGING_PARENT}/pkg/${PKG_NAME}' | while read fn; do \
 		chmod u+w $$fn; \

+ 2 - 2
mk/vars.mk

@@ -102,7 +102,7 @@ EXTRACT_CMD=		mkdir -p ${WRKDIR}; \
 			cd ${WRKDIR} && \
 			for file in ${FULLDISTFILES}; do case $$file in \
 			*.cpio) \
-				cat $$file | $(STAGING_TOOLS)/bin/cpio -i -d ;; \
+				cat $$file | $(TOPDIR)/bin/tools/cpio -i -d ;; \
 			*.tar) \
 				tar -xf $$file ;; \
 			*.cpio.Z | *.cpio.gz | *.cgz | *.mcz) \
@@ -114,7 +114,7 @@ EXTRACT_CMD=		mkdir -p ${WRKDIR}; \
 			*.tar.bz2 | *.tbz | *.tbz2) \
 				bzip2 -dc $$file | tar -xf - ;; \
 			*.zip) \
-				cat $$file | $(STAGING_TOOLS)/bin/cpio -ivd -H zip ;; \
+				cat $$file | $(TOPDIR)/bin/tools/cpio -ivd -H zip ;; \
 			*.arm) \
 				cp $$file ${WRKDIR} ;; \
 			*) \

+ 9 - 2
package/Makefile

@@ -28,6 +28,7 @@ endif
 include $(TOPDIR)/package/Depends.mk
 
 DOWNLOAD:=$(patsubst %,%-download,$(package-y) $(package-m))
+REBUILD_PACKAGES:=$(patsubst %,%-rebuild,$(package-y) $(package-m))
 COMPILE_PACKAGES:=$(patsubst %,%-compile,$(package-y) $(package-m))
 INSTALL_PACKAGES:=$(patsubst %,%-install,$(package-y))
 
@@ -35,10 +36,10 @@ all: compile
 download: $(DOWNLOAD)
 clean: $(patsubst %,%-clean,$(package-) $(package-y) $(package-m) base-files)
 ifeq ($(ADK_TOOLCHAIN_ONLY),y)
-compile: $(COMPILE_PACKAGES)
+compile: $(REBUILD_PACKAGES) $(COMPILE_PACKAGES)
 install: $(INSTALL_PACKAGES)
 else
-compile: base-files-compile $(COMPILE_PACKAGES)
+compile: base-files-compile $(REBUILD_PACKAGES) $(COMPILE_PACKAGES)
 install: base-files-install $(INSTALL_PACKAGES)
 endif
 
@@ -57,6 +58,12 @@ $(TARGET_DIR):
 	$(CMD_TRACE) " done"
 	$(END_TRACE)
 
+%-rebuild:
+	$(START_TRACE) "package/$(patsubst %-rebuild,%,$@)-rebuild: "
+	$(MAKE) -C $(patsubst %-rebuild,%,$@) rebuild
+	$(CMD_TRACE) " done"
+	$(END_TRACE)
+
 %-install:
 	@$(START_TRACE) "package/$(patsubst %-install,%,$@)-install: "
 	@$(MAKE) -C $(patsubst %-install,%,$@) install

+ 0 - 8
package/base-files/Makefile

@@ -77,12 +77,4 @@ ifneq (${ADK_PACKAGE_CONFIG_IN_ETC},)
 	chmod 600 $(IDIR_BASE_FILES)/etc/adkconfig.gz
 endif
 
-rebuild:
-	@if [ -f ${TOPDIR}/.rebuild.${PKG_NAME} ];then \
-		rm ${WRKBUILD}/.build_done; \
-		rm ${TOPDIR}/.rebuild.${PKG_NAME}; \
-	fi
-
-fake: rebuild
-
 include ${TOPDIR}/mk/pkg-bottom.mk

+ 0 - 8
package/busybox/Makefile

@@ -82,12 +82,4 @@ udhcpd-install:
 	${INSTALL_DIR} ${IDIR_UDHCPD}/etc/
 	${INSTALL_DATA} ./files/udhcpd.conf ${IDIR_UDHCPD}/etc/
 
-rebuild:
-	@if [ -f ${TOPDIR}/.rebuild.${PKG_NAME} ];then \
-		rm ${WRKBUILD}/.build_done; \
-		rm ${TOPDIR}/.rebuild.${PKG_NAME}; \
-	fi
-
-fake: rebuild
-
 include ${TOPDIR}/mk/pkg-bottom.mk

+ 4 - 1
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

+ 234 - 0
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);
+}

+ 3 - 3
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

+ 1 - 1
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);

+ 3 - 3
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