Makefile; mirroring a growing tree through a process

Posted by Martineau on Stack Overflow See other posts from Stack Overflow or by Martineau
Published on 2014-05-28T15:04:29Z Indexed on 2014/05/28 15:26 UTC
Read the original article Hit count: 234

Filed under:
|

I would like to periodically mirror a growing tree, say, from $in to $out, doing a process in between (saving the only file header). As;

#!/bin/bash
in=./segd
out=./db

for f in `find $in -name "*.segd"`;do 

    # Deduct output (dir + name)
    d=`dirname $f|perl -pe 's!'$in'!'$out'!'`
    n=`basename $f|perl -pe 's!$!_hdr!'`

    if [ ! -e $d/$n ]; then
        [ ! -d $d ] && mkdir -p $d;
        printf "From %s now build %s\n" $f "$d/$n" 
        # Do something, whathever. For example e.g;
        dd if=$f bs=32 count=1 conv=swab 2>/dev/null|od -x > $d/$n    
    fi

done

That is about fair. However; to be more robust, for a better synchronization (say if a source file did change or whatever), I would like to use a Makefile, as in;

HDR := $(patsubst ./segd/%.segd,./db/%.segd_hdr,$(wildcard ./segd/*.segd))

all: ${HDR}

db/%.segd_hdr: ./segd/%.segd
        echo "Doing"
        dd if=$< bs=32 count=1 conv=swab 2>/dev/null|od -x > $@ 

My problem; I cannot code this Makefile to "dive" more deeply within the source ./segd tree. How can we do it and is there a way ? Many thanks for your kind recommendations.

PS: The idea will be to later rsync the (smaller) destination tree over a sat connection.

© Stack Overflow or respective owner

Related posts about bash

Related posts about makefile