<NME> Makefile
<BEF> # Requirements to build:
#   rsync
#   wget or curl
#
JRUBY_VERSION=1.7.11
ELASTICSEARCH_VERSION=1.1.1
ELASTICSEARCH_URL=http://github.com/downloads/elasticsearch/elasticsearch
ELASTICSEARCH=vendor/jar/elasticsearch-$(ELASTICSEARCH_VERSION)

default: compile

# Compile config grammar (ragel -> ruby)
compile-grammar: lib/logstash/config/grammar.rb
lib/logstash/config/grammar.rb: lib/logstash/config/grammar.rl
	$(MAKE) -C lib/logstash/config grammar.rb
PLUGIN_FILES=$(shell find lib -type f| egrep '^lib/logstash/(inputs|outputs|filters|codecs)/[^/]+$$' | egrep -v '/(base|threadable).rb$$|/inputs/ganglia/')
.PHONY: clean
clean:
	-rm -rf .bundle
	-sh "rm -rf build"
	-sh "rm -rf vendor"

compile: compile-grammar compile-runner | build/ruby

.PHONY: compile-runner
ifeq (0, $(TARCHECK))
build/ruby/logstash/runner.class: lib/logstash/runner.rb | build/ruby
	(cd lib; jrubyc -t ../build/ruby logstash/runner.rb) 

.PHONY: copy-ruby-files
copy-ruby-files: | build/ruby
	@# Copy lib/ and test/ files to the root.
#spec/outputs/graphite.rb spec/outputs/email.rb)
default:
	git ls-files | grep '^test/.*\.rb$$' | sed -e 's,^test/,,' \
	| (cd test; cpio -p --make-directories ../build/ruby)

# TODO(sissel): Copy all .rb files from lib and test to build/ruby

.PHONY: jar
jar: | compile

vendor: 
	mkdir $@

vendor/jar: | vendor
	mkdir $@

#vendor-jruby: vendor/jar/jruby-complete-$(JRUBY_VERSION).jar
vendor-jruby: $(JRUBY)
$(JRUBY): | vendor/jar
	wget -O $@ $(JRUBY_URL)/$(shell basename $@)
.PHONY: wget-or-curl
wget-or-curl:
ifeq ($(CURL),)
ifeq ($(WGET),)
	wget --no-check-certificate \
		-O $@ $(ELASTICSEARCH_URL)/elasticsearch-$(ELASTICSEARCH_VERSION).tar.gz

vendor-elasticsearch: $(ELASTICSEARCH)
$(ELASTICSEARCH): $(ELASTICSEARCH).tar.gz | vendor/jar
	@echo "Pulling the jars out of $<"
endif

.PHONY: clean
clean:
	@echo "=> Cleaning up"
	-$(QUIET)rm -rf .bundle
	-$(QUIET)rm -rf build
	-$(QUIET)rm -f pkg/*.deb
	-$(QUIET)rm .VERSION.mk

.PHONY: vendor-clean
vendor-clean:
	-$(QUIET)rm -rf vendor/kibana vendor/geoip vendor/collectd
	-$(QUIET)rm -rf vendor/jar vendor/ua-parser

.PHONY: clean-vendor
clean-vendor:
	-$(QUIET)rm -rf vendor

.PHONY: copy-ruby-files
copy-ruby-files: | build/ruby
	@# Copy lib/ and test/ files to the root
	$(QUIET)rsync -a --include "*/" --include "*.rb" --include "*.yaml" --exclude "*" ./lib/ ./build/ruby
	$(QUIET)rsync -a ./spec ./build/ruby
	@# Delete any empty directories copied by rsync.
	$(QUIET)find ./build/ruby -type d -empty -delete

vendor:
	$(QUIET)mkdir $@

vendor/jar: | vendor
	$(QUIET)mkdir $@

	-mkdir -p $@
	@# Unpack all the 3rdparty jars and any jars in gems
	find $$PWD/vendor/bundle $$PWD/vendor/jar -name '*.jar' \
	| (cd $@; xargs -P2 -tn1 jar xf)
	@# Purge any extra files we don't need in META-INF (like manifests and
	@# TODO(sissel): Simplify this.
	-rm -f $@/META-INF/{INDEX.LIST,MANIFEST.MF,ECLIPSEF.RSA,ECLIPSEF.SF}
	@echo "=> Fetching elasticsearch"
	$(QUIET)$(DOWNLOAD_COMMAND) $@ $(ELASTICSEARCH_URL)/elasticsearch-$(ELASTICSEARCH_VERSION).tar.gz

