Makefile for packaging an extension

From MozillaZine Knowledge Base
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

here is my proposal for a Makefile

after you set the variables run

make -f Makefile.mozextention 

or rename it to Makefile and just run

make

This will create the directory structures and files for project reffered by variable PROJECT.

If you run

make -f Makefile.mozextention package 

or

make package

than you'll have a XPI package under PROJECT

copy paste the script into file called Makefile.mozextention

it should work under windows too with a proper make utility

have fun

and here is the file itself

## This Makefile.mozextention is for the test extension 
PROJECT=test
PROJECT_NAME=TestWorld
MKDIR=/bin/mkdir
ZIPPROG=/usr/bin/zip
SHELL = /bin/sh
NOOP = $(SHELL) -c true
NOECHO = @
RM_RF=rm -f
CP=/bin/cp -i


.PHONY: all 


all ::  make_structure make_files 
	$(NOECHO) $(NOOP)

package:: make_xpi
	$(NOECHO) $(NOOP)
	
#install :: make_xpi make_install
#	$(NOECHO) $(NOOP)

clean :: make_clean clean_all
	$(NOECHO) $(NOOP)

make_structure: 
	$(MKDIR) $(PROJECT)
	$(MKDIR) $(PROJECT)/content $(PROJECT)/locale $(PROJECT)/locale/en-us $(PROJECT)/components/ $(PROJECT)/defaults/ $(PROJECT)/defaults/preferences/ $(PROJECT)/locale/de-de $(PROJECT)/skin
	
make_xpi:
	$(MKDIR) $(PROJECT)/chrome && \
	cd $(PROJECT) && \
	$(ZIPPROG)  -r  chrome/$(PROJECT).jar content locale skin && \
	$(ZIPPROG)  -r  $(PROJECT).xpi chrome.manifest install.rdf components defaults chrome && cd ..

