Skip to content

Commit

Permalink
Add support for building JARs from Java sources
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Dec 18, 2013
1 parent 99ed25a commit 259086d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
29 changes: 29 additions & 0 deletions mk/jars.mk
@@ -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
11 changes: 10 additions & 1 deletion mk/lib.mk
Expand Up @@ -37,6 +37,7 @@ BUILD_DEBUG ?= 1
ifeq ($(BUILD_DEBUG), 1)
GLOBAL_CFLAGS += -g
GLOBAL_CXXFLAGS += -g
GLOBAL_JAVACFLAGS += -g
endif


Expand All @@ -50,6 +51,7 @@ include mk/dist.mk
include mk/install.mk
include mk/libraries.mk
include mk/programs.mk
include mk/jars.mk
include mk/patterns.mk
include mk/templates.mk
include mk/tests.mk
Expand All @@ -67,14 +69,15 @@ $(foreach mf, $(SUBS), $(eval $(call include-sub-makefile, $(mf))))
# Instantiate stuff.
$(foreach lib, $(LIBS), $(eval $(call build-library,$(lib))))
$(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 programs_list += $(script)))
$(foreach script, $(noinst_SCRIPTS), $(eval programs_list += $(script)))
$(foreach template, $(template_files), $(eval $(call instantiate-template,$(template))))
$(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test))))


all: $(programs_list) $(libs_list)
all: $(programs_list) $(libs_list) $(jars_list)


help:
Expand All @@ -99,3 +102,9 @@ ifdef libs_list
@echo ""
@for i in $(libs_list); do echo " $$i"; done
endif
ifdef jars_list
@echo ""
@echo "The following JARs can be built:"
@echo ""
@for i in $(jars_list); do echo " $$i"; done
endif

0 comments on commit 259086d

Please sign in to comment.