pgmon/Makefile

142 lines
3.6 KiB
Makefile
Raw Normal View History

2025-01-08 23:34:51 +00:00
PACKAGE_NAME := pgmon
VERSION := 1.0
2025-01-09 01:58:52 +00:00
2025-01-08 23:34:51 +00:00
BUILD_DIR := build
2025-01-09 01:58:52 +00:00
2025-01-08 23:34:51 +00:00
DEB_IMAGE := debian-package-builder
RPM_IMAGE := rpm-package-builder
2025-01-14 06:54:35 +00:00
EL7_IMAGE := el7-package-builder
2025-01-08 23:34:51 +00:00
SCRIPT := src/$(PACKAGE_NAME).py
2025-01-10 05:40:41 +00:00
INSTALL_TEST_DEBIAN := 11
INSTALL_TEST_REDHAT := 9
INSTALL_TEST_UBUNTU := 24.04
##
# These targets are the main ones to use for most things.
##
.PHONY: all clean deb rpm test install install-tests
2025-01-08 23:34:51 +00:00
all: deb rpm
deb:
mkdir -p $(BUILD_DIR)/deb
docker run --rm \
-v .:/src:ro \
-v ./$(BUILD_DIR)/deb:/output \
--user $(shell id -u):$(shell id -g) \
2025-01-08 23:34:51 +00:00
$(DEB_IMAGE)
rpm:
mkdir -p $(BUILD_DIR)/rpm
docker run --rm \
-v .:/src:ro \
-v ./$(BUILD_DIR)/rpm:/output \
--user $(shell id -u):$(shell id -g) \
2025-01-08 23:34:51 +00:00
$(RPM_IMAGE)
2025-01-10 05:40:41 +00:00
tgz:
rm -rf $(BUILD_DIR)/tgz/root
mkdir -p $(BUILD_DIR)/tgz/root
$(MAKE) install DESTDIR=$(BUILD_DIR)/tgz/root
tar -cz -f $(BUILD_DIR)/tgz/$(PACKAGE_NAME)-$(VERSION).tgz -C $(BUILD_DIR)/tgz/root .
2025-01-08 23:34:51 +00:00
clean:
rm -rf $(BUILD_DIR)
2025-01-09 01:58:52 +00:00
test:
cd src ; python3 -m unittest
2025-01-08 23:34:51 +00:00
2025-01-10 05:40:41 +00:00
install:
# Set up directories
mkdir -p $(DESTDIR)/etc/$(PACKAGE_NAME)
mkdir -p ${DESTDIR}/etc/logrotate.d
2025-01-10 05:40:41 +00:00
mkdir -p $(DESTDIR)/lib/systemd/system
mkdir -p $(DESTDIR)/usr/local/bin
mkdir -p $(DESTDIR)/usr/share/man/man1
2025-01-10 05:40:41 +00:00
# Install script
cp $(SCRIPT) $(DESTDIR)/usr/local/bin/$(PACKAGE_NAME)
chmod 755 $(DESTDIR)/usr/local/bin/$(PACKAGE_NAME)
# Install manpage
cp manpages/* $(DESTDIR)/usr/share/man/man1/
gzip -f -9 $(DESTDIR)/usr/share/man/man1/$(PACKAGE_NAME).1
2025-01-10 05:40:41 +00:00
# Install sample config
cp sample-config/* $(DESTDIR)/etc/$(PACKAGE_NAME)/
# Install systemd unit files
cp systemd/* $(DESTDIR)/lib/systemd/system/
2025-01-15 06:34:04 +00:00
# Install logrotate config
cp logrotate/${PACKAGE_NAME}.logrotate ${DESTDIR}/etc/logrotate.d/${PACKAGE_NAME}
2025-01-08 23:34:51 +00:00
2025-01-10 05:40:41 +00:00
install-tests: debian-install-test rocky-install-test ubuntu-install-test
2025-01-08 23:34:51 +00:00
2025-01-10 05:40:41 +00:00
debian-install-test:
docker run --rm \
-v ./$(BUILD_DIR)/deb:/output \
debian:$(INSTALL_TEST_DEBIAN) \
bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)_$(VERSION).deb'
2025-01-08 23:34:51 +00:00
2025-01-10 05:40:41 +00:00
rocky-install-test:
docker run --rm \
-v ./$(BUILD_DIR)/rpm:/output \
rockylinux:$(INSTALL_TEST_REDHAT) \
bash -c 'yum makecache && yum install -y /output/$(PACKAGE_NAME)-$(VERSION)-1.el$(INSTALL_TEST_REDHAT).noarch.rpm'
ubuntu-install-test:
docker run --rm \
-v ./$(BUILD_DIR)/deb:/output \
ubuntu:$(INSTALL_TEST_UBUNTU) \
bash -c 'apt-get update && apt-get install -y /output/$(PACKAGE_NAME)_$(VERSION).deb'
2025-01-08 23:34:51 +00:00
2025-01-10 05:40:41 +00:00
##
2025-01-08 23:34:51 +00:00
# Inside-container targets
2025-01-10 05:40:41 +00:00
#
# These targets are used inside containers. They expect the repo to be mounted
# at /src and the package manager specific build directory to be mounted at
# /output.
##
2025-01-08 23:34:51 +00:00
.PHONY: package-deb package-rpm
# Debian package creation logic
package-deb:
2025-01-10 05:40:41 +00:00
$(MAKE) install DESTDIR=/output
cp -r --preserve=mode DEBIAN /output/
2025-01-10 05:40:41 +00:00
dpkg-deb -Zgzip --build /output /output/$(PACKAGE_NAME)_$(VERSION).deb
2025-01-08 23:34:51 +00:00
# RPM package creation logic
package-rpm:
mkdir -p /output/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
cp RPM/$(PACKAGE_NAME).spec /output/SPECS/
rpmbuild --define '_topdir /output' \
--define 'version $(VERSION)' \
2025-01-09 01:58:52 +00:00
-bb /output/SPECS/$(PACKAGE_NAME).spec
2025-01-10 05:40:41 +00:00
cp /output/RPMS/noarch/*.rpm /output/
2025-01-08 23:34:51 +00:00
2025-01-10 05:40:41 +00:00
##
# Container targets
#
# These targets build the docker images used to create packages
##
.PHONY: docker deb-package-image rpm-package-image
docker: deb-package-image rpm-package-image
2025-01-14 06:59:18 +00:00
deb-package-image: docker/Dockerfile-deb
docker build -t $(DEB_IMAGE) -f docker/Dockerfile-deb .
2025-01-10 05:40:41 +00:00
2025-01-14 06:59:18 +00:00
rpm-package-image: docker/Dockerfile-rpm
docker build -t $(RPM_IMAGE) -f docker/Dockerfile-rpm .
2025-01-14 06:54:35 +00:00
2025-01-14 06:59:18 +00:00
el7-package-image: docker/Dockerfile-el7
docker build -t $(EL7_IMAGE) -f docker/Dockerfile-el7 .