make_files:	
	# make chrome.manifest
	echo "content	$(PROJECT) content/ " > $(PROJECT)/chrome.manifest
	echo "overlay	chrome://browser/content/browser.xul 	chrome://$(PROJECT)/content/overlay.xul" >> $(PROJECT)/chrome.manifest
	echo "" >> $(PROJECT)/chrome.manifest
	echo "locale	$(PROJECT)	en-US	locale/en-US/" >> $(PROJECT)/chrome.manifest
	echo "" >> $(PROJECT)/chrome.manifest
	echo "skin	$(PROJECT)	classic/1.0	skin/" >> $(PROJECT)/chrome.manifest
	echo "style	chrome://global/content/customizeToolbar.xul	chrome://$(PROJECT)/skin/overlay.css" >> $(PROJECT)/chrome.manifest
	echo "" >> $(PROJECT)/chrome.manifest
	
	# make  overlay.xul
	echo '<?xml version="1.0"?>' > $(PROJECT)/content/overlay.xul
	echo '<?xml-stylesheet href="chrome://$(PROJECT)/skin/overlay.css" type="text/css"?>' >> $(PROJECT)/content/overlay.xul
	echo '<!DOCTYPE overlay SYSTEM "chrome://$(PROJECT)/locale/overlay.dtd">' >> $(PROJECT)/content/overlay.xul
	echo '<overlay id="$(PROJECT)-overlay"       xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">' >> $(PROJECT)/content/overlay.xul
	echo '<script src="overlay.js"/>' >> $(PROJECT)/content/overlay.xul
	echo '' >> $(PROJECT)/content/overlay.xul
	echo '	<menupopup id="menu_ToolsPopup">' >> $(PROJECT)/content/overlay.xul
	echo '		<menuitem id="$(PROJECT)-extention" label="&$(PROJECT);"         oncommand="$(PROJECT).onMenuItemCommand(event);"/>' >> $(PROJECT)/content/overlay.xul
	echo '	</menupopup>' >> $(PROJECT)/content/overlay.xul
	echo '</overlay>' >> $(PROJECT)/content/overlay.xul
	echo '' >> $(PROJECT)/content/overlay.xul

	# make overlay.js
	echo 'var $(PROJECT_NAME) = { ' > $(PROJECT)/content/overlay.js
	echo '  onLoad: function() { ' >> $(PROJECT)/content/overlay.js
	echo '    // initialization code ' >> $(PROJECT)/content/overlay.js
	echo '    this.initialized = true; ' >> $(PROJECT)/content/overlay.js
	echo '  }, ' >> $(PROJECT)/content/overlay.js
	echo ' ' >> $(PROJECT)/content/overlay.js
	echo '  onMenuItemCommand: function() { ' >> $(PROJECT)/content/overlay.js
	echo '    if(this.initialized) ' >> $(PROJECT)/content/overlay.js
	echo '      alert("Hi!"); ' >> $(PROJECT)/content/overlay.js
	echo '  } ' >> $(PROJECT)/content/overlay.js
	echo '}; ' >> $(PROJECT)/content/overlay.js
	echo ' ' >> $(PROJECT)/content/overlay.js
	echo 'window.addEventListener("load", function(e) { $(PROJECT_NAME).onLoad(e); }, false);  ' >> $(PROJECT)/content/overlay.js
	echo ' ' >> $(PROJECT)/content/overlay.js

	# make overlay.dtd
	echo ' ' >> $(PROJECT)/locale/en-us/overlay.dtd
	echo ' <!ENTITY $(PROJECT) "$(PROJECT_NAME)">' >> $(PROJECT)/locale/en-us/overlay.dtd
	echo ' ' >> $(PROJECT)/locale/en-us/overlay.dtd
	
	# make install.rdf
	#Firefox 	{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
	#Thunderbird 	{3550f703-e582-4d05-9a08-453d09bdfdc6}
	#Nvu 	{136c295a-4a5a-41cf-bf24-5cee526720d5}
	#Mozilla Suite 	{86c18b42-e466-45a9-ae7a-9b95ba6f5640}
	#SeaMonkey 	{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
	#Sunbird 	{718e30fb-e89b-41dd-9da7-e25a45638b28}
	#Netscape Browser	{3db10fab-e461-4c80-8b97-957ad5f8ea47}
	echo ' ' > $(PROJECT)/install.rdf
	echo ' <?xml version="1.0"?> ' >> $(PROJECT)/install.rdf
	echo ' <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"     xmlns:em="http://www.mozilla.org/2004/em-rdf#"> ' >> $(PROJECT)/install.rdf
	echo ' ' >> $(PROJECT)/install.rdf
	echo ' <Description about="urn:mozilla:install-manifest">' >> $(PROJECT)/install.rdf
	echo ' ' >> $(PROJECT)/install.rdf
	echo ' 	<em:id>{XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}</em:id>' >> $(PROJECT)/install.rdf
	echo ' 	<em:name>$(PROJECT_NAME)</em:name>' >> $(PROJECT)/install.rdf
	echo ' 	<em:version>1.0</em:version>' >> $(PROJECT)/install.rdf
	echo ' 	<em:description>A $(PROJECT_NAME) project  with advanced features</em:description>' >> $(PROJECT)/install.rdf
	echo ' 	<em:creator>Emanoil Kotsev</em:creator>' >> $(PROJECT)/install.rdf
	echo ' 	<!-- optional items -->' >> $(PROJECT)/install.rdf
	echo ' 	<em:contributor>Here is a place for you who helped me</em:contributor>' >> $(PROJECT)/install.rdf
	echo ' 	<!-- <em:contributor>Another one</em:contributor> -->' >> $(PROJECT)/install.rdf
	echo ' 	<em:homepageURL>http://$(PROJECT).mozdev.org/</em:homepageURL>' >> $(PROJECT)/install.rdf
	echo ' 	<em:optionsURL>chrome://$(PROJECT)/content/settings.xul</em:optionsURL>' >> $(PROJECT)/install.rdf
	echo ' 	<em:aboutURL>chrome://$(PROJECT)/content/about.xul</em:aboutURL>' >> $(PROJECT)/install.rdf
	echo ' 	<em:iconURL>chrome://$(PROJECT)/skin/mainicon.png</em:iconURL>' >> $(PROJECT)/install.rdf
	echo '	<em:updateURL>http://$(PROJECT).mozdev.org/update.rdf</em:updateURL>' >> $(PROJECT)/install.rdf
	echo ' 	<em:type>2</em:type> <!-- type=extension --> ' >> $(PROJECT)/install.rdf
	echo ' ' >> $(PROJECT)/install.rdf
	echo '        <!-- Firefox -->' >> $(PROJECT)/install.rdf
	echo ' 	<em:targetApplication>' >> $(PROJECT)/install.rdf
	echo ' 		<Description>' >> $(PROJECT)/install.rdf
	echo ' 			<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>' >> $(PROJECT)/install.rdf
	echo ' 			<em:minVersion>0.9</em:minVersion>' >> $(PROJECT)/install.rdf
	echo ' 			<em:maxVersion>1.0</em:maxVersion>' >> $(PROJECT)/install.rdf
	echo ' 		</Description>' >> $(PROJECT)/install.rdf
	echo ' 	</em:targetApplication>' >> $(PROJECT)/install.rdf
	echo ' ' >> $(PROJECT)/install.rdf
	echo '        <!-- This is not needed for Firefox 1.1 and later. Only include this ' >> $(PROJECT)/install.rdf
	echo '              if you want to make your extension compatible with older versions -->' >> $(PROJECT)/install.rdf
	echo ' 	<em:file>' >> $(PROJECT)/install.rdf
	echo ' 		<Description about="urn:mozilla:extension:file:sampleext.jar">' >> $(PROJECT)/install.rdf
	echo ' 			<em:package>content/</em:package>' >> $(PROJECT)/install.rdf
	echo ' 			<!-- optional items -->' >> $(PROJECT)/install.rdf
	echo ' 			<em:skin>skin/classic/</em:skin>' >> $(PROJECT)/install.rdf
	echo ' 			<em:locale>locale/en-US/</em:locale>' >> $(PROJECT)/install.rdf
	echo ' 			<em:locale>locale/ru-RU/</em:locale>' >> $(PROJECT)/install.rdf
	echo ' 		</Description>' >> $(PROJECT)/install.rdf
	echo ' 	</em:file>' >> $(PROJECT)/install.rdf
	echo ' </Description>' >> $(PROJECT)/install.rdf
	echo ' ' >> $(PROJECT)/install.rdf
	echo ' </RDF>' >> $(PROJECT)/install.rdf
	echo ' ' >> $(PROJECT)/install.rdf
	
make_clean:
	rm -rf $(PROJECT)

real_install:
	$(CP) chrome/$(PROJECT).jar ~/.mozilla/default/32p27fdr.slt/chrome/

temporary it's avialable for download here

Makefile.mozextention