net: wimax: i2400m: control.c: Cleaning up conjunction always evaluates to false
[linux/fpc-iii.git] / scripts / objdiff
blobb3e4f10bfc3edac5a5119d31f432371f8e75feee
1 #!/bin/bash
3 # objdiff - a small script for validating that a commit or series of commits
4 # didn't change object code.
6 # Copyright 2014, Jason Cooper <jason@lakedaemon.net>
8 # Licensed under the terms of the GNU GPL version 2
10 # usage example:
12 # $ git checkout COMMIT_A
13 # $ <your fancy build command here>
14 # $ ./scripts/objdiff record path/to/*.o
16 # $ git checkout COMMIT_B
17 # $ <your fancy build command here>
18 # $ ./scripts/objdiff record path/to/*.o
20 # $ ./scripts/objdiff diff COMMIT_A COMMIT_B
21 # $
23 # And to clean up (everything is in .tmp_objdiff/*)
24 # $ ./scripts/objdiff clean all
26 # Note: 'make mrproper' will also remove .tmp_objdiff
28 GIT_DIR="`git rev-parse --git-dir`"
30 if [ -d "$GIT_DIR" ]; then
31 TMPD="${GIT_DIR%git}tmp_objdiff"
33 [ -d "$TMPD" ] || mkdir "$TMPD"
34 else
35 echo "ERROR: git directory not found."
36 exit 1
39 usage() {
40 echo "Usage: $0 <command> <args>"
41 echo " record <list of object files>"
42 echo " diff <commitA> <commitB>"
43 echo " clean all | <commit>"
44 exit 1
47 dorecord() {
48 [ $# -eq 0 ] && usage
50 FILES="$*"
52 CMT="`git rev-parse --short HEAD`"
54 OBJDUMP="${CROSS_COMPILE}objdump"
55 OBJDIFFD="$TMPD/$CMT"
57 [ ! -d "$OBJDIFFD" ] && mkdir -p "$OBJDIFFD"
59 for f in $FILES; do
60 dn="${f%/*}"
61 bn="${f##*/}"
63 [ ! -d "$OBJDIFFD/$dn" ] && mkdir -p "$OBJDIFFD/$dn"
65 # remove addresses for a more clear diff
66 # http://dummdida.tumblr.com/post/60924060451/binary-diff-between-libc-from-scientificlinux-and
67 $OBJDUMP -D "$f" | sed "s/^[[:space:]]\+[0-9a-f]\+//" \
68 >"$OBJDIFFD/$dn/$bn"
69 done
72 dodiff() {
73 [ $# -ne 2 ] && [ $# -ne 0 ] && usage
75 if [ $# -eq 0 ]; then
76 SRC="`git rev-parse --short HEAD^`"
77 DST="`git rev-parse --short HEAD`"
78 else
79 SRC="`git rev-parse --short $1`"
80 DST="`git rev-parse --short $2`"
83 DIFF="`which colordiff`"
85 if [ ${#DIFF} -eq 0 ] || [ ! -x "$DIFF" ]; then
86 DIFF="`which diff`"
89 SRCD="$TMPD/$SRC"
90 DSTD="$TMPD/$DST"
92 if [ ! -d "$SRCD" ]; then
93 echo "ERROR: $SRCD doesn't exist"
94 exit 1
97 if [ ! -d "$DSTD" ]; then
98 echo "ERROR: $DSTD doesn't exist"
99 exit 1
102 $DIFF -Nurd $SRCD $DSTD
105 doclean() {
106 [ $# -eq 0 ] && usage
107 [ $# -gt 1 ] && usage
109 if [ "x$1" = "xall" ]; then
110 rm -rf $TMPD/*
111 else
112 CMT="`git rev-parse --short $1`"
114 if [ -d "$TMPD/$CMT" ]; then
115 rm -rf $TMPD/$CMT
116 else
117 echo "$CMT not found"
122 [ $# -eq 0 ] && usage
124 case "$1" in
125 record)
126 shift
127 dorecord $*
129 diff)
130 shift
131 dodiff $*
133 clean)
134 shift
135 doclean $*
138 echo "Unrecognized command '$1'"
139 exit 1
141 esac