build/tarball/logstash-$(LOGSTASH_VERSION).tar.gz: | wget-or-curl build build/tarball
	@echo "=> Fetching logstash $(LOGSTASH_VERSION)"
	$(QUIET)$(DOWNLOAD_COMMAND) $@ $(LOGSTASH_URL)/logstash-$(LOGSTASH_VERSION).tar.gz

.PHONY: vendor-elasticsearch
vendor-elasticsearch: $(ELASTICSEARCH)
$(ELASTICSEARCH): $(ELASTICSEARCH).tar.gz | vendor/jar
	@echo "=> Pulling the jars out of $<"
	$(QUIET)tar -C $(shell dirname $@) -xf $< $(TAR_OPTS) --exclude '*sigar*' \
		'elasticsearch-$(ELASTICSEARCH_VERSION)/lib/*.jar'

.PHONY: vendor-gems
vendor-gems: | vendor/bundle

test: 
	ruby bin/logstash test

docs: docgen doccopy docindex

# XXX Finish here' stopped at require_output_env
	echo $(VERSION)

.PHONY: prepare-tarball
prepare-tarball tarball zip: WORKDIR=build/tarball/logstash-$(VERSION)
prepare-tarball: $(LOGSTASH) $(JRUBY) vendor-gems
prepare-tarball:
	@echo "=> Preparing tarball"
	$(QUIET)$(MAKE) $(WORKDIR)
	$(QUIET)rsync -a --relative lib spec vendor/bundle/jruby vendor/jar --exclude 'vendor/bundle/jruby/1.9/cache' --exclude 'vendor/bundle/jruby/1.9/gems/*/doc' --exclude 'vendor/jar/elasticsearch-$(ELASTICSEARCH_VERSION).tar.gz' $(WORKDIR)

.PHONY: tarball
tarball: | build/logstash-$(VERSION).tar.gz
build/logstash-$(VERSION).tar.gz: | prepare-tarball
	$(QUIET)tar -C $$(dirname $(WORKDIR)) -c $$(basename $(WORKDIR)) \
		| gzip -9c > $@
	@echo "=> tarball ready: $@"

.PHONY: zip
zip: | build/logstash-$(VERSION).zip
build/logstash-$(VERSION).zip: | prepare-tarball
	$(QUIET)(cd $$(dirname $(WORKDIR)); find $$(basename $(WORKDIR)) | zip $(PWD)/$@ -@ -9)$(QUIET_OUTPUT)
	@echo "=> zip ready: $@"

.PHONY: tarball-test
tarball-test: #build/logstash-$(VERSION).tar.gz
	$(QUIET)-rm -rf build/test-tarball/
	$(QUIET)mkdir -p build/test-tarball/
	tar -C build/test-tarball --strip-components 1 -xf build/logstash-$(VERSION).tar.gz
	(cd build/test-tarball; bin/logstash rspec spec/**/kafka*.rb)

<MSG> Merge branch 'master' into ruby1.9

<DFF> @@ -7,9 +7,12 @@ ELASTICSEARCH_VERSION=0.17.6
 ELASTICSEARCH_URL=http://github.com/downloads/elasticsearch/elasticsearch
 ELASTICSEARCH=vendor/jar/elasticsearch-$(ELASTICSEARCH_VERSION)
 
+PLUGIN_FILES=$(shell git ls-files | egrep '^lib/logstash/(inputs|outputs|filters)/')
+
 default: compile
 
 # Compile config grammar (ragel -> ruby)
+.PHONY: compile-grammar
 compile-grammar: lib/logstash/config/grammar.rb
 lib/logstash/config/grammar.rb: lib/logstash/config/grammar.rl
 	$(MAKE) -C lib/logstash/config grammar.rb
@@ -17,9 +20,10 @@ lib/logstash/config/grammar.rb: lib/logstash/config/grammar.rl
 .PHONY: clean
 clean:
 	-rm -rf .bundle
-	-sh "rm -rf build"
-	-sh "rm -rf vendor"
+	-rm -rf build
+	-rm -rf vendor
 
