From 07bedb6ceb6e06808ab5b5ee28e0d095e11a1cd5 Mon Sep 17 00:00:00 2001 From: bryan Date: Thu, 27 Aug 2026 10:49:41 +0200 Subject: Make install work on Windows as well as Linux. Windows copies rg.exe to %USERPROFILE%\.local\bin and skips the man page. Linux still installs to /usr/local/bin and share/man. PREFIX overrides the destination on both. --- Makefile | 23 +++++++++++++++++------ README | 7 +++++-- config.mk | 31 +++++++++++++++++-------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index 19ecfb6..1f3971c 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ rg${EXE}: ${OBJ} ${CC} -o $@ ${OBJ} ${LDFLAGS} clean: - rm -f rg rg.exe ${OBJ} rg-${VERSION}.tar.gz + -${RM} rg rg.exe ${OBJ} rg-${VERSION}.tar.gz dist: clean mkdir -p rg-${VERSION} @@ -35,17 +35,28 @@ dist: clean tar -cf - rg-${VERSION} | gzip -c > rg-${VERSION}.tar.gz rm -rf rg-${VERSION} +ifeq ($(OS),Windows_NT) install: all - mkdir -p ${DESTDIR}${PREFIX}/bin - cp -f rg${EXE} ${DESTDIR}${PREFIX}/bin - chmod 755 ${DESTDIR}${PREFIX}/bin/rg${EXE} + -mkdir "$(subst /,\,${DESTDIR}${BINDIR})" + copy /Y rg${EXE} "$(subst /,\,${DESTDIR}${BINDIR}/rg${EXE})" + @echo installed to ${DESTDIR}${BINDIR}/rg${EXE} + +uninstall: + -${RM} "$(subst /,\,${DESTDIR}${BINDIR}/rg.exe)" +else +install: all + mkdir -p ${DESTDIR}${BINDIR} + cp -f rg${EXE} ${DESTDIR}${BINDIR} + chmod 755 ${DESTDIR}${BINDIR}/rg${EXE} mkdir -p ${DESTDIR}${MANPREFIX}/man1 sed "s/VERSION/${VERSION}/g" < rg.1 > ${DESTDIR}${MANPREFIX}/man1/rg.1 chmod 644 ${DESTDIR}${MANPREFIX}/man1/rg.1 + @echo installed to ${DESTDIR}${BINDIR}/rg${EXE} uninstall: - rm -f ${DESTDIR}${PREFIX}/bin/rg \ - ${DESTDIR}${PREFIX}/bin/rg.exe \ + rm -f ${DESTDIR}${BINDIR}/rg \ + ${DESTDIR}${BINDIR}/rg.exe \ ${DESTDIR}${MANPREFIX}/man1/rg.1 +endif .PHONY: all options clean dist install uninstall diff --git a/README b/README index d470444..f84fe26 100644 --- a/README +++ b/README @@ -30,10 +30,13 @@ Linux: Windows (GNU make + clang, from this tree): - make + make install The Windows bits of config.mk are selected when OS=Windows_NT. -Otherwise set CC, EXE=.exe, and CPPFLAGS by hand as commented there. +Install path (override with PREFIX=...): + Windows: %USERPROFILE%\.local\bin (add to PATH if it is not) + Linux: /usr/local/bin (often needs sudo) +make uninstall removes the binary (and the man page on Linux). Running without make diff --git a/config.mk b/config.mk index 845b457..886dedd 100644 --- a/config.mk +++ b/config.mk @@ -3,27 +3,30 @@ VERSION = 1.0 # Customize below to fit your system -# paths -PREFIX = /usr/local -MANPREFIX = ${PREFIX}/share/man +# Install: make install +# Windows: %USERPROFILE%\.local\bin +# Linux: /usr/local/bin +# Override: make PREFIX=... install -# compiler -CC = cc -EXE = LIBS = -# Windows (MinGW-w64): uncomment -# CC = gcc -# EXE = .exe - -# Windows (clang targeting MSVC CRT): uncomment -# CC = clang -# EXE = .exe - ifeq ($(OS),Windows_NT) CC = clang EXE = .exe +PREFIX ?= $(USERPROFILE)/.local +RM = cmd /c del /q +else +CC = cc +EXE = +PREFIX ?= /usr/local +RM = rm -f endif +BINDIR ?= $(PREFIX)/bin +MANPREFIX ?= $(PREFIX)/share/man + +# Windows (MinGW-w64): set CC = gcc instead of clang +# Windows (clang targeting MSVC CRT): default when OS=Windows_NT + CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os LDFLAGS = ${LIBS} -- cgit v1.2.3