forked from gtri/scrimmage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-plugin.sh
executable file
·118 lines (98 loc) · 3.76 KB
/
generate-plugin.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
#
# @file
#
# @section LICENSE
#
# Copyright (C) 2017 by the Georgia Tech Research Institute (GTRI)
#
# This file is part of SCRIMMAGE.
#
# SCRIMMAGE is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# SCRIMMAGE is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with SCRIMMAGE. If not, see <http://www.gnu.org/licenses/>.
#
# @author Kevin DeMarco <[email protected]>
# @author Eric Squires <[email protected]>
# @date 31 July 2017
# @version 0.1.0
# @brief Brief file description.
# @section DESCRIPTION
# A Long description goes here.
#
usage()
{
cat << EOF
USAGE:
$0 <PluginType> <PluginName> <ProjectDirectory>
OPTIONS:
-h Display this usage information
NOTES:
PluginType must be one of the following:
autonomy, motion, interaction, controller, metrics, sensor, network
EOF
}
if [ "$#" -lt 3 ]; then
usage
exit 2
fi
PLUGIN_TYPE="$1"
PLUGIN_NAME="$2"
PROJECT_DIR="$(readlink -f $3)"
if [ $PLUGIN_TYPE != "autonomy" ] && [ $PLUGIN_TYPE != "motion" ] && \
[ $PLUGIN_TYPE != "interaction" ] && [ $PLUGIN_TYPE != "controller" ] && \
[ $PLUGIN_TYPE != "metrics" ] && [ $PLUGIN_TYPE != "sensor" ] && \
[ $PLUGIN_TYPE != "network" ]; then
echo "Invalid plugin type."
echo "PluginType must be \"autonomy\", \"motion\", \"controller\", "
echo "\"metrics\", \"sensor\", \"network\", or \"interaction\""
exit 2
fi
if [ ! -d "$PROJECT_DIR" ];
then
echo "ProjectDirectory doesn't exist."
exit 1
fi
PROJECT_DIR=$(readlink -f "${PROJECT_DIR}")
PROJECT_NAME=$(basename "${PROJECT_DIR}")
HEADER_GUARD="INCLUDE_${PROJECT_NAME}_PLUGINS_${PLUGIN_TYPE}_${PLUGIN_NAME}_${PLUGIN_NAME}_H_"
HEADER_GUARD=$(echo $HEADER_GUARD | awk '{print toupper($0)}') # to uppercase
HEADER_GUARD=$(echo $HEADER_GUARD | tr - _) # replace - with _
# Jump to the directory that holds this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd ${DIR} >& /dev/null
###############################################################################
# Use the plugin template to generate the plugin
###############################################################################
H_FILE_IN=$(readlink -f ./templates/$PLUGIN_TYPE/PluginTemplate.h)
CPP_FILE_IN=$(readlink -f ./templates/$PLUGIN_TYPE/PluginTemplate.cpp)
XML_FILE_IN=$(readlink -f ./templates/$PLUGIN_TYPE/PluginTemplate.xml)
CMAKE_FILE_IN=$(readlink -f ./templates/$PLUGIN_TYPE/CMakeLists.txt)
OUT_SRC_DIR="${PROJECT_DIR}/src/plugins/${PLUGIN_TYPE}/${PLUGIN_NAME}"
OUT_H_DIR="${PROJECT_DIR}/include/${PROJECT_NAME}/plugins/${PLUGIN_TYPE}/${PLUGIN_NAME}"
mkdir -p ${OUT_SRC_DIR}
mkdir -p ${OUT_H_DIR}
H_FILE_OUT="${OUT_H_DIR}/$PLUGIN_NAME.h"
CPP_FILE_OUT="${OUT_SRC_DIR}/$PLUGIN_NAME.cpp"
XML_FILE_OUT="${OUT_H_DIR}/$PLUGIN_NAME.xml"
CMAKE_FILE_OUT="${OUT_SRC_DIR}/CMakeLists.txt"
cp $H_FILE_IN $H_FILE_OUT
cp $CPP_FILE_IN $CPP_FILE_OUT
cp $XML_FILE_IN $XML_FILE_OUT
cp $CMAKE_FILE_IN $CMAKE_FILE_OUT
sed -i -- "s/(>>>PLUGIN_NAME<<<)/$PLUGIN_NAME/g" $H_FILE_OUT
sed -i -- "s/(>>>HEADER_GUARD<<<)/$HEADER_GUARD/g" $H_FILE_OUT
sed -i -- "s/(>>>PLUGIN_NAME<<<)/$PLUGIN_NAME/g" $XML_FILE_OUT
sed -i -- "s/(>>>PLUGIN_NAME<<<)/$PLUGIN_NAME/g" $CMAKE_FILE_OUT
sed -i -- "s/(>>>PLUGIN_NAME<<<)/$PLUGIN_NAME/g" $CPP_FILE_OUT
sed -i -- "s/(>>>PROJECT_NAME<<<)/$PROJECT_NAME/g" $CPP_FILE_OUT
pushd >& /dev/null