+.PHONY: compile
 compile: compile-grammar compile-runner | build/ruby
 
 .PHONY: compile-runner
@@ -27,6 +31,7 @@ compile-runner: build/ruby/logstash/runner.class
 build/ruby/logstash/runner.class: lib/logstash/runner.rb | build/ruby
 	(cd lib; jrubyc -t ../build/ruby logstash/runner.rb) 
 
+# TODO(sissel): Stop using cpio for this
 .PHONY: copy-ruby-files
 copy-ruby-files: | build/ruby
 	@# Copy lib/ and test/ files to the root.
@@ -35,18 +40,13 @@ copy-ruby-files: | build/ruby
 	git ls-files | grep '^test/.*\.rb$$' | sed -e 's,^test/,,' \
 	| (cd test; cpio -p --make-directories ../build/ruby)
 
-# TODO(sissel): Copy all .rb files from lib and test to build/ruby
-
-.PHONY: jar
-jar: | compile
-
 vendor: 
 	mkdir $@
 
 vendor/jar: | vendor
 	mkdir $@
 
-#vendor-jruby: vendor/jar/jruby-complete-$(JRUBY_VERSION).jar
+.PHONY: vendor-jruby
 vendor-jruby: $(JRUBY)
 $(JRUBY): | vendor/jar
 	wget -O $@ $(JRUBY_URL)/$(shell basename $@)
@@ -57,6 +57,7 @@ vendor/jar/elasticsearch-$(ELASTICSEARCH_VERSION).tar.gz: | vendor/jar
 	wget --no-check-certificate \
 		-O $@ $(ELASTICSEARCH_URL)/elasticsearch-$(ELASTICSEARCH_VERSION).tar.gz
 
+.PHONY: vendor-elasticsearch
 vendor-elasticsearch: $(ELASTICSEARCH)
 $(ELASTICSEARCH): $(ELASTICSEARCH).tar.gz | vendor/jar
 	@echo "Pulling the jars out of $<"
@@ -96,7 +97,7 @@ build/monolith: compile copy-ruby-files
 	-mkdir -p $@
 	@# Unpack all the 3rdparty jars and any jars in gems
 	find $$PWD/vendor/bundle $$PWD/vendor/jar -name '*.jar' \
-	| (cd $@; xargs -P2 -tn1 jar xf)
+	| (cd $@; xargs -tn1 jar xf)
 	@# Purge any extra files we don't need in META-INF (like manifests and
 	@# TODO(sissel): Simplify this.
 	-rm -f $@/META-INF/{INDEX.LIST,MANIFEST.MF,ECLIPSEF.RSA,ECLIPSEF.SF}
@@ -120,6 +121,33 @@ build/logstash-$(VERSION)-monolithic.jar:
 test: 
 	ruby bin/logstash test
 
+.PHONY: docs
+docs: OUTPUT=build/docs
 docs: docgen doccopy docindex
 
-# XXX Finish here' stopped at require_output_env
+build/docs:
+	-mkdir -p $@
+
+doccopy: $(addprefix build/,$(shell git ls-files | grep '^docs/')) | $(OUTPUT)
+docindex: build/docs/index.html
+
+#docgen: 
+	#$(MAKE) $(MAKEFLAGS) $(addprefix build/docs/,$(subst lib/logstash/,,$(subst .rb,.html,$(FILES))))
+docgen: $(addprefix build/docs/,$(subst lib/logstash/,,$(subst .rb,.html,$(PLUGIN_FILES))))
+
+build/docs/inputs/%.html: lib/logstash/inputs/%.rb
+build/docs/filters/%.html: lib/logstash/filters/%.rb
+build/docs/outputs/%.html: lib/logstash/outputs/%.rb
+
+build/docs/inputs/%.html build/docs/filters/%.html build/docs/outputs/%.html:
+	ruby docs/docgen.rb -o $@ $<
+
+build/docs/%: docs/%
+	@-mkdir -p $(shell dirname $@)
+	sed -re 's/%VERSION%/$(VERSION)/g' $< > $@
+
+build/docs/index.html: docs/generate_index.rb
+	ruby $< > $@
+
+publish: | gem
+	gem push logstash-$(VERSION).gem

Merge branch 'master' into ruby1.9