build: rebuild idl if the pidl compiler is changed
[ddiss/samba.git] / librpc / build_idl.sh
index ac0fab48014073f3264ab8b289545c129b7e416c..23d7b3e329d4bc2a8ea7f1f827fd014691b68852 100755 (executable)
@@ -7,7 +7,7 @@ else
        FULL=0
 fi
 
-ARGS="--outputdir $PIDL_OUTPUTDIR --header --ndr-parser --samba3-ndr-server --samba3-ndr-client --server --client --python --dcom-proxy --com-header $PIDL_ARGS --"
+ARGS="--outputdir $PIDL_OUTPUTDIR --header --ndr-parser --samba3-ndr-server --server --client --python --dcom-proxy --com-header $PIDL_ARGS --"
 IDL_FILES="$*"
 
 oldpwd=`pwd`
@@ -15,30 +15,39 @@ cd ${srcdir}
 
 [ -d $PIDL_OUTPUTDIR ] || mkdir -p $PIDL_OUTPUTDIR || exit 1
 
-PIDL="$PIDL $ARGS"
+PIDL_CMD="$PIDL $ARGS"
 
 if [ $FULL = 1 ]; then
        echo "Rebuilding all idl files"
-       $PIDL $IDL_FILES || exit 1
+       $PIDL_CMD $IDL_FILES || exit 1
        exit 0
 fi
 
 ##
-## Find newer files rather than rebuild all of them
+## Find newer files rather than rebuild all of them. Also handle the case
+## where the pidl compiler itself is newer.
 ##
 
 list=""
 for f in ${IDL_FILES}; do
-       basename=`basename $f .idl`
-       ndr="$PIDL_OUTPUTDIR/py_$basename.c"
-
-       if [ -f $ndr ]; then
-               if [ "x`find $f -newer $ndr -print`" = "x$f" ]; then
-                       list="$list $f"
-               fi
-       else 
+        b=`basename $f .idl`
+       outfiles="$b.h ndr_${b}_c.c ndr_$b.h ndr_${b}_s.c srv_$b.c"
+       outfiles="$outfiles ndr_$b.c ndr_${b}_c.h py_$b.c srv_$b.h"
+
+       for o in $outfiles; do
+           [ -f $PIDL_OUTPUTDIR/$o ] || {
+               list="$list $f"
+               break
+           }
+           test "`find $f -newer $PIDL_OUTPUTDIR/$o`" != "" && {
+               list="$list $f"
+               break
+           }
+           test "`find $PIDL -newer $PIDL_OUTPUTDIR/$o`" != "" && {
                list="$list $f"
-       fi
+               break
+           }
+       done
 done
 
 ##
@@ -46,8 +55,8 @@ done
 ##
 
 if [ "x$list" != x ]; then
-       # echo "${PIDL} ${list}"
-       $PIDL $list || exit 1
+       # echo "${PIDL_CMD} ${list}"
+       $PIDL_CMD $list || exit 1
 fi
 
 cd ${oldpwd}