From 3f8ab4333f78afcf52f23bc05d51a83c74f7a1ea Mon Sep 17 00:00:00 2001 From: Benjamin Zaporzan Date: Wed, 13 Jun 2018 23:41:21 -0400 Subject: [PATCH] working .deb package generation --- Makefile | 45 +++++++++++++++++++++++ build-native.sh | 3 +- dist_config/dpkg/Makefile | 56 +++++++++++++++++------------ dist_config/dpkg/dbuild.mk.template | 13 ------- dist_config/dpkg/postinst.template | 5 +++ dist_config/dpkg/prerm.template | 5 +++ 6 files changed, 91 insertions(+), 36 deletions(-) create mode 100644 Makefile delete mode 100644 dist_config/dpkg/dbuild.mk.template create mode 100644 dist_config/dpkg/postinst.template create mode 100644 dist_config/dpkg/prerm.template diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f83194e --- /dev/null +++ b/Makefile @@ -0,0 +1,45 @@ +# Main makefile for building distributable packages of fif executable + +FIF_EXISTS := $(shell which fif >/dev/null && echo "True" || echo "False") + +# Use fif to retrieve the project version, since it's faster +ifeq ($(FIF_EXISTS), True) +FIF_VERSION := $(shell fif -e \"project.clj\" read-file first 2 nth println) +else +FIF_VERSION := $(shell lein project-version) +endif + +FIF_EXE_NAME := fif-$(FIF_VERSION) + +PROJ_FIF_EXE := bin/$(FIF_EXE_NAME) + +# default +all: clean build-native + + +# Generate `fif` native executable +build-native: $(PROJ_FIF_EXE) + + +$(PROJ_FIF_EXE): + ./build-native.sh + + +# Generate .deb Package for native executable +dpkg: $(PROJ_FIF_EXE) + make -C dist_config/dpkg/ dpkg + + +install: $(PROJ_FIF_EXE) + cp $(PROJ_FIF_EXE) /usr/bin/$(FIF_EXE_NAME) + rm -f /usr/bin/fif + ln -s /usr/bin/$(FIF_EXE_NAME) fif + + +clean: + rm -f $(PROJ_FIF_EXE) + + +distclean: + rm -f /usr/bin/$(FIF_EXE_NAME) + rm -f /usr/bin/fif diff --git a/build-native.sh b/build-native.sh index 78a1b00..70dc1bf 100755 --- a/build-native.sh +++ b/build-native.sh @@ -32,7 +32,8 @@ echo "Post Configuration..." mkdir -p bin chmod 744 fif mv fif-$FIF_VERSION ./bin/ +rm ./bin/fif ln -s ./bin/fif-$FIF_VERSION ./bin/fif echo "" -echo "Built executable can be found at ./bin/fif" +echo "Built executable can be found at ./bin/fif-${FIF_VERSION}" diff --git a/dist_config/dpkg/Makefile b/dist_config/dpkg/Makefile index 24fbb16..9e187cb 100644 --- a/dist_config/dpkg/Makefile +++ b/dist_config/dpkg/Makefile @@ -1,4 +1,6 @@ # Makefile for generating dpkgs for the native-image compiled 'fif' executable +# Requires: leiningen +# Optional: fif EMAIL := benzaporzan@gmail.com @@ -21,28 +23,35 @@ endif FIF_EXE_NAME := fif-$(FIF_VERSION) -DMAKE_DIR := $(DIST_DIR)/dpkg/$(ARCH)/$(FIF_EXE_NAME) + +DEB_NAME := $(FIF_EXE_NAME)-$(ARCH) +DEB_VERSION := 1 + +DMAKE_DIR := $(DIST_DIR)/dpkg/$(DEB_NAME) PROJ_FIF_EXE := $(PROJECT_ROOT_DIR)/bin/$(FIF_EXE_NAME) -DPKG_FIF_EXE := $(DMAKE_DIR)/$(FIF_EXE_NAME) +DPKG_FIF_EXE := $(DMAKE_DIR)/usr/bin/$(FIF_EXE_NAME) init: - mkdir -p $(DMAKE_DIR) - cd $(DMAKE_DIR) && dh_make --copyright custom \ - --copyrightfile $(PROJECT_ROOT_DIR)/LICENSE \ - --email $(EMAIL) \ - --single --native --yes - rm -f $(DMAKE_DIR)/debian/README - rm -f $(DMAKE_DIR)/debian/*.ex - cp dbuild.mk.template $(DMAKE_DIR)/Makefile - sed -i "s/FIF_NAME_EXE/$(FIF_EXE_NAME)/g" $(DMAKE_DIR)/Makefile - - sed -i "s/Section:.*/Section: interpreters/" $(DMAKE_DIR)/debian/control - sed -i "s/Homepage:.*/Homepage: http:\/\/github.com\/benzap\/fif/" $(DMAKE_DIR)/debian/control - sed -i "s/Architecture:.*/Architecture: any-$(ARCH)/" $(DMAKE_DIR)/debian/control - sed -i "s/Description:.*/Description: Interpreter and Repl for the fif language/" \ - $(DMAKE_DIR)/debian/control - sed -i "s/ > $(DMAKE_DIR)/DEBIAN/control + echo "Version: $(FIF_VERSION)-$(DEB_VERSION)" >> $(DMAKE_DIR)/DEBIAN/control + echo "Section: interpreters" >> $(DMAKE_DIR)/DEBIAN/control + echo "Priority: optional" >> $(DMAKE_DIR)/DEBIAN/control + echo "Homepage: http://github.com/benzap/fif" >> $(DMAKE_DIR)/DEBIAN/control + echo "Architecture: $(ARCH)" >> $(DMAKE_DIR)/DEBIAN/control + echo "Maintainer: Benjamin Zaporzan " >> $(DMAKE_DIR)/DEBIAN/control + echo "Description: Interpreter and Repl for the fif language" >> $(DMAKE_DIR)/DEBIAN/control + + cp prerm.template $(DMAKE_DIR)/DEBIAN/prerm + chmod 775 $(DMAKE_DIR)/DEBIAN/prerm + sed -i "s/FIF_EXE_NAME/$(FIF_EXE_NAME)/g" $(DMAKE_DIR)/DEBIAN/prerm + + cp postinst.template $(DMAKE_DIR)/DEBIAN/postinst + chmod 775 $(DMAKE_DIR)/DEBIAN/postinst + sed -i "s/FIF_EXE_NAME/$(FIF_EXE_NAME)/g" $(DMAKE_DIR)/DEBIAN/postinst + + cp $(PROJECT_ROOT_DIR)/LICENSE $(DMAKE_DIR)/DEBIAN/license $(PROJ_FIF_EXE): echo "Building Native Image..." @@ -50,18 +59,21 @@ $(PROJ_FIF_EXE): $(DPKG_FIF_EXE): $(PROJ_FIF_EXE) + mkdir -p $(DMAKE_DIR)/usr/bin cp $(PROJ_FIF_EXE) $(DPKG_FIF_EXE) + chmod 755 $(DPKG_FIF_EXE) prepare: $(DPKG_FIF_EXE) + find $(DMAKE_DIR) -type d | xargs chmod 755 - - +build: + dpkg-deb --build $(DMAKE_DIR) clean: rm -rf $(DMAKE_DIR) -dpkg: clean init prepare +dpkg: clean init prepare build diff --git a/dist_config/dpkg/dbuild.mk.template b/dist_config/dpkg/dbuild.mk.template deleted file mode 100644 index 8143caa..0000000 --- a/dist_config/dpkg/dbuild.mk.template +++ /dev/null @@ -1,13 +0,0 @@ -# Makefile for dpkg build - - -install: - cp FIF_NAME_EXE /usr/bin/FIF_NAME_EXE - chmod 755 /usr/bin/FIF_NAME_EXE - rm -f /usr/bin/fif - ln -s /usr/bin/FIF_NAME_EXE /usr/bin/fif - - -distclean: - rm -f /usr/bin/FIF_NAME_EXE - rm -f /usr/bin/fif diff --git a/dist_config/dpkg/postinst.template b/dist_config/dpkg/postinst.template new file mode 100644 index 0000000..e79f8df --- /dev/null +++ b/dist_config/dpkg/postinst.template @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +chmod 755 /usr/bin/FIF_EXE_NAME +rm -f /usr/bin/fif +ln -s /usr/bin/FIF_EXE_NAME /usr/bin/fif diff --git a/dist_config/dpkg/prerm.template b/dist_config/dpkg/prerm.template new file mode 100644 index 0000000..4635fa9 --- /dev/null +++ b/dist_config/dpkg/prerm.template @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +rm -f /usr/bin/FIF_EXE_NAME +rm -f /usr/bin/fif +