Skip to content

Instantly share code, notes, and snippets.

@dgmorales
Last active February 14, 2023 06:18
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgmorales/3420ce5dca9f0a79e97db5bcc9358a58 to your computer and use it in GitHub Desktop.
Save dgmorales/3420ce5dca9f0a79e97db5bcc9358a58 to your computer and use it in GitHub Desktop.
Example Makefile for creating deb/rpm packages with jordansissel/fpm
# This is an example Makefile for quick package creation
#
# It uses FPM [1] to generate simple packages.
# - If you need more features or a greater quality package, use debian
# standard tools for packaging.
# - Do not use checkinstall. Use FPM instead.
#
# [1] (https://github.com/jordansissel/fpm/wiki)
# IMPORTANT:
#
# Use whatever variables/paths you want, but PREFIX all destination install
# paths with $(DESTDIR), like below:
#CONFIGDIR=$(DESTDIR)/etc/myapp
#CRONDIR=$(DESTDIR)/etc/cron.d
#INITDIR=$(DESTDIR)/etc/init.d
#LOGROTATEDIR=$(DESTDIR)/etc/logrotate.d
#INSTALLDIR=$(DESTDIR)/my/install/path
# Basic package information
PKG_NAME=myapp
PKG_DESCRIPTION="Package that does foo"
PKG_VERSION=1
PKG_RELEASE=0
PKG_MAINTAINER="Lazy Guy \<someone@somewhere.com\>"
PKG_ARCH=all
PKG_ARCH_RPM=noarch
# These vars probably need no change
PKG_DEB=${PKG_NAME}_${PKG_VERSION}-${PKG_RELEASE}_${PKG_ARCH}.deb
PKG_RPM=${PKG_NAME}-${PKG_VERSION}-${PKG_RELEASE}.${PKG_ARCH_RPM}.rpm
FPM_OPTS=-s dir -n $(PKG_NAME) -v $(PKG_VERSION) --iteration $(PKG_RELEASE) -C $(TMPINSTALLDIR) --maintainer ${PKG_MAINTAINER} --description $(PKG_DESCRIPTION) -a $(PKG_ARCH)
TMPINSTALLDIR=/tmp/$(PKG_NAME)-fpm-install
# Do whatever you need to install the software. Remember to use $(DESTDIR) as
# prefix to all destination paths.
#
# About SYMLINKS: Making a symlink *pointing* to a path with $(DESTDIR) won't work. You can:
# - Use the pointed-to-path without $(DESTDIR) OR
# - Use relative paths OR
# - Create symlinks in the after install script.
#
# Example:
install:
# mkdir -p $(INSTALLDIR)
# cp myprog $(INSTALLDIR)
# ln -s /usr/local/myapp/myprog $(DESTDIR)/usr/local/bin/myprog
# ln -s ../myapp/myprog $(DESTDIR)/usr/local/bin/myprog
# Generate a deb package using fpm
deb:
rm -rf $(TMPINSTALLDIR)
rm -f $(PKG_DEB)
chmod -R g-w *
make install DESTDIR=$(TMPINSTALLDIR)
# Set as needed: package dependencies (-d), after-install script, and paths to
# include in the package (last line):
#
# Dependencies python and fping below are just examples, change that to your dependencies
#
fpm -t deb -p $(PKG_DEB) $(FPM_OPTS) \
-d python \
-d 'fping > 3' \
--after-install postinstall-deb \
etc usr var
# Generate a rpm package using fpm
rpm:
rm -rf $(TMPINSTALLDIR)
rm -f $(PKG_RPM)
chmod -R g-w *
make install-rpm DESTDIR=$(TMPINSTALLDIR)
# Set as needed: package dependencies (-d), after-install script, and paths to
# include in the package (last line):
#
# Dependencies python and fping below are just examples, change that to your dependencies
#
fpm -t rpm -p $(PKG_RPM) $(FPM_OPTS) \
-d python \
-d 'fping > 3' \
--after-install postinstall-rpm \
etc usr var
#publish:
# Do whatever you need to publish your packages to your private repos, if you have any.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment