aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-01-28 20:15:31 -0800
committerBruce Hill <bruce@bruce-hill.com>2021-01-28 20:15:31 -0800
commite0af178df1abe3524a6b636405aa140765405fcf (patch)
tree0d0c9f9c5e28b4a9768204d22dd4775dcd0a477f
parent1857870ccb8142d97d63b1adb0eb6318aacc6b33 (diff)
Fixed up some makefile stuff with NAME flag
-rw-r--r--Makefile16
-rw-r--r--bb.c22
2 files changed, 22 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 2dc1b48..015eb29 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ O=-O2
CFLAGS=-std=c99 -Werror -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
CWARN=-Wall -Wpedantic -Wextra -Wsign-conversion -Wtype-limits -Wunused-result
#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
+CFLAGS += '-DBB_NAME="$(NAME)"'
CFILES=draw.c bterm.c
OBJFILES=$(CFILES:.c=.o)
@@ -18,8 +19,8 @@ clean:
.c.o:
$(CC) -c $(CFLAGS) $(CWARN) $(G) $(O) -o $@ $<
-$(NAME): $(OBJFILES) $(NAME).c
- $(CC) $(CFLAGS) $(CWARN) $(G) $(O) -o $@ $(OBJFILES) $(NAME).c
+$(NAME): $(OBJFILES) bb.c
+ $(CC) $(CFLAGS) $(CWARN) $(G) $(O) -o $@ $(OBJFILES) bb.c
install: $(NAME)
@prefix="$(PREFIX)"; \
@@ -29,9 +30,10 @@ install: $(NAME)
fi; \
[ ! "$$prefix" ] && prefix="/usr/local"; \
[ ! "$$sysconfdir" ] && sysconfdir=/etc; \
- mkdir -pv -m 755 "$$prefix/share/man/man1" "$$prefix/bin" "$$sysconfdir/xdg/bb" \
- && cp -rv scripts/* "$$sysconfdir/xdg/bb/" \
- && cp -v bb.1 bbcmd.1 "$$prefix/share/man/man1/" \
+ mkdir -pv -m 755 "$$prefix/man/man1" "$$prefix/bin" "$$sysconfdir/xdg/$(NAME)" \
+ && cp -rv scripts/* "$$sysconfdir/xdg/$(NAME)/" \
+ && cp -v bb.1 "$$prefix/man/man1/$(NAME).1" \
+ && cp -v bbcmd.1 "$$prefix/man/man1/bbcmd.1" \
&& rm -f "$$prefix/bin/$(NAME)" \
&& cp -v $(NAME) "$$prefix/bin/"
@@ -44,7 +46,7 @@ uninstall:
[ ! "$$prefix" ] && prefix="/usr/local"; \
[ ! "$$sysconfdir" ] && sysconfdir=/etc; \
echo "Deleting..."; \
- rm -rvf "$$prefix/bin/$(NAME)" "$$prefix/share/man/man1/bb.1" "$$prefix/share/man/man1/bbcmd.1" "$$sysconfdir/xdg/bb"; \
- printf "\033[1mIf you created any config files in ~/.config/bb, you may want to delete them manually.\033[0m\n"
+ rm -rvf "$$prefix/bin/$(NAME)" "$$prefix/man/man1/$(NAME).1" "$$prefix/man/man1/bbcmd.1" "$$sysconfdir/xdg/$(NAME)"; \
+ printf "\033[1mIf you created any config files in ~/.config/$(NAME), you may want to delete them manually.\033[0m\n"
.PHONY: all, clean, install, uninstall
diff --git a/bb.c b/bb.c
index c753955..71a53fb 100644
--- a/bb.c
+++ b/bb.c
@@ -23,6 +23,10 @@
#include "bb.h"
#include "draw.h"
+#ifndef BB_NAME
+#define BB_NAME "bb"
+#endif
+
// Functions
void bb_browse(bb_t *bb, const char *initial_path);
static void check_cmdfile(bb_t *bb);
@@ -84,8 +88,8 @@ static const struct termios default_termios = {
.c_cc[VTIME] = 0,
};
-static const char *description_str = "bb - an itty bitty console TUI file browser\n";
-static const char *usage_str = "Usage: bb (-h/--help | -v/--version | -s | -d | -0 | +command)* [[--] directory]\n";
+static const char *description_str = BB_NAME" - an itty bitty console TUI file browser\n";
+static const char *usage_str = "Usage: "BB_NAME" (-h/--help | -v/--version | -s | -d | -0 | +command)* [[--] directory]\n";
// Variables used within this file to track global state
@@ -961,9 +965,9 @@ static void set_title(bb_t *bb)
{
char *home = getenv("HOME");
if (home && strncmp(bb->path, home, strlen(home)) == 0)
- fprintf(tty_out, "\033]2;bb: ~%s\007", bb->path + strlen(home));
+ fprintf(tty_out, "\033]2;"BB_NAME": ~%s\007", bb->path + strlen(home));
else
- fprintf(tty_out, "\033]2;bb: %s\007", bb->path);
+ fprintf(tty_out, "\033]2;"BB_NAME": %s\007", bb->path);
}
/*
@@ -1066,7 +1070,7 @@ int main(int argc, char *argv[])
return 0;
} else if (strcmp(argv[i], "--version") == 0) {
version:
- printf("bb " BB_VERSION "\n");
+ printf(BB_NAME" "BB_VERSION"\n");
return 0;
} else if (argv[i][0] == '-' && argv[i][1] != '-') {
for (char *c = &argv[i][1]; *c; c++) {
@@ -1096,10 +1100,10 @@ int main(int argc, char *argv[])
// Set up environment variables
// Default values
setenv("TMPDIR", "/tmp", 0);
- sprintf(cmdfilename, "%s/bb.XXXXXX", getenv("TMPDIR"));
+ sprintf(cmdfilename, "%s/"BB_NAME".XXXXXX", getenv("TMPDIR"));
int cmdfd;
if ((cmdfd = mkostemp(cmdfilename, O_APPEND)) == -1)
- err("Couldn't create bb command file: '%s'", cmdfilename);
+ err("Couldn't create "BB_NAME" command file: '%s'", cmdfilename);
setenv("BBCMD", cmdfilename, 1);
char xdg_config_home[PATH_MAX], xdg_data_home[PATH_MAX];
sprintf(xdg_config_home, "%s/.config", getenv("HOME"));
@@ -1120,11 +1124,11 @@ int main(int argc, char *argv[])
setenv("BBPATH", bbpath, 1);
}
if (getenv("BBPATH")) {
- if (asprintf(&newpath, "%s/bb:%s/scripts:%s",
+ if (asprintf(&newpath, "%s/"BB_NAME":%s/scripts:%s",
getenv("XDG_CONFIG_HOME"), getenv("BBPATH"), getenv("PATH")) < 0)
err("Could not allocate memory for PATH");
} else {
- if (asprintf(&newpath, "%s/bb:%s/xdg/bb:%s",
+ if (asprintf(&newpath, "%s/"BB_NAME":%s/xdg/"BB_NAME":%s",
getenv("XDG_CONFIG_HOME"), getenv("sysconfdir"), getenv("PATH")) < 0)
err("Could not allocate memory for PATH");
}