Skip to content

Instantly share code, notes, and snippets.

@jmc734
Last active August 31, 2015 17:43
Show Gist options
  • Save jmc734/20f8467d1cecf1a78d52 to your computer and use it in GitHub Desktop.
Save jmc734/20f8467d1cecf1a78d52 to your computer and use it in GitHub Desktop.
Compute a checksum (using cksum) for each object file in an archive
# For each library,
# 1) Print the name of each object files it contains
# 2) Sort those object file names
# 3) For each object file name
# a) Print the object file from the library to standard out
# b) Compute the checksum
# c) Append the object file name
# 4) Write all of that to a file (e.g. libExample.a.dir for a library libExample.a)
find . -type f -name "*.a" -print -exec sh -c "ar t {} | sort | while read in; do ar p {} \$in | cksum | echo \"\$(cat -) \$in\"; done > {}.dir" \;
# You could then run the same command against the archives you would like to compare with and write to .dir.new files instead
find . -type f -name "*.a" -print -exec sh -c "ar t {} | sort | while read in; do ar p {} \$in | cksum | echo \"\$(cat -) \$in\"; done > {}.dir.new" \;
# Then comparing those two sets of .dir* files is as easy as the following
find . -type f -name "*.a.dir" -print -exec sh -c "diff {} {}.new > {}.diff" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment