From d87237c88b8321839fb0bd3842c9fc7e0ffbe9aa Mon Sep 17 00:00:00 2001 From: xliang Date: Sat, 5 Aug 2023 21:38:45 -0700 Subject: [PATCH 1/3] Fix dnf installation, allow passing in CPU flag --- Makefile | 14 +++++++++++++- SPECS/haproxy.spec | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 884faaf..562c9d3 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ USE_PODMAN?=0 LUA_VERSION?=5.4.3 USE_LUA?=0 USE_PROMETHEUS?=0 +CPU?=0 VERSION=$(shell curl -s http://git.haproxy.org/git/haproxy-${MAINVERSION}.git/refs/tags/ | sed -n 's:.*>\(.*\).*:\1:p' | sed 's/^.//' | sort -rV | head -1) ifeq ("${VERSION}","./") VERSION="${MAINVERSION}.0" @@ -17,6 +18,16 @@ ifeq ($(NO_SUDO),1) else SUDO=sudo endif + +HAS_DNF:=$(shell command -v dnf 2> /dev/null) +ifndef HAS_DNF + PACKAGE_MANAGER=yum + INSTALL_FLAGS=-y +else + PACKAGE_MANAGER=dnf + INSTALL_FLAGS=-y --allowerasing +endif + ifeq ($(USE_PODMAN),1) CONTAINER_RUNTIME=podman else @@ -28,7 +39,7 @@ all: build install_prereq: # Check if the prereqs are there before trying to sudo rpm -q $(PREREQ) || \ - $(SUDO) yum install -y $(PREREQ) + $(SUDO) $(PACKAGE_MANAGER) install $(INSTALL_FLAGS) $(PREREQ) clean: rm -f ./SOURCES/haproxy-${VERSION}.tar.gz @@ -76,6 +87,7 @@ build: $(build_stages) --define "mainversion ${MAINVERSION}" \ --define "version ${VERSION}" \ --define "release ${RELEASE}" \ + --define "_cpu ${CPU}" \ --define "_extra_cflags ${EXTRA_CFLAGS}" \ --define "_topdir %(pwd)/rpmbuild" \ --define "_builddir %{_topdir}/BUILD" \ diff --git a/SPECS/haproxy.spec b/SPECS/haproxy.spec index c6a2430..de153e3 100644 --- a/SPECS/haproxy.spec +++ b/SPECS/haproxy.spec @@ -120,7 +120,12 @@ USE_PROMEX="USE_PROMEX=1" CFLAGS="$CFLAGS %{_extra_cflags}" %endif -%{__make} -j$RPM_BUILD_NCPUS %{?_smp_mflags} ${USE_LUA} CPU="generic" TARGET="linux-glibc" ${systemd_opts} ${pcre_opts} USE_OPENSSL=1 USE_ZLIB=1 ${regparm_opts} ADDINC="$CFLAGS" USE_LINUX_TPROXY=1 USE_THREAD=1 USE_TFO=${USE_TFO} USE_NS=${USE_NS} ${USE_PROMEX} ADDLIB="%{__global_ldflags}" +CPU="generic" +%if "%{_cpu}" != "0" + CPU="%{_cpu}" +%endif + +%{__make} -j$RPM_BUILD_NCPUS %{?_smp_mflags} ${USE_LUA} CPU="${CPU}" TARGET="linux-glibc" ${systemd_opts} ${pcre_opts} USE_OPENSSL=1 USE_ZLIB=1 ${regparm_opts} ADDINC="$CFLAGS" USE_LINUX_TPROXY=1 USE_THREAD=1 USE_TFO=${USE_TFO} USE_NS=${USE_NS} ${USE_PROMEX} ADDLIB="%{__global_ldflags}" %{__make} admin/halog/halog OPTIMIZE="%{optflags} %{__global_ldflags}" From 3759ccfb91ba92911ed8171a977e3604c9509862 Mon Sep 17 00:00:00 2001 From: xliang Date: Sun, 6 Aug 2023 14:42:19 -0700 Subject: [PATCH 2/3] Use ifdef for better code readability --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 562c9d3..6b262f2 100644 --- a/Makefile +++ b/Makefile @@ -20,12 +20,12 @@ else endif HAS_DNF:=$(shell command -v dnf 2> /dev/null) -ifndef HAS_DNF - PACKAGE_MANAGER=yum - INSTALL_FLAGS=-y -else +ifdef HAS_DNF PACKAGE_MANAGER=dnf INSTALL_FLAGS=-y --allowerasing +else + PACKAGE_MANAGER=yum + INSTALL_FLAGS=-y endif ifeq ($(USE_PODMAN),1) From fb33ae2ee46400304c22829df05752f57fd17937 Mon Sep 17 00:00:00 2001 From: xliang Date: Fri, 11 Aug 2023 20:15:01 -0700 Subject: [PATCH 3/3] Update README with instructions on target CPU flag --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd7ae1a..376088f 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,16 @@ Perform the following steps on a build box as a regular user. ### With Prometheus Module support make USE_PROMETHEUS=1 -### Without sudo for yum (for building in Docker) +### Without `sudo` for `yum` (for building in Docker) make NO_SUDO=1 ### With a custom release iteration, e.g. '2' (default '1'): make RELEASE=2 -### Custom CFLAGS, e.g. '-O0' to disable optimization for debug: +### With a custom target `CPU`, e.g. `armv81` + make CPU=armv81 + +### Custom `CFLAGS`, e.g. '-O0' to disable optimization for debug: make EXTRA_CFLAGS=-O0 Resulting RPMs will be in `/opt/rpm-haproxy/rpmbuild/RPMS/x86_64/`