Skip to content

Commit b949b93

Browse files
authored
Merge pull request #3 from budlabs/next
re-added all the commandline options, oopsi
2 parents 02b05a1 + 51efabe commit b949b93

File tree

6 files changed

+197
-94
lines changed

6 files changed

+197
-94
lines changed

Makefile GNUmakefile

+100-57
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
1-
.PHONY: clean check all install uninstall \
2-
install-dev uninstall-dev
1+
.PHONY: all install-dev uninstall-dev
32

43
.ONESHELL:
5-
.DEFAULT_GOAL := all
6-
7-
SHELL := /bin/bash
4+
.DEFAULT_GOAL := all
85

6+
SHELL := /bin/bash
97
CUSTOM_TARGETS =
108

11-
PREFIX := /usr
129
NAME := $(notdir $(realpath .))
1310
VERSION := 0
1411
UPDATED := $(shell date +'%Y-%m-%d')
15-
CREATED := $(UPDATED)
1612
AUTHOR := anon
17-
CONTACT := address
18-
ORGANISATION :=
1913
CACHE_DIR := .cache
2014
DOCS_DIR := docs
2115
CONF_DIR := conf
2216
AWK_DIR := awklib
2317
FUNCS_DIR := func
18+
FILE_EXT := .sh
2419
INDENT := $(shell echo -e " ")
2520
USAGE = $(NAME) [OPTIONS]
2621
OPTIONS_FILE := options
27-
MANPAGE = $(NAME).1
28-
MONOLITH = _$(NAME).sh
29-
BASE := _init.sh
22+
MONOLITH = _$(NAME)$(FILE_EXT)
23+
BASE := _init$(FILE_EXT)
3024
SHBANG := \#!/bin/bash
3125
OPTIONS_ARRAY_NAME := _o
32-
MANPAGE_OUT = _$(MANPAGE)
3326
FUNC_STYLE := "() {"
3427

35-
ifneq ($(wildcard config.mak),)
28+
config_mak := config.mak
29+
help_table := $(CACHE_DIR)/help_table.txt
30+
long_help := $(CACHE_DIR)/long_help.md
31+
getopt := $(CACHE_DIR)/getopt
32+
print_help := $(CACHE_DIR)/print_help$(FILE_EXT)
33+
print_version := $(CACHE_DIR)/print_version$(FILE_EXT)
34+
35+
ifneq ($(wildcard $(config_mak)),)
3636
include config.mak
37+
else
38+
config_mak :=
3739
endif
3840

39-
manpage_section = $(subst .,,$(suffix $(MANPAGE)))
40-
function_createconf := $(FUNCS_DIR)/_createconf.sh
41-
function_awklib := $(FUNCS_DIR)/_awklib.sh
41+
ifeq ($(wildcard $(OPTIONS_FILE)),)
42+
OPTIONS_FILE :=
43+
help_table :=
44+
long_help :=
45+
getopt :=
46+
print_help :=
47+
print_version :=
48+
endif
49+
50+
function_createconf := $(FUNCS_DIR)/_createconf$(FILE_EXT)
51+
function_awklib := $(FUNCS_DIR)/_awklib$(FILE_EXT)
4252

