diff options
| author | Bruce Hill <bruce@stainless.com> | 2025-08-22 13:24:42 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@stainless.com> | 2025-08-22 13:24:42 -0400 |
| commit | fe6da3015573079229a0da3166eb4b5f36520dbb (patch) | |
| tree | fb9e45632256959f826cd35fdd7d75bcaf85fc90 | |
| parent | 2d81f92fbadb0d60243cbcad7c4a5236815fdbbc (diff) | |
Update install process to use configuration script
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 35 | ||||
| -rw-r--r-- | bp.c | 6 | ||||
| -rw-r--r-- | configure.sh | 32 |
4 files changed, 60 insertions, 16 deletions
@@ -1,7 +1,8 @@ *.o *.so tags -bp +/bp .* !.gitignore /Lua/builtins.h +config.mk @@ -1,9 +1,23 @@ +ifeq ($(wildcard config.mk),) +all: config.mk + $(MAKE) all +install: config.mk + $(MAKE) install +install-files: config.mk + $(MAKE) install-files +install-lib: config.mk + $(MAKE) install-lib +test: config.mk + $(MAKE) test +config.mk: configure.sh + bash ./configure.sh +else + +include config.mk NAME=bp CC=cc -PREFIX=/usr/local -SYSCONFDIR=/etc CFLAGS=-std=c2x -Werror -D_GNU_SOURCE -fPIC -flto=auto -fvisibility=hidden \ - -fsanitize=signed-integer-overflow -fno-sanitize-recover -DSYSCONFDIR='"$(SYSCONFDIR)"' + -fsanitize=signed-integer-overflow -fno-sanitize-recover -DBP_PREFIX='"$(PREFIX)"' CWARN=-Wall -Wextra -Wno-format -Wshadow # -Wpedantic -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \ # -Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \ @@ -34,7 +48,7 @@ $(NAME): $(OBJFILES) bp.c $(LIBFILE): pattern.o utils.o match.o utf8.o $(CC) $^ $(ALL_FLAGS) -Wl,-soname,$(LIBFILE) -shared -o $@ -all: $(NAME) $(LIBFILE) bp.1 lua +all: $(NAME) bp.1 %.o: %.c %.h utf8.h $(CC) -c $(ALL_FLAGS) -o $@ $< @@ -80,8 +94,8 @@ splint: # $(CFILES) bp.c install: $(NAME) bp.1 - mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/bin" "$(SYSCONFDIR)/$(NAME)" - cp -r grammars/* "$(SYSCONFDIR)/$(NAME)/" + mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/bin" "$(PREFIX)/share/$(NAME)" + cp -r grammars "$(PREFIX)/share/$(NAME)/" cp bp.1 "$(PREFIX)/man/man1/$(NAME).1" rm -f "$(PREFIX)/bin/$(NAME)" cp $(NAME) "$(PREFIX)/bin/" @@ -92,12 +106,7 @@ install-lib: $(LIBFILE) bp.1 cp pattern.h match.h "$(PREFIX)/include/$(NAME)" uninstall: - rm -rf "$(PREFIX)/bin/$(NAME)" "$(PREFIX)/man/man1/$(NAME).1" "$(SYSCONFDIR)/$(NAME)" - @if [ -d ~/.config/$(NAME) ]; then \ - printf 'Config files exist in ~/.config/$(NAME) Do you want to delete them? [Y/n] '; \ - read confirm; \ - [ "$$confirm" != n ] && rm -rf ~/.config/$(NAME); \ - fi + rm -rf "$(PREFIX)/bin/$(NAME)" "$(PREFIX)/man/man1/$(NAME).1" "$(PREFIX)/share/$(NAME)" profile_grammar: bp perf stat -r 100 -e L1-dcache-loads,L1-dcache-load-misses,L1-dcache-stores -e cycles ./bp -f plain -g bp -p Grammar grammars/bp.bp >/dev/null @@ -105,4 +114,6 @@ profile_grammar: bp profile_pattern: bp perf stat -r 1 -e L1-dcache-loads,L1-dcache-load-misses,L1-dcache-stores -e cycles ./bp -f plain -p 'id parens' /usr/include/*.h >/dev/null +endif + .PHONY: all clean install install-lib uninstall leaktest splint test tutorial lua profile luatest @@ -557,9 +557,9 @@ int main(int argc, char *argv[]) bp_pat_t *pattern = NULL; // Load builtins: - file_t *builtins_file = load_file(&loaded_files, SYSCONFDIR"/"BP_NAME"/builtins.bp"); + file_t *builtins_file = load_file(&loaded_files, BP_PREFIX"/"BP_NAME"/builtins.bp"); if (builtins_file) defs = load_grammar(defs, builtins_file); - file_t *local_file = load_filef(&loaded_files, "%s/.config/"BP_NAME"/builtins.bp", getenv("HOME")); + file_t *local_file = load_file(&loaded_files, BP_PREFIX"/share/"BP_NAME"/grammars/builtins.bp"); if (local_file) defs = load_grammar(defs, local_file); bool explicit_case_sensitivity = false; @@ -605,7 +605,7 @@ int main(int argc, char *argv[]) if (f == NULL) f = load_filef(&loaded_files, "%s/.config/"BP_NAME"/%s.bp", getenv("HOME"), flag); if (f == NULL) - f = load_filef(&loaded_files, SYSCONFDIR"/"BP_NAME"/%s.bp", flag); + f = load_filef(&loaded_files, BP_PREFIX"/share/"BP_NAME"/grammars/%s.bp", flag); if (f == NULL) errx(EXIT_FAILURE, "Couldn't find grammar: %s", flag); defs = load_grammar(defs, f); // Keep in memory for debug output diff --git a/configure.sh b/configure.sh new file mode 100644 index 0000000..13c3830 --- /dev/null +++ b/configure.sh @@ -0,0 +1,32 @@ +#!/bin/env bash + +error() { + printf "\033[31;1m%s\033[m\n" "$@" + exit 1 +} + +default_prefix='/usr/local' +if echo "$PATH" | tr ':' '\n' | grep -qx "$HOME/.local/bin"; then + default_prefix="~/.local" +fi + +printf '\033[1mChoose where to install bp (default: %s):\033[m ' "$default_prefix" +read PREFIX +if [ -z "$PREFIX" ]; then PREFIX="$default_prefix"; fi +PREFIX="${PREFIX/#\~/$HOME}" + +if ! echo "$PATH" | tr ':' '\n' | grep -qx "$PREFIX/bin"; then + error "Your \$PATH does not include this prefix, so you won't be able to run tomo!" \ + "Please put this in your .profile or .bashrc: export PATH=\"$PREFIX/bin:\$PATH\"" +fi + +if command -v doas >/dev/null; then + SUDO=doas +else + SUDO=sudo +fi + +cat <<END >config.mk +PREFIX=$PREFIX +SUDO=$SUDO +END |
