Add support for building JARs from Java sources

This commit is contained in:
Eelco Dolstra 2013-12-18 16:40:48 +01:00
parent 99ed25accf
commit 259086de84
2 changed files with 39 additions and 1 deletions

29
mk/jars.mk Normal file
View file

@ -0,0 +1,29 @@
define build-jar =
$(1)_NAME ?= $(1)
_d := $$(strip $$($(1)_DIR))
$(1)_PATH := $$(_d)/$$($(1)_NAME).jar
$(1)_TMPDIR := $$(_d)/.$$($(1)_NAME).jar.tmp
$$($(1)_PATH): $$($(1)_SOURCES)
@rm -rf $$($(1)_TMPDIR)
@mkdir -p $$($(1)_TMPDIR)
$(QUIET) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) $$($(1)_SOURCES)
$(QUIET) jar cf $$($(1)_PATH) -C $$($(1)_TMPDIR) .
@rm -rf $$($(1)_TMPDIR)
$(1)_INSTALL_DIR ?= $$(libdir)/java
$(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).jar
$$(eval $$(call install-file-as, $$($(1)_PATH), $$($(1)_INSTALL_PATH), 0644))
install: $$($(1)_INSTALL_PATH)
jars_list += $$($(1)_PATH)
clean_files += $$($(1)_PATH)
endef

View file

@ -37,6 +37,7 @@ BUILD_DEBUG ?= 1
ifeq ($(BUILD_DEBUG), 1) ifeq ($(BUILD_DEBUG), 1)
GLOBAL_CFLAGS += -g GLOBAL_CFLAGS += -g
GLOBAL_CXXFLAGS += -g GLOBAL_CXXFLAGS += -g
GLOBAL_JAVACFLAGS += -g
endif endif
@ -50,6 +51,7 @@ include mk/dist.mk
include mk/install.mk include mk/install.mk
include mk/libraries.mk include mk/libraries.mk
include mk/programs.mk include mk/programs.mk
include mk/jars.mk
include mk/patterns.mk include mk/patterns.mk
include mk/templates.mk include mk/templates.mk
include mk/tests.mk include mk/tests.mk
@ -67,6 +69,7 @@ $(foreach mf, $(SUBS), $(eval $(call include-sub-makefile, $(mf))))
# Instantiate stuff. # Instantiate stuff.
$(foreach lib, $(LIBS), $(eval $(call build-library,$(lib)))) $(foreach lib, $(LIBS), $(eval $(call build-library,$(lib))))
$(foreach prog, $(PROGRAMS), $(eval $(call build-program,$(prog)))) $(foreach prog, $(PROGRAMS), $(eval $(call build-program,$(prog))))
$(foreach jar, $(JARS), $(eval $(call build-jar,$(jar))))
$(foreach script, $(bin_SCRIPTS), $(eval $(call install-program-in,$(script),$(bindir)))) $(foreach script, $(bin_SCRIPTS), $(eval $(call install-program-in,$(script),$(bindir))))
$(foreach script, $(bin_SCRIPTS), $(eval programs_list += $(script))) $(foreach script, $(bin_SCRIPTS), $(eval programs_list += $(script)))
$(foreach script, $(noinst_SCRIPTS), $(eval programs_list += $(script))) $(foreach script, $(noinst_SCRIPTS), $(eval programs_list += $(script)))
@ -74,7 +77,7 @@ $(foreach template, $(template_files), $(eval $(call instantiate-template,$(temp
$(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test)))) $(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test))))
all: $(programs_list) $(libs_list) all: $(programs_list) $(libs_list) $(jars_list)
help: help:
@ -99,3 +102,9 @@ ifdef libs_list
@echo "" @echo ""
@for i in $(libs_list); do echo " $$i"; done @for i in $(libs_list); do echo " $$i"; done
endif endif
ifdef jars_list
@echo ""
@echo "The following JARs can be built:"
@echo ""
@for i in $(jars_list); do echo " $$i"; done
endif