mkproject.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # there is a better version of this somewhere
  3. here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
  4. echo "we are here <$here>"
  5. sed_files=( _build.c _build.inc.c build.sh debug.sh profiling.sh valgrind.sh )
  6. code_file="test.c"
  7. dest_name_code=""
  8. dest_name_exe=""
  9. dest_path_build="build"
  10. dest_path_exe="./"
  11. dest_path_root=""
  12. dest_path_source="src"
  13. while getopts ":b:c:e:r:s:x:" opt; do
  14. case $opt in
  15. b)
  16. dest_path_build="$OPTARG"
  17. ;;
  18. c)
  19. dest_name_code="$OPTARG"
  20. ;;
  21. e)
  22. dest_path_exe="$OPTARG"
  23. ;;
  24. r)
  25. dest_path_root="$OPTARG"
  26. ;;
  27. s)
  28. dest_path_source="$OPTARG"
  29. ;;
  30. x)
  31. dest_name_exe="$OPTARG"
  32. ;;
  33. \?)
  34. echo "Invalid option: -$OPTARG"
  35. exit 1
  36. ;;
  37. :)
  38. echo "Option -$OPTARG requires an argument"
  39. exit 1
  40. ;;
  41. esac
  42. done
  43. shift $((OPTIND-1))
  44. if [ "$dest_path_root" = "" ] ; then
  45. if [ "$1" != "" ] ; then
  46. dest_path_root="$1"
  47. else
  48. echo "Missing destination root path of project"
  49. exit 2
  50. fi
  51. fi
  52. if [ "$dest_name_code" = "" ] ; then
  53. if [ "$dest_name_exe" != "" ] ; then
  54. dest_name_code="$dest_name_exe.c"
  55. else
  56. dest_name_code=code_file
  57. fi
  58. fi
  59. if [ "$dest_name_exe" = "" ] ; then
  60. dest_name_exe="hworld"
  61. fi
  62. mkdir -p "$dest_path_root/$dest_path_source"
  63. cp "$here/$code_file" "$dest_path_root/$dest_path_source/$dest_name_code"
  64. mkdir -p "$dest_path_root/$dest_path_build"
  65. for f in "${sed_files[@]}"; do
  66. cp "$here/$f" "$dest_path_root/$f"
  67. done
  68. sed -i -E -e "s;__SED_TOKEN_EXE_NAME;$dest_name_exe;" "${sed_files[@]}"
  69. sed -i -E -e "s;__SED_TOKEN_EXE_PATH;$dest_path_exe;" "${sed_files[@]}"
  70. sed -i -E -e "s;__SED_TOKEN_BUILD_PATH;$dest_path_build;" "${sed_files[@]}"
  71. sed -i -E -e "s;__SED_TOKEN_SOURCE_PATH;$dest_path_source;" "${sed_files[@]}"
  72. sed -i -E -e "s;__SED_TOKEN_CODE_NAME;$dest_name_code;" "${sed_files[@]}"
  73. echo "._build" >> "$dest_path_root/.gitignore"
  74. echo $( realpath --relative-to="$dest_path_root" "$dest_path_exe/$dest_name_exe" ) >> "$dest_path_root/.gitignore"
  75. echo "$dest_path_build/*" >> "$dest_path_root/.gitignore"