about summary refs log tree commit diff stats
path: root/bonus/Makefile
blob: 6365e7c0c68134643d2ee7a42871a4cf561acfaa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#TODO curse XDG
CHA_CGI_DIR ?= "$$HOME/cgi-bin"

prefix = /usr/local

bindir = $(DESTDIR)$(prefix)/bin

.PHONY: none
none:
	@echo "Run make install-{file} to install a script."

stbir2_url=https://raw.githubusercontent.com/nothings/stb/master/stb_image_resize2.h

stbir2/stb_image_resize2.h:
	@printf 'stb_image_resize2.h not found.\n'
	@printf 'Should I download it from $(stbir2_url)? (y/n) '
	@read -r res; if test "$$res" = "y"; then \
	cd stbir2; cha -d "$(stbir2_url)" >stb_image_resize2.h; \
	else exit 1; \
	fi

.PHONY: install-stbir2
install-stbir2: stbir2/stbir2.nim stbir2/stb_image_resize2.h stbir2/stb_image_resize2.c
	mkdir -p $(CHA_CGI_DIR)
	nim c -d:release -d:lto -o:$(CHA_CGI_DIR)/resize stbir2/stbir2.nim

.PHONY: install-git.cgi
install-git.cgi: git.cgi
	mkdir -p $(CHA_CGI_DIR)
	cp git.cgi $(CHA_CGI_DIR)
	./addurimethod git git.cgi
#TODO this will almost never work unless the user is root...
	ln -s $(CHA_CGI_DIR)/git.cgi $(bindir)/gitcha

.PHONY: install-filei.cgi
install-filei.cgi: filei.cgi
	mkdir -p $(CHA_CGI_DIR)
	cp filei.cgi $(CHA_CGI_DIR)

.PHONY: install-libfetch.c
install-libfetch-http.c: $(CHA_CGI_DIR)/libfetch-http
	$(CC) -Wall -O2 -g -std=c89 $< -lfetch -o $@
	./addurimethod http libfetch-http
	./addurimethod https libfetch-http

install-magnet.cgi: magnet.cgi
	mkdir -p $(CHA_CGI_DIR)
	cp magnet.cgi $(CHA_CGI_DIR)
	./addurimethod magnet magnet.cgi

install-trans.cgi: trans.cgi
	mkdir -p $(CHA_CGI_DIR)
	cp trans.cgi $(CHA_CGI_DIR)
	@echo
	@echo 'Add this to your config.toml:'
	@echo
	@echo '[page]'
	@echo "gT = '''"
	@echo 'async () => {'
	@echo '  if (!pager.currentSelection) {'
	@echo '    pager.alert("No selection to translate.");'
	@echo '    return;'
	@echo '  }'
	@echo '  const text = await pager.getSelectionText(pager.currentSelection);'
	@echo '  pager.cursorToggleSelection();'
	@echo '  pager.load(`cgi-bin:trans.cgi?${encodeURIComponent(text)}\n`);'
	@echo '}'
	@echo "'''"