-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreate-extension
executable file
·124 lines (97 loc) · 3.9 KB
/
create-extension
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
119
120
121
122
123
124
#!/usr/bin/perl
use Getopt::Long;
# Functions
sub replace {
my $file = shift;
my $old = shift;
my $new = shift;
#print "sed -i \"s/$old/$new/\" $file\n";
print `sed -i "s/$old/$new/g" $file`;
}
# Execution starts here
my $name;
my $fsharp;
GetOptions ("fsharp" => \$fsharp);
$name = $ARGV[0];
if (!$name || $name eq '') {
print "name: $name\n";
print "Usage: ./create-extension [--fsharp] EXTENSION_NAME\n\n";
print "Example: ./create-extension AlarmClock\n";
exit ();
}
if ($name !~ m/^[A-Z][a-zA-Z0-9]+$/) {
print "name should start with upper-case letter, and consist only of letters and numbers\n";
exit ();
}
my $dir = "src/$name";
if (-d $dir || -e $dir) {
print "$dir already exists; remove it or choose a new name\n";
exit ();
}
my $ext = "cs";
my $proj_type = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}";
if ($fsharp) {
$ext = "fs";
$proj_type = "{4925A630-B079-445d-BCD4-3A9C94FE9307}";
}
# TODO ensure the working copy of git is clean
print "Creating new extension: '$name'\n";
print ('=' x 80);
print "\n\n";
print `mkdir -p $dir`;
print `cp -R build/extension-templates/$ext/* $dir/`;
# Rename files appropriately
my $name_source = $name . 'Source';
print `mv $dir/Banshee.Template/TemplateSource.$ext $dir/Banshee.Template/$name_source.$ext`;
print `mv $dir/Banshee.Template/ $dir/Banshee.$name`;
print `mv $dir/Template.addin.xml $dir/$name.addin.xml`;
print `mv $dir/Template.${ext}proj $dir/$name.${ext}proj`;
# Replace the GUID
if (not -f "build/gen-guid.exe") {
`gmcs build/gen-guid.cs`;
}
my $guid = `mono build/gen-guid.exe`; chomp($guid); $guid = uc($guid);
replace ("$dir/$name.${ext}proj", "TEMPLATE-GUID", $guid);
# Replace the extension name
replace ("$dir/Makefile.am", "EXTENSION-NAME", $name);
replace ("$dir/$name.addin.xml", "EXTENSION-NAME", $name);
replace ("$dir/$name.${ext}proj", "EXTENSION-NAME", $name);
replace ("$dir/Banshee.$name/$name_source.${ext}", "EXTENSION-NAME", $name);
# Add to configure.ac
replace ("configure.ac", 'src\\/Makefile', 'src\\/Makefile\nsrc\\/' . $name. '\\/Makefile');
replace ("configure.ac", "Extensions:", 'Extensions:\n ' . $name . ':' . (' ' x (20 - length($name))) . "yes");
# Add to src/Makefile.am
my $subdirs = "SUBDIRS = \\\\\\";
replace ("src/Makefile.am", $subdirs, $subdirs . ' \n ' . $name . ' \\\\\\');
replace ("src/Makefile.am", " \$", "");
# Add to Extensions.sln
replace ("Extensions.sln", "Visual Studio 2010", 'Visual Studio 2010\n' .
'Project(\"' . $proj_type . '\") = \"' . $name . '\", \"src\\\\\\'. $name . '\\\\\\' . $name . '.' . $ext . 'proj\", \"{' . $guid . '}\"\nEndProject');
replace ("Extensions.sln", "postSolution", 'postSolution\n'.
"\t\t{$guid}.Debug|x86.ActiveCfg = Debug|Any CPU".'\n'.
"\t\t{$guid}.Debug|x86.Build.0 = Debug|Any CPU".'\n'.
"\t\t{$guid}.Release|x86.ActiveCfg = Release|Any CPU".'\n'.
"\t\t{$guid}.Release|x86.Build.0 = Release|Any CPU");
# Add everything to git, ready to commit
print `git add configure.ac src/Makefile.am Extensions.sln`;
print `git add $dir/`;
#print `git commit -m "[$name] Initial skeleton"`;
# run autogen.sh
print "Running ./autogen.sh\n";
`./autogen.sh` || die "Failed running ./autogen.sh - run it yourself to get the error";
# run make
print "Running make";
`make -s`;
print "\n\n";
print ("=" x 80);
print "\n";
print ("=" x 80);
print "\nYour extension has been created, and all the necessary files ready \n";
print "to commit to git:\n\n";
print `git status`;
print "\nYou can commit it now, or after you've started customizing it!\n";
print "\nYou can undo the creation of this extension, and revert to the last commit with\n";
print "git reset --hard HEAD\n";
print "\nYou can run Banshee with your newely created extension right now! Just run:\n";
print "make run\n";
print "\nNOTE: Do not forget to enable your extension within Preferences > Extensions\n";