From 6dc74faf96f6e5caea3985d3c986e2c5655b4178 Mon Sep 17 00:00:00 2001 From: fherrero <fherrero@iri.upc.edu> Date: Wed, 13 May 2020 12:40:21 +0200 Subject: [PATCH] Add usage text. Check name has no whitespaces. Do not create bin and lib directories. Add CMakeLists plural variables _DIRS, _LIBRARIES, add gitlab-ci.yml file. --- new_project.sh | 164 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 116 insertions(+), 48 deletions(-) diff --git a/new_project.sh b/new_project.sh index 017be3c..84fadb0 100755 --- a/new_project.sh +++ b/new_project.sh @@ -6,6 +6,18 @@ PROJECT_DESC= NAME= TEST=0 +# usage="Usage: +# \tnew_project.sh -t <library/application> -n project_name -p \"project description\" [-d dependency1,dependency2,dependency3][-g] +# Parameters: +# \t-d: comma separated dependencies (optional). +# \t-g: include test structure (optional)." + +usage="Usage: +\tnew_project.sh -t <library/application> -n project_name -p \"project description\" [-d dependency1,dependency2,dependency3] +Parameters: +\t-d: comma separated dependencies (optional)." +##\t-g: include test structure (optional). + while getopts “t:p:n:d:g†OPTION do case $OPTION in @@ -25,7 +37,8 @@ do TEST=1 ;; ?) - echo invalid argument $OPTION + echo "ERROR: invalid argument: $OPTION" + echo "${usage}" exit ;; esac @@ -36,46 +49,58 @@ case $TYPE in ;; library) echo Generating a library project ... ;; - *) echo Unknown project type "$TYPE" - exit + *) echo "ERROR: unknown project type: $TYPE" + echo "${usage}" + exit ;; esac if [ "$NAME" ] then - echo "Generating folder structure for project $NAME ..." + case $NAME in + *\ * ) + echo "ERROR: project name cannot have whitespaces, aborting..." + exit + ;; + *) + echo "Generating folder structure for project $NAME ..." + NAME=$(echo $NAME | tr '[:upper:]' '[:lower:]') + echo "Using library name $NAME ..." + ;; + esac else - echo "No project name provided, aborting ..." + echo "ERROR: No project name provided, aborting..." + echo "${usage}" exit fi -if [ $NAME ] +if [ ! "$PROJECT_DESC" ] then - NAME=$(echo $NAME | tr '[:upper:]' '[:lower:]') - echo "Using library name $NAME ..." -else - echo "No library name provided, aborting ..." + echo "ERROR: No project description provided, aborting..." + echo "${usage}" exit fi -#create the bin directory -BIN_DIR="./bin" -if [ -e "$BIN_DIR" ] -then - echo "$BIN_DIR directory already exists, skipping ..." -else - echo "Creating $BIN_DIR directory" - mkdir $BIN_DIR -fi -# create the lib directory -LIB_DIR="./lib" -if [ -e "$LIB_DIR" ] -then - echo "$LIB_DIR directory already exists, skipping ..." -else - echo "Creating $LIB_DIR directory" - mkdir $LIB_DIR -fi +# #create the bin directory +# BIN_DIR="./bin" +# if [ -e "$BIN_DIR" ] +# then +# echo "$BIN_DIR directory already exists, skipping ..." +# else +# echo "Creating $BIN_DIR directory" +# mkdir $BIN_DIR +# fi + +# # create the lib directory +# LIB_DIR="./lib" +# if [ -e "$LIB_DIR" ] +# then +# echo "$LIB_DIR directory already exists, skipping ..." +# else +# echo "Creating $LIB_DIR directory" +# mkdir $LIB_DIR +# fi + # create the src directory SRC_DIR="./src" if [ -e "$SRC_DIR" ] @@ -147,30 +172,38 @@ fi #parse the dependencies and create the dependencies file arr=$(echo $DEP | tr "," "\n") +NAME_WITH_DASHES=$(echo $NAME | sed 's/_/-/g') + #Set the author's email on the ReadMe.md disclaimer file sed 's/author_email/labrobotica@iri.upc.edu/g' <ReadMe_template.md >tmp1.md #set the author's name on the ReadMe.txt disclaimer file -sed 's/author_name/IRI labrobotics/g' <tmp1.md >tmp2.md +sed 's/author_name/IRI labrobotica/g' <tmp1.md >tmp2.md #Set the project name on the ReadMe.txt disclaimer file sed 's/project_description/'"$PROJECT_DESC"'/g' <tmp2.md >tmp3.md -sed 's/project_name/'"$NAME"'/g' <tmp3.md >./ReadMe.md +sed 's/project_name/'"$NAME"'/g' <tmp3.md >tmp4.md +sed 's/project-name/'"$NAME_WITH_DASHES"'/g' <tmp4.md >./ReadMe.md + +for x in $arr +do + DEP_LINE=" - $x" + sed -i '/^This package also requires of the following dependencies:/a'"${DEP_LINE}" ./ReadMe.md +done + rm tmp1.md rm tmp2.md rm tmp3.md +rm tmp4.md rm ReadMe_template.md -#Set the project name on the CMakeLists.txt script file -#NEW_NAME=$(echo $NAME | sed 's/_/-/g') -NEW_NAME=$NAME -NEW_NAME_WITH_DASHES=$(echo $NAME | sed 's/_/-/g') if [ $TEST = 1 ] then - sed 's/project_name/'$NEW_NAME'/g' <CMakeLists_test_template.txt >./CMakeLists.txt + sed 's/project_name/'$NAME'/g' <CMakeLists_test_template.txt >./CMakeLists.txt else - sed 's/project_name/'$NEW_NAME'/g' <CMakeLists_template.txt >./temp1.txt - sed 's/project-name/'$NEW_NAME_WITH_DASHES'/g' <temp1.txt >./CMakeLists.txt + sed 's/project_name/'$NAME'/g' <CMakeLists_template.txt >temp1.txt + sed 's/project-name/'$NAME_WITH_DASHES'/g' <temp1.txt >./CMakeLists.txt + rm temp1.txt fi -rm temp1.txt + rm CMakeLists_test_template.txt rm CMakeLists_template.txt @@ -188,69 +221,104 @@ then do echo "FIND_PACKAGE($x REQUIRED)" >> CMakeLists.tmp done + echo "" >> CMakeLists.tmp + echo "# add the necessary include directories" >> CMakeLists.tmp echo "INCLUDE_DIRECTORIES(../include)" >> CMakeLists.tmp for x in $arr do - echo "INCLUDE_DIRECTORIES("'${'"${x}_INCLUDE_DIR"'}'")" >> CMakeLists.tmp + echo "INCLUDE_DIRECTORIES("'${'"${x}_INCLUDE_DIRS"'}'")" >> CMakeLists.tmp done + echo "" >> CMakeLists.tmp + echo "# application source files" >> CMakeLists.tmp echo "SET(sources ${PROJECT_NAME_VAR}.cpp)" >> CMakeLists.tmp + echo "" >> CMakeLists.tmp + echo "# application header files" >> CMakeLists.tmp echo "SET(headers ../include/${PROJECT_NAME_VAR}.h)" >> CMakeLists.tmp + echo "" >> CMakeLists.tmp + echo "# create the executable file" >> CMakeLists.tmp echo "ADD_EXECUTABLE(${PROJECT_NAME_VAR} "'${'"sources"'}'")" >> CMakeLists.tmp + echo "" >> CMakeLists.tmp + echo "# link necessary libraries" >> CMakeLists.tmp echo "#TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} \${my_example_library_LIBRARIES})">>CMakeLists.tmp for x in $arr do - echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} "'${'"${x}_LIBRARY"'}'")" >> CMakeLists.tmp + echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} "'${'"${x}_LIBRARIES"'}'")" >> CMakeLists.tmp done + echo "" >> CMakeLists.tmp + echo "#ADD_DEPENDENCIES(${PROJECT_NAME_VAR} my_example_library_target)">>CMakeLists.tmp mv CMakeLists.tmp ./src/CMakeLists.txt mv application_src_template.cpp ./src/$NAME.cpp else echo "# driver source files" >> CMakeLists.tmp echo "SET(sources ${PROJECT_NAME_VAR}.cpp)" >> CMakeLists.tmp + echo "" >> CMakeLists.tmp + echo "# application header files" >> CMakeLists.tmp echo "SET(headers ../include/${PROJECT_NAME_VAR}.h)" >> CMakeLists.tmp + echo "" >> CMakeLists.tmp + echo "# locate the necessary dependencies" >> CMakeLists.tmp for x in $arr do echo "FIND_PACKAGE($x REQUIRED)" >> CMakeLists.tmp done + echo "" >> CMakeLists.tmp + echo "# add the necessary include directories" >> CMakeLists.tmp echo "INCLUDE_DIRECTORIES(../include)" >> CMakeLists.tmp for x in $arr do - echo "INCLUDE_DIRECTORIES("'${'"${x}_INCLUDE_DIR"'}'")" >> CMakeLists.tmp + echo "INCLUDE_DIRECTORIES("'${'"${x}_INCLUDE_DIRS"'}'")" >> CMakeLists.tmp done + echo "" >> CMakeLists.tmp + echo "# create the shared library" >> CMakeLists.tmp echo "ADD_LIBRARY(${PROJECT_NAME_VAR} SHARED "'${'"sources"'}'")" >> CMakeLists.tmp + echo "" >> CMakeLists.tmp + echo "# link necessary libraries" >> CMakeLists.tmp echo "#TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} \${my_example_library_LIBRARIES})">>CMakeLists.tmp for x in $arr do - echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} "'${'"${x}_LIBRARY"'}'")" >> CMakeLists.tmp + echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR} "'${'"${x}_LIBRARIES"'}'")" >> CMakeLists.tmp done + echo "" >> CMakeLists.tmp + echo "#ADD_DEPENDENCIES(${PROJECT_NAME_VAR} my_example_library_target)">>CMakeLists.tmp + echo "" >> CMakeLists.tmp + echo "INSTALL(TARGETS $PROJECT_NAME_VAR" >> CMakeLists.tmp echo " RUNTIME DESTINATION bin" >> CMakeLists.tmp echo " LIBRARY DESTINATION lib/iri/${PROJECT_NAME_VAR}" >> CMakeLists.tmp echo " ARCHIVE DESTINATION lib/iri/${PROJECT_NAME_VAR})" >> CMakeLists.tmp echo "INSTALL(FILES "'${'"headers"'}' "DESTINATION include/iri/${PROJECT_NAME_VAR})" >> CMakeLists.tmp echo "INSTALL(FILES ../Find$PROJECT_NAME_VAR.cmake DESTINATION "'${'"CMAKE_ROOT"'}'"/Modules/)" >> CMakeLists.tmp + echo "" >> CMakeLists.tmp + + echo "#Install script files if needed" >> CMakeLists.tmp + echo "#INSTALL(FILES ../scripts/<script_name> " >> CMakeLists.tmp + echo "# DESTINATION share/iri" >> CMakeLists.tmp + echo "# PERMISSIONS OWNER_EXECUTE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)" >> CMakeLists.tmp + echo "" >> CMakeLists.tmp + echo "ADD_SUBDIRECTORY(examples)" >> CMakeLists.tmp + mv CMakeLists.tmp ./src/CMakeLists.txt echo "# create an example application" >> CMakeLists.tmp echo "ADD_EXECUTABLE(${PROJECT_NAME_VAR}_test ${PROJECT_NAME_VAR}_test.cpp)" >> CMakeLists.tmp echo "# link necessary libraries" >> CMakeLists.tmp echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR}_test $PROJECT_NAME_VAR)" >> CMakeLists.tmp - for x in $arr - do - echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR}_test "'${'"${x}_LIBRARY"'}'")" >> CMakeLists.tmp - done + # for x in $arr + # do + # echo "TARGET_LINK_LIBRARIES(${PROJECT_NAME_VAR}_test "'${'"${x}_LIBRARY"'}'")" >> CMakeLists.tmp + # done mv CMakeLists.tmp ./src/examples/CMakeLists.txt sed 's/library_name/'$NAME'/g' <Findlib_template.cmake >./Find$NAME.cmake @@ -271,12 +339,12 @@ else rm application_src_template.cpp fi -sed 's/library-name/'$NEW_NAME_WITH_DASHES'/g' <.gitlab-ci_template.yml >./.gitlab-ci.yml +sed 's/library-name/'$NAME_WITH_DASHES'/g' <.gitlab-ci_template.yml >./.gitlab-ci.yml if [ $TEST = 1 ] then Library_name=$(echo $NAME | sed 's/\([a-zA-Z]\)\([a-zA-Z0-9]*\)/\u\1\2/g') - sed 's/library_name/'$NEW_NAME'/g' <./test/CMakeLists_template.txt >./test/tmp.txt + sed 's/library_name/'$NAME'/g' <./test/CMakeLists_template.txt >./test/tmp.txt sed 's/Library_name/'$Library_name'/g' <./test/tmp.txt >./test/CMakeLists.txt rm ./test/CMakeLists_template.txt rm ./test/tmp.txt -- GitLab