-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
plugin_builder.pl
executable file
·176 lines (155 loc) · 6.92 KB
/
plugin_builder.pl
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/perl
#####################################################
# A script to automate creation of a new QGIS plugin
# using the plugin_template
# Authors GSherman TSutton
# Feb 21, 2004
#####################################################
# $Id$ #
# get the needed information from the user
print "\n\nEnter the directory name under qgis/src/plugins/ where your new plugin will be created.\n";
print "We suggest using a lowercase underscore separated name e.g. clever_plugin\n";
print "Directory for the new plugin:";
$pluginDir =<STDIN>;
chop $pluginDir;
print "\n\nEnter the name that will be used when creating the plugin library.\n";
print "The name should be entered as a mixed case name with no spaces. e.g. CleverTool\n";
print "The plugin name will be used in the following ways:\n";
print "1) it will be 'lower cased' and used as the root of the generated lib name \n";
print " e.g. libqgis_plugin_clevertool\n";
print "2) in its upper cased form it will be used as the basis for class names, in particular\n";
print " CleverToolGuiBase <- The base class for the plugins configuration dialog / gui generated by uic\n";
print " CleverToolGui <- The concrete class for the plugins configuration dialog\n";
print "3) CleverTool <- The class that includes the plugin loader instructions and\n";
print " and calls to your custom application logic\n";
print "4) clevertool.h, clevertool.cpp etc. <- the filenames used to hold the above derived classes\n";
print "Plugin name: " ;
$pluginName = <STDIN>;
chop $pluginName;
$pluginLCaseName = lc($pluginName); #todo convert to lower case
print "\n\nEnter a short description (typically one line)\n";
print "e.g. The clever plugin does clever stuff in QGIS\n";
print "Plugin description: " ;
$pluginDescription = <STDIN>;
chop $pluginDescription;
print "\n\n Enter the name of the application menu that will be created for your plugin\n";
print "Clever Tools\n";
print "Menu name: ";
$menuName = <STDIN>;
chop $menuName;
print "\n\n Enter the name of the menu entry (under the menu that you have just defined) that\n";
print "will be used to invoke your plugin. e.g. Clever Plugin\n";
print "Menu item name: ";
$menuItemName = <STDIN>;
chop $menuItemName;
# print a summary of what's about to happen
print << "EOF";
Summary of plugin parameters:
---------------------------------------------
Plugin directory $pluginDir
Name of the plugin: $pluginName
Library name of the plugin: libqgis_plugin_$pluginLCaseName
Description of the plugin: $pluginDescription
Menu name: $menuName
Menu item name: $menuItemName
Warning - Proceeding will make changes to Makefile.am in this directory,
as well as ../../configure.in. Please use caution.
EOF
# ask if we should proceed
print "Create the plugin? [y/n]: ";
$createIt = <STDIN>;
chop $createIt;
if(($createIt eq 'y') || ($createIt eq 'Y')){
#
# its a go -- create the plugin and modify the build files
#
# create the new plugin directory
system("cp -r plugin_template $pluginDir");
# remove the README file
system("rm -rf $pluginDir/README");
# remove the subversion directory
system("rm -rf $pluginDir/.svn");
# copy files to appropriate names
system("cp $pluginDir/plugin.cpp $pluginDir/$pluginLCaseName.cpp");
system("cp $pluginDir/plugin.h $pluginDir/$pluginLCaseName.h");
#todo sort out copying these next items properly
system("cp $pluginDir/pluginbase.cpp $pluginDir/$pluginLCaseName.cpp");
system("cp $pluginDir/plugin.cpp $pluginDir/$pluginLCaseName.cpp");
# Substitute the plugin specific vars in the various files
# This is a brute force approach but its quick and dirty :)
#
# replace [pluginlcasename] in template with the new plugin name
system("perl -pi -e 's/\\\[pluginlcasename\\\]/$pluginLCaseName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am $pluginDir/*.ui");
# replace [pluginname] in template with the new plugin name
system("perl -pi -e 's/\\\[pluginname\\\]/$pluginName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am $pluginDir/*.ui");
# replace [plugindescription] in template with the description
system("perl -pi -e 's/\\\[plugindescription\\\]/$pluginDescription/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
# replace [menuname] in the template with the menu name
system("perl -pi -e 's/\\\[menuname\\\]/$menuName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
# replace [menuitemname] in the template with the menu item name
system("perl -pi -e 's/\\\[menuitemname\\\]/$menuItemName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
# Add an entry to qgis/plugins/Makefile.am
# We won't add it the EXTRA_DIST since we don't want to necesarily distribute
# third party plugins
open MAKEFILE, "<./Makefile.am" || die 'Unable to open Makefile.am';
open MAKEFILEMOD, ">./Makefile.am.mod" || die 'Unable to create Makefile.am.mod';
# read through Makefile.am and write each line to Makefile.am.mod
while(<MAKEFILE>){
if(/^\s*SUBDIRS =*/){
# add our plugin dir to the next line after SUBDIRS line
print MAKEFILEMOD;
print MAKEFILEMOD "\t\t$pluginDir \\\n";
}else{
print MAKEFILEMOD;
}
}
# close the Makefile file handles
close MAKEFILEMOD;
close MAKEFILE;
# save Makefile.am in case we die before done moving things around
system("mv Makefile.am Makefile.am.save");
# move the new Makefile.am to where it belongs
system("mv Makefile.am.mod Makefile.am");
# delete the original Makefile.am
unlink("Makefile.am.save");
# Add an entry to qgis/configure.in
# Do we really want to do this or add a message telling the user how to do
# it?
open CONFIGUREIN, "<../../configure.in" || die 'Unable to open ../../configure.in';
open CONFIGUREINMOD, ">../../configure.in.mod" || die 'Unable to create ../../configure.in.mod';
# read through configure.in until we find the AC_CONFIG_FILES section
while(<CONFIGUREIN>){
if(/^\s*AC_CONFIG_FILES*/){
# set the flag so we can look for the closing ])
$inConfigFile = 1;
print CONFIGUREINMOD;
}else{
if($inConfigFile){
if(/^\s*\]\)*/){
# write our entry
print CONFIGUREINMOD "\tplugins/$pluginDir/Makefile\n";
$inConfigFile = 0;
}
}
print CONFIGUREINMOD;
}
}
close CONFIGUREIN;
close CONFIGUREINMOD;
# save configure.in in case we die before done moving things around
system("mv ../../configure.in ../../configure.in.save");
# move the new configure.in to where it belongs
system("mv ../../configure.in.mod ../../configure.in");
# delete the original configure.in
unlink("../../configure.in.save");
# print out some end of processing info
print << "EOP";
Your plugin ($pluginName) has been created in $pluginDir.
Makefile.am and configure.in have been modified.
To build the plugin, you must change to the top level of the source tree and
run autoreconf, configure, then make.
EOP
}else{
# user cancelled
print "Plugin not created\n";
}