autoexplicit.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. while getopts ":C:h" opt; do
  3. case $opt in
  4. C)
  5. if ! cd "$OPTARG" 2>/dev/null
  6. then
  7. (>&2 echo "Failed to change directory to $OPTARG")
  8. exit 1
  9. fi
  10. ;;
  11. h)
  12. echo "
  13. Usage:
  14. autoexplicit.sh [-C dir] \"
  15. Undefined symbols for architecture x86_64:
  16. \\\"...\\\" \"
  17. Or
  18. make -C [your_project] 2>&1 | autoexplicit.sh -C \$LIBIGL"
  19. exit 1
  20. ;;
  21. \?)
  22. echo "Invalid option: -$OPTARG" >&2
  23. ;;
  24. esac
  25. done
  26. # Shift so that $# makes sense
  27. shift $((OPTIND-1))
  28. # process input line by line
  29. while read line; do
  30. if ! echo "$line" | grep -q "^\".*\", referenced from:$"
  31. then
  32. # undefined symbol line not found
  33. continue
  34. fi
  35. symbol=`echo "$line" | sed -e "s/^\"\(.*\)\", referenced from:$/\1/"`
  36. #echo "symbol = $symbol"
  37. filename=`echo "$symbol" | perl -pe "s#.*?igl::([A-z0-9_:]*).*$'$'#\1#"`
  38. filename=`echo "$filename" | sed -e "s/::/\//g"`
  39. #echo "filename = $filename"
  40. cpp="$LIBIGL/include/igl/$filename.cpp"
  41. # append .cpp and check that file exists
  42. if [ ! -e "$cpp" ]
  43. then
  44. echo "Warning: $cpp does not exist, skipping ..."
  45. continue
  46. fi
  47. if ! grep -q "^\/\/ Explicit template instantiation*$" "$cpp"
  48. then
  49. echo "Warning: skipping $cpp because it does not match ^\/\/ Explicit template instantiation*$ "
  50. continue;
  51. fi
  52. before=`sed '/^\/\/ Explicit template instantiation$/q' "$cpp"`;
  53. #echo "before = $before"
  54. after=`sed '1,/^\/\/ Explicit template instantiation$/d' $cpp`;
  55. #echo "after = $after"
  56. explicit=`echo "template $symbol;" | sed -e "s/std::__1::/std::/g"`
  57. #echo "$explicit"
  58. if grep -F "$explicit" "$cpp"
  59. then
  60. echo "Error: $cpp already contains $explicit"
  61. echo " Recompile igl static lib, recompile your project, and try again."
  62. continue
  63. fi
  64. echo "$before" > "$cpp"
  65. echo "// generated by autoexplicit.sh" >> "$cpp"
  66. echo "$explicit" >> "$cpp"
  67. echo "$after" >> "$cpp"
  68. done