Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package Themis JNI library in DEB and RPM #553

Merged
merged 5 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Themis ChangeLog

## Unreleased

Changes that are currently in development and have not been released yet.

_Code:_

- **Java**

- JNI libraries are now available as `libthemis-jni` packages for supported Linux systems ([#552](https://github.com/cossacklabs/themis/pull/552), [#553](https://github.com/cossacklabs/themis/pull/553)).

## [0.12.0](https://github.com/cossacklabs/themis/releases/tag/0.12.0), September 27th 2019

**TL;DR:**
Expand Down
44 changes: 42 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ exec_prefix = $(prefix)
bindir = $(prefix)/bin
includedir = $(prefix)/include
libdir = $(exec_prefix)/lib
jnidir = $(libdir)
pkgconfigdir = $(libdir)/pkgconfig

CFLAGS += -I$(SRC_PATH) -I$(SRC_PATH)/wrappers/themis/ -fPIC
Expand Down Expand Up @@ -577,11 +578,13 @@ DEB_DEPENDENCIES := --depends openssl
DEB_DEPENDENCIES_DEV += --depends "$(PACKAGE_NAME) = $(VERSION)+$(OS_CODENAME)"
DEB_DEPENDENCIES_DEV += --depends libssl-dev
DEB_DEPENDENCIES_THEMISPP = --depends "$(DEB_DEV_PACKAGE_NAME) = $(VERSION)+$(OS_CODENAME)"
DEB_DEPENDENCIES_JNI += --depends "$(PACKAGE_NAME) >= $(VERSION)+$(OS_CODENAME)"

RPM_DEPENDENCIES = --depends openssl
RPM_DEPENDENCIES_DEV += --depends "$(PACKAGE_NAME) = $(RPM_VERSION)-$(RPM_RELEASE_NUM)"
RPM_DEPENDENCIES_DEV += --depends openssl-devel
RPM_DEPENDENCIES_THEMISPP = --depends "$(RPM_DEV_PACKAGE_NAME) = $(RPM_VERSION)-$(RPM_RELEASE_NUM)"
RPM_DEPENDENCIES_JNI += --depends "$(PACKAGE_NAME) >= $(RPM_VERSION)-$(RPM_RELEASE_NUM)"
RPM_RELEASE_NUM = 1

ifeq ($(shell lsb_release -is 2> /dev/null),Debian)
Expand All @@ -608,6 +611,7 @@ DEB_DEV_PACKAGE_NAME = libthemis-dev
RPM_DEV_PACKAGE_NAME = libthemis-devel
DEB_THEMISPP_PACKAGE_NAME = libthemispp-dev
RPM_THEMISPP_PACKAGE_NAME = libthemispp-devel
JNI_PACKAGE_NAME = libthemis-jni

PACKAGE_CATEGORY = security
SHORT_DESCRIPTION = Data security library for network communication and data storage
Expand All @@ -634,11 +638,14 @@ LIB_PACKAGE_FILES += $(libdir)/$(LIBTHEMIS_LINK)

THEMISPP_PACKAGE_FILES += $(includedir)/themispp/

JNI_PACKAGE_FILES += $(jnidir)/$(LIBTHEMISJNI_SO)

deb: DESTDIR = $(BIN_PATH)/deb/root
deb: PREFIX = /usr
deb: libdir = $(PREFIX)/$(DEB_LIBDIR)
deb: jnidir = $(PREFIX)/$(DEB_LIBDIR)/jni

deb: install themispp_install
deb: install themispp_install themis_jni_install
@printf "ldconfig" > $(POST_INSTALL_SCRIPT)
@printf "ldconfig" > $(POST_UNINSTALL_SCRIPT)

Expand Down Expand Up @@ -695,13 +702,30 @@ deb: install themispp_install
--category $(PACKAGE_CATEGORY) \
$(foreach file,$(THEMISPP_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))

@fpm --input-type dir \
--output-type deb \
--name $(JNI_PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--maintainer $(MAINTAINER) \
--package $(BIN_PATH)/deb/$(JNI_PACKAGE_NAME)_$(NAME_SUFFIX) \
--architecture $(DEB_ARCHITECTURE) \
--version $(VERSION)+$(OS_CODENAME) \
$(DEB_DEPENDENCIES_JNI) \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
--deb-priority optional \
--category $(PACKAGE_CATEGORY) \
$(foreach file,$(JNI_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))

@find $(BIN_PATH) -name \*.deb

rpm: DESTDIR = $(BIN_PATH)/rpm/root
rpm: PREFIX = /usr
rpm: libdir = $(PREFIX)/$(RPM_LIBDIR)

rpm: install themispp_install
rpm: install themispp_install themis_jni_install
@printf "ldconfig" > $(POST_INSTALL_SCRIPT)
@printf "ldconfig" > $(POST_UNINSTALL_SCRIPT)

Expand Down Expand Up @@ -755,6 +779,22 @@ rpm: install themispp_install
--category $(PACKAGE_CATEGORY) \
$(foreach file,$(THEMISPP_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))

@fpm --input-type dir \
--output-type rpm \
--name $(JNI_PACKAGE_NAME) \
--license $(LICENSE_NAME) \
--url '$(COSSACKLABS_URL)' \
--description '$(SHORT_DESCRIPTION)' \
--rpm-summary '$(RPM_SUMMARY)' \
--maintainer $(MAINTAINER) \
--after-install $(POST_INSTALL_SCRIPT) \
--after-remove $(POST_UNINSTALL_SCRIPT) \
$(RPM_DEPENDENCIES_JNI) \
--package $(BIN_PATH)/rpm/$(JNI_PACKAGE_NAME)-$(NAME_SUFFIX) \
--version $(RPM_VERSION) \
--category $(PACKAGE_CATEGORY) \
$(foreach file,$(JNI_PACKAGE_FILES),$(DESTDIR)/$(file)=$(file))

@find $(BIN_PATH) -name \*.rpm

########################################################################
Expand Down
42 changes: 40 additions & 2 deletions jni/themis_jni.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,45 @@ $(BIN_PATH)/$(LIBTHEMISJNI_SO): $(THEMIS_JNI_OBJ) $(THEMIS_STATIC)
@mkdir -p $(@D)
@echo -n "link "
@$(BUILD_CMD)

themis_jni_install: $(BIN_PATH)/$(LIBTHEMISJNI_SO)
@echo -n "install Themis JNI "
@mkdir -p $(DESTDIR)$(jnidir)
@$(INSTALL_PROGRAM) $(BIN_PATH)/$(LIBTHEMISJNI_SO) $(DESTDIR)$(jnidir)
ifdef IS_MACOS
@install_name_tool -id "$(PREFIX)/lib/$(notdir $@)" $(BIN_PATH)/$(notdir $@)
@install_name_tool -change "$(BIN_PATH)/$(notdir $@)" "$(PREFIX)/lib/$(notdir $@)" $(BIN_PATH)/$(notdir $@)
@install_name_tool -id "$(jnidir)/$(LIBTHEMISJNI_SO)" "$(DESTDIR)$(jnidir)/$(LIBTHEMISJNI_SO)"
@install_name_tool -change "$(BIN_PATH)/$(LIBTHEMIS_SO)" "$(libdir)/$(LIBTHEMIS_SO)" "$(DESTDIR)$(jnidir)/$(LIBTHEMISJNI_SO)"
endif
@$(PRINT_OK_)
@java_library_path=$$(\
java -XshowSettings:properties -version 2>&1 \
| sed -E 's/^ +[^=]+ =/_&/' \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black magic happening here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you'd like it can be replaced with the following Java code:

import java.io.File;

public final class Main {
    public static void main(String[] args) {
        String rawPath = System.getProperty("java.library.path");
        String[] paths = rawPath.split(File.pathSeparator);
        for (String path : paths) {
            System.out.println(path);
        }
    }
}

Just need to compile and run it. Or we can bundle a precompiled *.jar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for explanation, my skills of understanding regex "on the fly" are not perfect

| awk -v prop=java.library.path \
'BEGIN { RS = "_"; IFS = " = " } \
{ if($$1 ~ prop) { \
for (i = 3; i <= NF; i++) { \
print $$i \
} \
} \
}' \
) && \
if echo "$$java_library_path" | grep -vq '^$(jnidir)$$'; \
then \
echo ''; \
echo 'Your Java installation does not seem to have "$(jnidir)" in its'; \
echo 'search path for JNI libraries:'; \
echo ''; \
echo "$$java_library_path" | sed 's/^/ /'; \
echo ''; \
echo 'You will need to either add it to the "java.library.path" property'; \
echo 'on application startup, or to move $(LIBTHEMISJNI_SO) manually'; \
echo 'to one of these locations so that Java could find it.'; \
echo ''; \
fi

themis_jni_uninstall:
@echo -n "uninstall Themis JNI "
@rm -f $(DESTDIR)$(jnidir)/$(LIBTHEMISJNI_SO)
@$(PRINT_OK_)

uninstall: themis_jni_uninstall