-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_pkg.sh
More file actions
58 lines (47 loc) · 1.64 KB
/
Copy pathcreate_pkg.sh
File metadata and controls
58 lines (47 loc) · 1.64 KB
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
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $0 <folder_name>"
exit 1
fi
folder_name="$1"
folder_path="src/$folder_name"
source_cmake_dir="src/template"
source_cmake_file="$source_cmake_dir/CMakeLists.txt"
source_cc_file="$source_cmake_dir/template.cc"
source_h_file="$source_cmake_dir/template.h"
if [ ! -f "$source_cmake_file" ]; then
echo "Source CMakeLists.txt file does not exist: $source_cmake_file"
exit 1
fi
if [ ! -d "$folder_path" ]; then
mkdir -p "$folder_path"
echo "Created directory: $folder_path"
file_name=$(basename "$folder_name")
header_file="$folder_path/$file_name.h"
if [ -f "$source_h_file" ]; then
cp "$source_h_file" "$header_file"
echo "Copied $source_h_file to $header_file"
else
echo "Source .h file does not exist: $source_h_file"
exit 1
fi
source_file="$folder_path/$file_name.cc"
if [ -f "$source_cc_file" ]; then
cp "$source_cc_file" "$source_file"
echo "Copied $source_cc_file to $source_file"
include_line="#include \"$file_name.h\""
if ! grep -q "$include_line" "$source_file"; then
sed -i "/^#include/s/^/#include \"$file_name.h\"\n/" "$source_file"
echo "Added '#include \"$file_name.h\"' in $source_file"
else
echo "'#include \"$file_name.h\"' already exists in $source_file"
fi
else
echo "Source .cc file does not exist: $source_cc_file"
exit 1
fi
else
echo "Folder already exists: $folder_path"
fi
cp "$source_cmake_file" "$folder_path/CMakeLists.txt"
echo "CMakeLists.txt has been copied to the $folder_path directory"