4
#####################################################
5
# A script to automate creation of a new QGIS plugin
6
# using the plugin_template
7
# Authors GSherman TSutton
9
#####################################################
10
# $Id: plugin_builder.pl 5212 2006-04-07 23:21:38Z timlinux $ #
12
#make sure we are in a the plugins directory otherwise the changes this script will make will
15
print "\n\nChecking that we are in the <qgis dir>/src/plugins/ directory....";
16
if ($myDir =~ m/src\/plugins$/) {
21
print "\nPlease relocate to the plugins directory before attempting to run this script.\n";
24
# get the needed information from the user
25
print "\n\nEnter the directory name under qgis/src/plugins/ where your new plugin will be created.\n";
26
print "We suggest using a lowercase underscore separated name e.g. clever_plugin\n";
27
print "Directory for the new plugin:";
31
print "\n\nEnter the name that will be used when creating the plugin library.\n";
32
print "The name should be entered as a mixed case name with no spaces. e.g. CleverTool\n";
33
print "The plugin name will be used in the following ways:\n";
34
print "1) it will be 'lower cased' and used as the root of the generated lib name \n";
35
print " e.g. libqgis_plugin_clevertool\n";
36
print "2) in its upper cased form it will be used as the basis for class names, in particular\n";
37
print " CleverToolGuiBase <- The base class for the plugins configuration dialog / gui generated by uic\n";
38
print " CleverToolGui <- The concrete class for the plugins configuration dialog\n";
39
print "3) CleverTool <- The class that includes the plugin loader instructions and\n";
40
print " and calls to your custom application logic\n";
41
print "4) clevertool.h, clevertool.cpp etc. <- the filenames used to hold the above derived classes\n";
42
print "Plugin name: " ;
43
$pluginName = <STDIN>;
45
$pluginLCaseName = lc($pluginName); #todo convert to lower case
47
print "\n\nEnter a short description (typically one line)\n";
48
print "e.g. The clever plugin does clever stuff in QGIS\n";
49
print "Plugin description: " ;
50
$pluginDescription = <STDIN>;
51
chop $pluginDescription;
53
print "\n\n Enter the name of the application menu that will be created for your plugin\n";
54
print "Clever Tools\n";
59
print "\n\n Enter the name of the menu entry (under the menu that you have just defined) that\n";
60
print "will be used to invoke your plugin. e.g. Clever Plugin\n";
61
print "Menu item name: ";
62
$menuItemName = <STDIN>;
65
# print a summary of what's about to happen
68
Summary of plugin parameters:
69
---------------------------------------------
70
Plugin directory $pluginDir
71
Name of the plugin: $pluginName
72
Library name of the plugin: libqgis_plugin_$pluginLCaseName
73
Description of the plugin: $pluginDescription
75
Menu item name: $menuItemName
77
Warning - Proceeding will make changes to Makefile.am in this directory,
78
as well as ../../configure.in. Please use caution.
80
# ask if we should proceed
81
print "Create the plugin? [y/n]: ";
85
if(($createIt eq 'y') || ($createIt eq 'Y')){
87
# its a go -- create the plugin and modify the build files
89
# create the new plugin directory
90
system("mkdir $pluginDir");
91
# copy files to appropriate names
92
system("cp plugin_template/Makefile.am $pluginDir/");
93
system("cp plugin_template/README.whatnext $pluginDir/README");
94
system("cp plugin_template/plugin.qrc $pluginDir/$pluginLCaseName.qrc");
95
system("cp plugin_template/plugin.png $pluginDir/$pluginLCaseName.png");
96
system("cp plugin_template/plugin.cpp $pluginDir/$pluginLCaseName.cpp");
97
system("cp plugin_template/plugin.h $pluginDir/$pluginLCaseName.h");
98
system("cp plugin_template/plugingui.cpp $pluginDir/${pluginLCaseName}gui.cpp");
99
system("cp plugin_template/plugingui.h $pluginDir/${pluginLCaseName}gui.h");
100
system("cp plugin_template/pluginguibase.ui $pluginDir/${pluginLCaseName}guibase.ui");
101
system("cp plugin_template/pluginguibase.ui.h $pluginDir/${pluginLCaseName}guibase.ui.h");
103
# Substitute the plugin specific vars in the various files
104
# This is a brute force approach but its quick and dirty :)
106
# replace [pluginlcasename] in template with the new plugin name
107
system("perl -pi -e 's/\\\[pluginlcasename\\\]/$pluginLCaseName/g' $pluginDir/*.qrc $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am $pluginDir/*.ui");
108
# replace [pluginname] in template with the new plugin name
109
system("perl -pi -e 's/\\\[pluginname\\\]/$pluginName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am $pluginDir/*.ui");
110
# replace [plugindescription] in template with the description
111
system("perl -pi -e 's/\\\[plugindescription\\\]/$pluginDescription/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
112
# replace [menuname] in the template with the menu name
113
system("perl -pi -e 's/\\\[menuname\\\]/$menuName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
114
# replace [menuitemname] in the template with the menu item name
115
system("perl -pi -e 's/\\\[menuitemname\\\]/$menuItemName/g' $pluginDir/*.cpp $pluginDir/*.h $pluginDir/*.am");
117
# Add an entry to qgis/plugins/Makefile.am
118
# We won't add it the EXTRA_DIST since we don't want to necesarily distribute
119
# third party plugins
120
open MAKEFILE, "<./Makefile.am" || die 'Unable to open Makefile.am';
121
open MAKEFILEMOD, ">./Makefile.am.mod" || die 'Unable to create Makefile.am.mod';
122
# read through Makefile.am and write each line to Makefile.am.mod
124
if(/^\s*SUBDIRS =*/){
125
# add our plugin dir to the next line after SUBDIRS line
127
print MAKEFILEMOD "\t\t$pluginDir \\\n";
132
# close the Makefile file handles
136
# save Makefile.am in case we die before done moving things around
137
system("mv Makefile.am Makefile.am.save");
138
# move the new Makefile.am to where it belongs
139
system("mv Makefile.am.mod Makefile.am");
140
# delete the original Makefile.am
141
unlink("Makefile.am.save");
143
# Add an entry to qgis/configure.in
144
# Do we really want to do this or add a message telling the user how to do
146
open CONFIGUREIN, "<../../configure.in" || die 'Unable to open ../../configure.in';
147
open CONFIGUREINMOD, ">../../configure.in.mod" || die 'Unable to create ../../configure.in.mod';
148
# read through configure.in until we find the AC_CONFIG_FILES section
149
while(<CONFIGUREIN>){
150
if(/^\s*AC_CONFIG_FILES*/){
151
# set the flag so we can look for the closing ])
153
print CONFIGUREINMOD;
159
print CONFIGUREINMOD "\tsrc/plugins/$pluginDir/Makefile\n";
163
print CONFIGUREINMOD;
167
close CONFIGUREINMOD;
169
# save configure.in in case we die before done moving things around
170
system("mv ../../configure.in ../../configure.in.save");
171
# move the new configure.in to where it belongs
172
system("mv ../../configure.in.mod ../../configure.in");
173
# delete the original configure.in
174
unlink("../../configure.in.save");
176
# print out some end of processing info
179
Your plugin ($pluginName) has been created in $pluginDir.
180
Makefile.am and configure.in have been modified.
181
To build the plugin, you must change to the top level of the source tree and
182
run autoreconf, configure, then make.
184
Once your plugin has successfully built, please see $pluginDir/README for
185
hints on how to get started.
191
print "Plugin not created\n";