From c900dde5d1ae890414d728b04c8fbddb3e2238c4 Mon Sep 17 00:00:00 2001 From: mazze Date: Mon, 14 Oct 2013 01:34:56 +0000 Subject: [PATCH] Implemented %copy_dir_recursive with a Python script so that we can copy file names with space characters. git-svn-id: https://svn.aros.org/svn/aros/trunk@48287 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- AROS/config/make.cfg.in | 3 ++- AROS/config/make.tmpl | 30 +++++---------------- AROS/scripts/cpy-dir-rec.py | 65 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 25 deletions(-) create mode 100755 AROS/scripts/cpy-dir-rec.py diff --git a/AROS/config/make.cfg.in b/AROS/config/make.cfg.in index 2cdaf59..6c69346 100644 --- a/AROS/config/make.cfg.in +++ b/AROS/config/make.cfg.in @@ -105,7 +105,8 @@ SCRIPTDIR := $(GENDIR)/scripts MKDEPEND := $(SRCDIR)/scripts/mkdep FETCH := $(SRCDIR)/scripts/fetch.sh - +CPYDIRREC := @PYTHON@ $(SRCDIR)/scripts/cpy-dir-rec.py + # The paths to the generated tools TOOLDIR := $(HOSTDIR)/tools TOOLLIB := $(TOOLDIR)/libtool.a diff --git a/AROS/config/make.tmpl b/AROS/config/make.tmpl index 1e04504..f6d0d0e 100644 --- a/AROS/config/make.tmpl +++ b/AROS/config/make.tmpl @@ -2429,37 +2429,19 @@ GLOB_MKDIRS += %(dst) # Copy a directory recursively to another place, preserving the original # hierarchical structure # -# src: the source directory whose content will be copied -# dst: the directory where to copy src's content. If not existing, it will be made. +# src: the source directory whose content will be copied. +# dst: the directories where to copy src's content. If not existing, they will be made. +# excludefiles: files which must not be copied. Path must be relative to src. %define copy_dir_recursive mmake=/A src=. dst=/A excludefiles= -%(mmake)_SRC := $(shell echo %(src) | sed 's/^\(.\):\//\/\1\//') -%(mmake)_FILES := $(shell cd $(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)); find . -path '*/CVS' -prune -o -path '*/.svn' -prune -o -name .cvsignore -prune -o -name mmakefile -prune -o -name mmakefile.src -prune $(%(mmake)_FILTER) -o -type f -print) -%(mmake)_DIRS := $(sort $(dir $(%(mmake)_FILES))) - -%(mmake)_EXCLUDEFILES := $(addprefix ./,%(excludefiles)) -%(mmake)_FILES := $(filter-out $(%(mmake)_EXCLUDEFILES),$(%(mmake)_FILES)) - -GLOB_MKDIRS += $(GENDIR)/$(CURDIR) +%(mmake)_EXCLUDEFILES := %(excludefiles) .PHONY : %(mmake) #MM -%(mmake): | $(GENDIR)/$(CURDIR) - @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \ - $(ECHO) "all: $(addprefix \$$(DST)/,$(%(mmake)_FILES))" > $$m - @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \ - for d in $(%(mmake)_DIRS); do \ - $(ECHO) "\$$(DST)/$$d: ; $(MKDIR) \$$@" >> $$m; \ - done - @m="$(GENDIR)/$(CURDIR)/%(mmake)-auxiliary.mak"; \ - for f in $(%(mmake)_FILES); do \ - $(ECHO) "\$$(DST)/$$f: \$$(SRC)/$$f | \$$(dir \$$(DST)/$$f); $(CP) \$$< \$$@" >> $$m; \ - done; \ - for dst in %(dst); do \ - $(MAKE) -f $$m DST=$$dst SRC=$(if $(filter /%,$(%(mmake)_SRC)),$(%(mmake)_SRC),$(SRCDIR)/$(CURDIR)/$(%(mmake)_SRC)) all; \ - done +%(mmake) : + @cd $(SRCDIR)/$(CURDIR) && $(CPYDIRREC) -s %(src) -d %(dst) -e $(%(mmake)_EXCLUDEFILES) %end #------------------------------------------------------------------------------ diff --git a/AROS/scripts/cpy-dir-rec.py b/AROS/scripts/cpy-dir-rec.py new file mode 100755 index 0000000..3b4d45b --- /dev/null +++ b/AROS/scripts/cpy-dir-rec.py @@ -0,0 +1,65 @@ +# -*- coding: iso-8859-1 -*- +# Copyright © 2013, The AROS Development Team. All rights reserved. + +# Copy directory 'src' recursively to 'dst' while ignoring +# all files given by 'ignore' parameter. Only files younger +# than those in 'dst' are copied. + +# The files '.cvsignore', 'mmakefile.src' and the directories +# 'CVS', '.svn' are ignored. + +# This is a support script for the %copy_dir_recursive macro +# in make.tmpl. Main purpose is to fix problem with file names +# which contain space characters. + +import sys, os, shutil + +def copy_tree(src, dst, ignore): + names = os.listdir(src) + + if not os.path.exists(dst): + os.makedirs(dst) + + for name in names: + srcname = os.path.join(src, name) + dstname = os.path.join(dst, name) + + if os.path.isdir(srcname): + if name not in ("CVS", ".svn"): + # print "Copying dir %s to %s" % (srcname, dstname) + copy_tree(srcname, dstname, ignore) + else: + if (name not in (".cvsignore", "mmakefile.src")) and (srcname not in ignore): + if not os.path.exists(dstname) or (os.path.getctime(srcname) > os.path.getctime(dstname)): + # print "Copying file %s to %s" % (srcname, dstname) + shutil.copy(srcname, dstname) + +################################################################################ + +st_source = 1 +st_dest = 2 +st_exclude = 3 +state = 0 + +sourcedir = "." +destdirs = [] +ignore = [] + +for arg in sys.argv: + if arg == "-s": + state = st_source + elif arg == "-d": + state = st_dest + elif arg == "-e": + state = st_exclude + else: + if state == st_source: + sourcedir = arg + elif state == st_dest: + destdirs.append(arg) + elif state == st_exclude: + ignore.append(arg) + +for destdir in destdirs: + print "Copying directory '%s' to '%s', ignore '%s'" % (sourcedir, destdir, ignore) + copy_tree(sourcedir, destdir, ignore) -- 2.1.4