sdk: track files with git and use it to implement proper clean targets
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 10 Jan 2015 11:17:02 +0000 (11:17 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 10 Jan 2015 11:17:02 +0000 (11:17 +0000)
Initialize a Git repository in the SDK and use git reset / git clean
to rollback any SDK changes with "make clean" or "make dirclean".

This approach is more robust than nuking entire directory trees because
some parts of them might have been shipped with the original archive.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
SVN-Revision: 43904

include/toplevel.mk
target/sdk/files/Makefile

index 8a21f7eef4b6d6a2432551a603f2a04698ac38c6..f623e03118f925bc979def1b39a8d16aed43667a 100644 (file)
@@ -135,7 +135,7 @@ kernel_menuconfig: prepare_kernel_conf
 kernel_nconfig: prepare_kernel_conf
        $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
 
-tmp/.prereq-build: include/prereq-build.mk
+tmp/.prereq-build: $(if $(SDK),.git/config) include/prereq-build.mk
        mkdir -p tmp
        rm -f tmp/.host.mk
        @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
index 0c27f1a47308bc5d41d37560bc23e7833810bcb5..01c1e1c788352af23ff65a2ae1e74ba8ec6f787c 100644 (file)
@@ -14,6 +14,16 @@ export TOPDIR LC_ALL LANG SDK
 
 world:
 
+# Initialize SDK snapshot
+.git/config:
+       @( \
+               echo -n "Initializing SDK ... "; \
+               git init -q .; \
+               find . -mindepth 1 -maxdepth 1 -not -name feeds | xargs git add; \
+               git commit -q -m "Initial state"; \
+               echo "ok."; \
+       )
+
 include $(TOPDIR)/include/host.mk
 
 ifneq ($(OPENWRT_BUILD),1)
@@ -36,14 +46,17 @@ else
 $(package/stamp-compile): $(BUILD_DIR)/.prepared
 $(BUILD_DIR)/.prepared: Makefile
        @mkdir -p $$(dirname $@)
-       @mkdir -p bin/packages
        @touch $@
 
 clean: FORCE
-       rm -rf $(BUILD_DIR) $(BIN_DIR)
+       git clean -f -d $(STAGING_DIR); true
+       git clean -f -d $(BUILD_DIR); true
+       git clean -f -d $(BIN_DIR); true
 
 dirclean: clean
-       rm -rf $(TMP_DIR)
+       git reset --hard HEAD
+       git clean -f -d
+       rm -rf feeds/
 
 # check prerequisites before starting to build
 prereq: $(package/stamp-prereq) ;