nat: use correct data types for memory sizes
[vpp.git] / build-root / copyimg
1 #!/bin/sh
2
3 # Copyright (c) 2015 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17 if [ $# -lt 2 ]; then
18     cat - <<EOF
19 $0 FROM-DIR TO-DIR ENVIRONMENT
20
21 Copies files from one directory to another with possible
22 transformations.
23
24 Files named FILE.spp will be transformed via the spp preprocessor
25 subject to environment definitions.  Source FILE.copyimgspp results in
26 destination file FILE in the corresponding destination directory.
27
28 Files named FILE.copyimgsh are run as shell scripts in (i.e. via chdir)
29 the corresponding destination directory (and not copied).
30
31 First regular files are copied.  Then transformations are preformed.
32 Finally, shell scripts are run.
33 EOF
34   exit 1;
35 fi
36
37 FROM_DIR=$1
38 TO_DIR=$2
39
40 FILTER=" -and -not -name '*~'";
41 FILTER="${FILTER} -and -not -name '.*~'";
42 FILTER="$FILTER -and -not -path '*/.git*'";
43 FILTER="$FILTER -and -not -path '*/.svn*'";
44 FILTER="$FILTER -and -not -path '*/.CVS*'";
45
46 FROM_FILES=`(cd $FROM_DIR; eval "find . -not -type d $FILTER")`;
47  FROM_DIRS=`(cd $FROM_DIR; eval "find .      -type d $FILTER")`;
48
49 COPY_FILES=
50 SPP_FILES=
51 SH_FILES=
52 for f in $FROM_FILES; do
53   case $f in
54     *.copyimgspp) SPP_FILES="$SPP_FILES $f" ;;
55     *.copyimgsh)   SH_FILES="$SH_FILES $f" ;;
56     *)           COPY_FILES="$COPY_FILES $f";;
57   esac
58 done
59
60 # Make destination directories.
61 mkdir -p $TO_DIR;
62 if [ "$FROM_DIRS" != "" ]; then
63   for d in $FROM_DIRS; do
64     mkdir -p $TO_DIR/$d;
65   done
66 fi
67
68 # Copy files
69 if [ "$COPY_FILES" != "" ]; then
70     tar -cf - -C $FROM_DIR $COPY_FILES | tar --preserve-permissions -xf - -C $TO_DIR;
71 fi
72
73 # Use spp to transform any spp files
74 if [ "$SPP_FILES" != "" ]; then
75   for f in $SPP_FILES; do
76     d=`dirname $f`;
77     b=`basename $f .copyimgspp`;
78     mkdir -p $TO_DIR/$d;
79     t=$TO_DIR/$d/$b;
80     spp -o $TO_DIR/$d/$b $FROM_DIR/$f || exit 1;
81   done;
82 fi
83
84 # Now that all files have been copied/created we run any shell scripts
85 ABS_FROM_DIR=`(cd $FROM_DIR; pwd)`;
86 if [ "$SH_FILES" != "" ]; then
87   # Allow directory to define some functions
88   if [ -f $FROM_DIR/copyimgsh-functions.sh ]; then
89     . $FROM_DIR/copyimgsh-functions.sh ;
90   fi ;
91   for f in $SH_FILES; do
92     d=`dirname $f`;
93     b=`basename $f`;
94     mkdir -p $TO_DIR/$d;
95     (cd $TO_DIR/$d; . $ABS_FROM_DIR/$d/$b) || exit 1;
96   done;
97 fi;