From 5e7fbf18953e0a907146eabefbba6c4fcd794d20 Mon Sep 17 00:00:00 2001 From: Gregory Gauthier Date: Fri, 6 Mar 2026 17:01:00 +0000 Subject: [PATCH] build: add Makefile with standard targets - Introduce Makefile supporting build, test, install, uninstall, clean - Add variables for PREFIX and DESTDIR - Update README.md with Makefile usage instructions --- Makefile | 38 ++++++++++++++++++++++++++++++++++++++ README.md | 18 ++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0181e88 --- /dev/null +++ b/Makefile @@ -0,0 +1,38 @@ +# Makefile for passwdgen +# Supports: build, test, install, uninstall, clean +# Vars: PREFIX=/usr/local make install +# DESTDIR=/tmp/staging make install + +PREFIX ?= /usr/local +BUILD_DIR ?= build +JOBS ?= $(shell sysctl -n hw.ncpu 2>/dev/null || echo 4) + +.PHONY: all build test clean install uninstall + +all: build + +build: + cmake -S . -B $(BUILD_DIR) -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release + cmake --build $(BUILD_DIR) -j$(JOBS) + +test: build + ctest --test-dir $(BUILD_DIR) -V + +clean: + rm -rf $(BUILD_DIR) + +install: build + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp $(BUILD_DIR)/passwdgen $(DESTDIR)$(PREFIX)/bin/passwdgen + chmod 755 $(DESTDIR)$(PREFIX)/bin/passwdgen + mkdir -p $(DESTDIR)$(PREFIX)/lib + cp $(BUILD_DIR)/libpasswdgen_lib.a $(DESTDIR)$(PREFIX)/lib/libpasswdgen_lib.a + chmod 644 $(DESTDIR)$(PREFIX)/lib/libpasswdgen_lib.a + mkdir -p $(DESTDIR)$(PREFIX)/include + cp include/passwdgen.h $(DESTDIR)$(PREFIX)/include/passwdgen.h + chmod 644 $(DESTDIR)$(PREFIX)/include/passwdgen.h + +uninstall: + rm -f $(DESTDIR)$(PREFIX)/bin/passwdgen + rm -f $(DESTDIR)$(PREFIX)/lib/libpasswdgen_lib.a + rm -f $(DESTDIR)$(PREFIX)/include/passwdgen.h \ No newline at end of file diff --git a/README.md b/README.md index 00a8f42..f991857 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,21 @@ or directly: ```bash ./tests/passwdgen_test ``` + + + +## Makefile + +Now supports standard targets via `Makefile`: + +```bash +make # alias for build (Release) +make test # build + run tests +sudo make install # to /usr/local/bin, /lib, /include +make uninstall # remove installed files +make clean # rm -rf build/ +``` + +Variables: +- `PREFIX=/opt/myprefix make install` +- `DESTDIR=/tmp/root PREFIX=/usr make install` (packaging) \ No newline at end of file