mkproject.sh 1.9 KB

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