autoexplicit.sh 1.9 KB

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