3 # A tool to simplify Makefiles that need to put something
6 # Copyright (C) David McCullough, 2002,2003
8 #############################################################################
10 # Provide a default PATH setting to avoid potential problems...
11 PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:$PATH"
16 $0: [options] [src] dst
17 -v : output actions performed.
18 -V : output actions not performed.
19 -e env-var : only take action if env-var is set to "y".
20 -E env-var : only take action if env-var is not set to "y".
21 -o option : only take action if option is set to "y".
22 -O option : only take action if option is not set to "y".
23 -c : process with cpp+cflags
24 -p perms : chmod style permissions for dst.
25 -d : make dst directory if it doesn't exist
26 -S : don't strip after installing
27 -a text : append text to dst.
28 -A pattern : only append text if pattern doesn't exist in file
29 -l link : dst is a hard link to 'link'.
30 -s sym-link : dst is a sym-link to 'sym-link'.
31 -M : install kernel module into dst subdir of module dir
32 -r : root directory of install (default ROMFSDIR)
34 -f : do not follow symlinks
36 if "src" is not provided, basename is run on dst to determine the
37 source in the current directory.
39 multiple -e and -o options are ANDed together. To achieve an OR affect
40 use a single -e/-o with 1 or more y/n/"" chars in the condition.
42 if src is a directory, everything in it is copied recursively to dst
43 with special files removed (currently CVS and Subversion dirs).
48 #############################################################################
53 # Always start with write access for the user so that files can be
54 # updated/overwritten during make romfs
55 chmod u+w ${ROMFSDIR}${dst}
58 [ "$v" ] && echo "chmod ${perm} ${ROMFSDIR}${dst}"
59 chmod ${perm} ${ROMFSDIR}${dst}
65 #############################################################################
72 [ "$v" ] && echo "CopyDir ${src} ${ROMFSDIR}${dst}"
77 find . -print | grep -E -v '/CVS|/\.svn' | cpio --quiet -p${VV}dum${follow} ${ROMFSDIR}${dst}
79 # And make sure these files are still writable
80 find . -print | grep -E -v '/CVS|/\.svn' | ( cd ${ROMFSDIR}${dst}; xargs chmod u+w )
81 setperm ${ROMFSDIR}${dst}
82 find . -type f | grep -E -v '/CVS|/\.svn|\.ko$' | while read t; do
83 if [ -n "$strip" ]; then
84 ${STRIPTOOL} ${ROMFSDIR}${dst}/$t 2>/dev/null
85 ${STRIPTOOL} -R .comment -R .note ${ROMFSDIR}${dst}/$t 2>/dev/null
90 if [ -d ${ROMFSDIR}${dst} ]; then
91 dstfile=${ROMFSDIR}${dst}/`basename ${src}`
93 dstfile=${ROMFSDIR}${dst}
96 [ "$v" ] && echo "cp ${src} ${dstfile}"
97 if [ ! -d "$IMAGEDIR" ]
102 /*) echo "${src} ${dstfile}" ;;
103 *) echo "`pwd`/${src} ${dstfile}" ;;
104 esac >> $IMAGEDIR/romfs-inst.log
105 cp ${src} ${dstfile} && setperm ${dstfile}
107 if [ $rc -eq 0 -a -n "$strip" ]; then
108 ${STRIPTOOL} ${dstfile} 2>/dev/null
109 ${STRIPTOOL} -R .comment -R .note ${dstfile} 2>/dev/null
115 #############################################################################
119 touch ${ROMFSDIR}${dst} || return 1
120 if [ -z "${pattern}" ] && grep -F "${src}" ${ROMFSDIR}${dst} > /dev/null
122 [ "$V" ] && echo "File entry already installed."
123 elif [ "${pattern}" ] && egrep "${pattern}" ${ROMFSDIR}${dst} > /dev/null
125 [ "$V" ] && echo "File pattern already installed."
127 [ "$v" ] && echo "Installing entry into ${ROMFSDIR}${dst}."
128 if [ -s ${ROMFSDIR}${dst} ] ; then
129 # if file lacks a trailing new line, add it before appending the text
130 if [ $(tail -n1 ${ROMFSDIR}${dst} | tr -d '\n' | wc -c) = $(tail -n1 ${ROMFSDIR}${dst} | wc -c) ] ; then
131 echo "" >> ${ROMFSDIR}${dst} || return 1
134 echo "${src}" >> ${ROMFSDIR}${dst} || return 1
136 setperm ${ROMFSDIR}${dst}
140 #############################################################################
144 rm -f ${ROMFSDIR}${dst}
145 [ "$v" ] && echo "ln ${src} ${ROMFSDIR}${dst}"
146 ln ${ROMFSDIR}${src} ${ROMFSDIR}${dst}
150 #############################################################################
154 rm -f ${ROMFSDIR}${dst}
155 [ "$v" ] && echo "ln -s ${src} ${ROMFSDIR}${dst}"
156 ln -sf ${src} ${ROMFSDIR}${dst}
160 #############################################################################
165 if [ -d ${ROMFSDIR}${dst} ]; then
166 dstfile=${ROMFSDIR}${dst}/`basename ${src}`
168 dstfile=${ROMFSDIR}${dst}
171 [ "$v" ] && echo "${CROSS_COMPILE}cpp ${CFLAGS} -P < ${src} > ${dstfile}"
172 ${CROSS_COMPILE}cpp ${CFLAGS} -P < ${src} > ${dstfile}
176 #############################################################################
180 # if ROMFSDIR is not set, play it safe
181 [ "${ROMFSDIR}" ] || return 1
182 if [ -d "${ROMFSDIR}${dst}" ]; then
183 echo "rm -rf ${ROMFSDIR}${dst}"
184 rm -rf "${ROMFSDIR}${dst}"
186 echo "rm -f ${ROMFSDIR}${dst}"
187 rm -f "${ROMFSDIR}${dst}"
192 #############################################################################
194 # main program entry point
212 while getopts 'VdRfSMvce:E:o:O:A:p:a:l:s:r:' opt "$@"
221 o) option="$OPTARG"; ;;
222 O) noption="$OPTARG"; ;;
223 e) eval option=\"\$$OPTARG\"; ;;
224 E) eval noption=\"\$$OPTARG\"; ;;
225 p) perm="$OPTARG"; ;;
226 a) src="$OPTARG"; func=file_append; ;;
227 A) pattern="$OPTARG"; ;;
228 l) src="$OPTARG"; func=hard_link; ;;
229 s) src="$OPTARG"; func=sym_link; ;;
230 r) ROMFSDIR="$OPTARG"; r=1; ;;
237 # process option here to get an ANDing effect
240 *[mMyY]*) # this gives OR effect, ie., nYn
243 [ "$V" ] && echo "Condition not satisfied."
249 # process negative options here to get an ANDing effect
251 case "${noption:-n}" in
252 *[nN]*) # this gives OR effect, ie., yNy
255 [ "$V" ] && echo "Condition not satisfied."
261 if [ -z "$ROMFSDIR" -a -z "$r" ]
263 echo "ROMFSDIR is not set" >&2
268 if [ -z "$STRIPTOOL" ]
273 shift `expr $OPTIND - 1`
280 src="`basename $dst`"
286 echo "Source file already provided" >&2
297 if [ -n "$kernmod" ]; then
299 kerndir=${ROOTDIR}/${LINUXDIR}
300 # could prob take from UTS headers as well ...
301 kernver=$(cat ${kerndir}/include/config/kernel.release)
302 dst="/lib/modules/${kernver}/${dst}"
305 if [ "$mdir" -a ! -d "`dirname ${ROMFSDIR}${dst}`/." ]
307 mkdir -p "`dirname ${ROMFSDIR}${dst}`/." || exit 1
314 #############################################################################