4353
ifneq ($(wildcard $(CONF_DIR)/*),)
4454
include_createconf = $(function_createconf)
45-
conf_dirs = $(shell find $(CONF_DIR) -type d)
46-
conf_files = $(shell find $(CONF_DIR) -type f)
55+
conf_dirs = $(patsubst ./%,%,$(shell find "./$(CONF_DIR)" -type d))
56+
conf_files = $(patsubst ./%,%,$(shell find "./$(CONF_DIR)" -type f))
4757
else
4858
$(shell rm -f $(function_createconf))
4959
endif
@@ -59,8 +69,9 @@ option_docs = $(wildcard $(DOCS_DIR)/options/*)
5969

6070
generated_functions := $(function_err) $(include_createconf) $(include_awklib)
6171
function_files := \
62-
$(generated_functions) \
63-
$(filter-out $(generated_functions),$(wildcard $(FUNCS_DIR)/*))
72+
$(generated_functions) \
73+
$(filter-out $(generated_functions),$(wildcard $(FUNCS_DIR)/*))
74+
6475

6576
# this hack writes 1 or 0 to the file .cache/got_func
6677
# depending on existence of files in FUNC_DIR
@@ -95,36 +106,35 @@ install-dev: $(BASE) $(NAME)
95106
uninstall-dev: $(PREFIX)/bin/$(NAME)
96107
rm $^
97108

98-
check: all
99-
shellcheck $(MONOLITH)
100-
101-
$(BASE): config.mak $(CACHE_DIR)/getopt $(CACHE_DIR)/print_help.sh $(CACHE_DIR)/print_version.sh $(CACHE_DIR)/got_func
109+
$(BASE): $(getopt) $(print_help) $(print_version) $(CACHE_DIR)/got_func
102110
@$(info making $@)
103111
{
104112
printf '%s\n' '$(SHBANG)' ''
105113

106-
grep -vhE -e '^#!/' $(CACHE_DIR)/print_version.sh | sed '0,/2/s//3/'
107-
grep -vhE -e '^#!/' $(CACHE_DIR)/print_help.sh | sed '0,/2/s//3/'
114+
[[ -f $${pv:=$(print_version)} ]] \
115+
&& grep -vhE -e '^#!/' $(print_version) | sed '0,/2/s//3/'
116+
[[ -f $${ph:=$(print_help)} ]] \
117+
&& grep -vhE -e '^#!/' $(print_help) | sed '0,/2/s//3/'
108118

109119
echo
110120

111-
[[ -d $(FUNCS_DIR) ]] && {
121+
[[ -d $${fd:=$(FUNCS_DIR)} ]] && {
112122
printf '%s\n' \
113123
'for ___f in "$$__dir/$(FUNCS_DIR)"/*; do' \
114124
'$(INDENT). "$$___f" ; done ; unset -v ___f'
115125
}
116126

117127
echo
118128

119-
cat $(CACHE_DIR)/getopt
129+
[[ -f $${go:=$(getopt)} ]] && cat $(getopt)
120130

121131
echo "((BASHBUD_VERBOSE)) && _o[verbose]=1"
122132
echo
123133

124134
echo 'main "$$@"'
125135
} > $@
126136

127-
$(MONOLITH): $(CACHE_DIR)/print_version.sh $(NAME) $(CACHE_DIR)/print_help.sh $(function_files) $(CACHE_DIR)/getopt
137+
$(MONOLITH): $(print_version) $(NAME) $(print_help) $(function_files) $(getopt)
128138
@$(info making $@)
129139
{
130140
printf '%s\n' '$(SHBANG)' ''
@@ -141,29 +151,12 @@ $(MONOLITH): $(CACHE_DIR)/print_version.sh $(NAME) $(CACHE_DIR)/print_help.sh $(
141151

142152
chmod +x $@
143153

144-
$(CACHE_DIR)/copyright.txt: config.mak
145-
@$(info making $@)
146-
year_created=$(CREATED) year_created=$${year_created%%-*}
147-
year_updated=$$(date +'%Y')
148-
149-
copy_text="Copyright (c) "
150-
151-
((year_created == year_updated)) \
152-
&& copy_text+=$$year_created \
153-
|| copy_text+="$${year_created}-$${year_updated}, $(AUTHOR)"
154-
155-
[[ $${org:=$(ORGANISATION)} ]] \
156-
&& copy_text+=" of $(ORGANISATION) "
157-
158-
printf '%s\n' \
159-
"$$copy_text" "SPDX-License-Identifier: $(LICENSE)" > $@
160-
161154
# if a file in docs/options contains more than
162155
# 2 lines, it will get added to the file .cache/long_help.md
163156
# like this:
164157
# ### -s, --long-option ARG
165158
# text in docs/options/long-option after the first 2 lines
166-
$(CACHE_DIR)/long_help.md: $(CACHE_DIR)/options_in_use $(option_docs)
159+
$(long_help): $(CACHE_DIR)/options_in_use $(option_docs)
167160
@$(info making $@)
168161
for option in $(file < $(CACHE_DIR)/options_in_use); do
169162
[[ $$(wc -l < $(DOCS_DIR)/options/$$option) -lt 2 ]] \
@@ -179,7 +172,7 @@ $(CACHE_DIR)/synopsis.txt: $(OPTIONS_FILE) | $(CACHE_DIR)/
179172
@$(info making $@)
180173
sed 's/^/$(NAME) /g;s/*//g' $< > $@
181174

182-
$(CACHE_DIR)/help_table.txt: $(CACHE_DIR)/long_help.md
175+
$(help_table): $(long_help)
183176
@$(info making $@)
184177
for option in $$(cat $(CACHE_DIR)/options_in_use); do
185178
[[ -f $(CACHE_DIR)/options/$$option ]] \
@@ -193,7 +186,7 @@ $(CACHE_DIR)/help_table.txt: $(CACHE_DIR)/long_help.md
193186
paste <(echo "$$frag") <(echo "$$desc") | tr -d '\t'
194187
done > $@
195188

196-
$(CACHE_DIR)/print_version.sh: config.mak | $(CACHE_DIR)/
189+
$(print_version): $(config_mak) | $(CACHE_DIR)/
197190
@$(info making $@)
198191
echo $(SHBANG)
199192
fstyle=$(FUNC_STYLE)
@@ -205,7 +198,7 @@ $(CACHE_DIR)/print_version.sh: config.mak | $(CACHE_DIR)/
205198
"}" \
206199
"" >> $@
207200

208-
$(CACHE_DIR)/print_help.sh: $(CACHE_DIR)/help_table.txt $(CACHE_DIR)/synopsis.txt
201+
$(print_help): $(help_table) $(CACHE_DIR)/synopsis.txt
209202
@$(info making $@)
210203
{
211204
echo $(SHBANG)
@@ -219,7 +212,7 @@ $(CACHE_DIR)/print_help.sh: $(CACHE_DIR)/help_table.txt $(CACHE_DIR)/synopsis.tx
219212
printf '%s\n' 'usage: $(USAGE)' ''
220213
echo
221214
fi
222-
cat $(CACHE_DIR)/help_table.txt
215+
cat $(help_table)
223216
printf '%s\n' 'EOB' '}'
224217
} > $@
225218

@@ -283,11 +276,11 @@ $(FUNCS_DIR)/:
283276
@$(info creating $(FUNCS_DIR)/ dir)
284277
mkdir -p $(FUNCS_DIR)
285278

286-
$(CACHE_DIR)/options_in_use $(CACHE_DIR)/getopt &: $(OPTIONS_FILE) | $(CACHE_DIR)/
279+
$(CACHE_DIR)/options_in_use $(getopt) &: $(OPTIONS_FILE) | $(CACHE_DIR)/
287280
@$(info parsing $(OPTIONS_FILE))
288281
mkdir -p $(DOCS_DIR)/options
289282
gawk '
290-
BEGIN { RS=" |\\n" }
283+
BEGIN { RS=" |\\n" ; longest = length("version")}
291284

292285
/./ {
293286
if (match($$0,/^\[?--([^][|[:space:]]+)(([|]-)(\S))?\]?$$/,ma))
@@ -447,11 +440,61 @@ $(CACHE_DIR)/options_in_use $(CACHE_DIR)/getopt &: $(OPTIONS_FILE) | $(CACHE_DIR
447440
}
448441
' $(OPTIONS_FILE) \
449442
cache=$(CACHE_DIR) \
450-
name=$(NAME) > $(CACHE_DIR)/getopt
443+
name=$(NAME) > $(getopt)
444+
445+
$(CACHE_DIR)/copyright.txt: $(config_mak)
446+
@$(info making $@)
447+
year_created=$(CREATED) year_created=$${year_created%%-*}
448+
year_updated=$$(date +'%Y')
449+
author="$(AUTHOR)" org=$(ORGANISATION)
450+
451+
copy_text="Copyright (c) "
452+
453+
((year_created == year_updated)) \
454+
&& copy_text+=$$year_created \
455+
|| copy_text+="$${year_created}-$${year_updated}"
456+
457+
[[ $$author ]] && copy_text+=", $$author"
458+
[[ $$org ]] && copy_text+=" of $$org "
459+
460+
printf '%s\n' \
461+
"$$copy_text" "SPDX-License-Identifier: $(LICENSE)" > $@
462+
463+
.PHONY: check
464+
check: all
465+
shellcheck $(MONOLITH)
466+
467+
.PHONY: install uninstall
468+
469+
installed_script := $(DESTDIR)$(PREFIX)/bin/$(NAME)
470+
installed_license := $(DESTDIR)$(PREFIX)/share/licenses/$(NAME)/LICENSE
471+
installed_manpage := \
472+
$(DESTDIR)$(PREFIX)/share/man/man$(subst .,,$(suffix $(MANPAGE)))/$(MANPAGE)
473+
474+
install: all
475+
@[[ -f $${manpage:=$(MANPAGE)} ]] && {
476+
echo "install -Dm644 $(MANPAGE) $(installed_manpage)"
477+
install -Dm644 $(MANPAGE) $(installed_manpage)
478+
}
479+
[[ -f LICENSE ]] && {
480+
echo "install -Dm644 LICENSE $(installed_license)"
481+
install -Dm644 LICENSE $(installed_license)
482+
}
483+
484+
echo "install -Dm755 $(MONOLITH) $(installed_script)"
485+
install -Dm755 $(MONOLITH) $(installed_script)
486+
487+
uninstall:
488+
@for f in $(installed_script) $(installed_manpage) $(installed_license); do
489+
[[ -f $$f ]] || continue
490+
echo "rm $$f"
491+
rm "$$f"
492+
done
493+
451494

452-
other_maks := $(filter-out config.mak,$(wildcard *.mak))
495+
other_maks := $(filter-out $(config_mak),$(wildcard *.mak))
453496
-include $(other_maks)
454497

455498
# by having all: last, it is possible to add CUSTOM_TARGETS
456-
# in "other_maks", and have them automatically apply
499+
# in 'other_maks', and have them automatically apply
457500
all: $(CUSTOM_TARGETS) $(MONOLITH) $(BASE)

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,16 @@ updated: 2020-06-22 by budRich
6060

6161
## usage
6262
ssrt [OPTIONS]
63-
-h, --help | print help and exit
64-
-v, --version | print version info and exit
63+
-e, --codec CODEC | CODEC defaults to h264 (or vp8 for webm).
64+
-c, --config-dir DIR | set ssr conifg directory
65+
-n, --container CONTAINER | set CONTAINER type. example containers: mkv and webm.
66+
-d, --delay SECONDS | delay start of recording
67+
-h, --help | print help and exit
68+
-i, --input-file FILE | change default (/tmp/ssrt/in) inputfile.
69+
-m, --mute | disables audio in recording
70+
-p, --pause | toggle play/pause or start a new recording.
71+
-s, --select | select recording area before recording starts.
72+
-v, --version | print version info and exit
6573

6674
*event scripts* are stored in
6775
**SSR\_CONFIG\_DIR**/events\* ,

config.mak

+5-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
NAME := ssrt
22
DESCRIPTION := simplescreenreocrder - now even simpler
3-
VERSION := 2022.05.24.2
3+
VERSION := 2022.06.14.1
44
CREATED := 2020-06-19
5-
UPDATED := 2022-05-24
5+
UPDATED := 2022-06-14
66
AUTHOR := budRich
77
ORGANISATION := budlabs
88
CONTACT := https://github.com/budlabs/ssrt
@@ -38,12 +38,11 @@ MANPAGE_DEPS = \
3838
$(DOCS_DIR)/description.md \
3939
$(CACHE_DIR)/copyright.txt
4040

41-
# CUSTOM_TARGETS += $(MANPAGE_OUT)
42-
MANPAGE_OUT = $(MANPAGE)
41+
MANPAGE := $(NAME).1
4342
.PHONY: manpage
44-
manpage: $(MANPAGE_OUT)
43+
manpage: $(MANPAGE)
4544

46-
$(MANPAGE_OUT): config.mak $(MANPAGE_DEPS)
45+
$(MANPAGE): config.mak $(MANPAGE_DEPS)
4746
@$(info making $@)
4847
uppercase_name=$(NAME)
4948
uppercase_name=$${uppercase_name^^}
@@ -72,29 +71,3 @@ $(MANPAGE_OUT): config.mak $(MANPAGE_DEPS)
7271
cat $(DOCS_DIR)/manpage_footer.md
7372

7473
} | go-md2man > $@
75-
76-
77-
# --- INSTALLATION RULES --- #
78-
installed_manpage = $(DESTDIR)$(PREFIX)/share/man/man$(manpage_section)/$(MANPAGE)
79-
installed_script := $(DESTDIR)$(PREFIX)/bin/$(NAME)
80-
installed_license := $(DESTDIR)$(PREFIX)/share/licenses/$(NAME)/$(LICENSE)
81-
82-
install: all
83-
@[[ -n $${manpage:=$(MANPAGE_OUT)} && -f $$manpage ]] && {
84-
echo "install -Dm644 $(MANPAGE_OUT) $(installed_manpage)"
85-
install -Dm644 $(MANPAGE_OUT) $(installed_manpage)
86-
}
87-
[[ -n $${license:=$(LICENSE)} && -f $$license ]] && {
88-
echo "install -Dm644 $(LICENSE) $(installed_license)"
89-
install -Dm644 $(LICENSE) $(installed_license)
90-
}
91-
92-
echo "install -Dm755 $(MONOLITH) $(installed_script)"
93-
install -Dm755 $(MONOLITH) $(installed_script)
94-
95-
uninstall:
96-
@for f in $(installed_script) $(installed_manpage) $(installed_license); do
97-
[[ -f $$f ]] || continue
98-
echo "rm $$f"
99-
rm "$$f"
100-
done

options

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
[--pause|-p] [--delay|-d SECONDS] [--select|-s] [--config-dir|-c DIR] [--input-file|-i FILE] [--mute|-m] [--container|-n CONTAINER] [--codec|-e CODEC]
12
--help|-h
23
--version|-v

0 commit comments

Comments
 (0)