-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
240 lines (215 loc) · 8 KB
/
Makefile
File metadata and controls
240 lines (215 loc) · 8 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# bash-logger Makefile
# Installation directories
PREFIX ?= /usr/local
DESTDIR ?=
LIBDIR = $(PREFIX)/lib/bash-logger
DOCDIR = $(PREFIX)/share/doc/bash-logger
# User installation directories
USER_PREFIX ?= $(HOME)/.local
USER_LIBDIR = $(USER_PREFIX)/lib/bash-logger
USER_DOCDIR = $(USER_PREFIX)/share/doc/bash-logger
# Files to install
LIBRARY = logging.sh
DOCS = README.md LICENSE CHANGELOG.md CONTRIBUTING.md CODE_OF_CONDUCT.md SECURITY.md
# Shell for execution
SHELL := /bin/bash
.PHONY: all help install install-user uninstall uninstall-user test test-quiet test-junit coverage sonar sonar-analysis lint lint-shell lint-markdown check demo demos clean pre-commit
all: help
help:
@echo "bash-logger - Installation and development targets"
@echo ""
@echo "Installation targets:"
@echo " make install Install system-wide (requires root/sudo)"
@echo " make install-user Install for current user only"
@echo " make uninstall Remove system-wide installation"
@echo " make uninstall-user Remove user installation"
@echo ""
@echo "Development targets:"
@echo " make test Run test suite"
@echo " make test-junit Run tests with JUnit XML output"
@echo " make coverage Run tests with kcov coverage"
@echo " make sonar Run SonarQube scanner (syncs version from logging.sh)"
@echo " make sonar-analysis Run coverage, JUnit tests, and SonarQube scan"
@echo " make demo Run all demo scripts"
@echo " make lint Run all linters (shellcheck + markdownlint)"
@echo " make lint-shell Run shellcheck only"
@echo " make lint-markdown Run markdownlint only"
@echo " make check Run tests and all linters"
@echo " make pre-commit Run pre-commit hooks on all files"
@echo " make clean Remove temporary files"
@echo ""
@echo "Note: pre-commit must be installed to run linting and pre-commit targets."
@echo ""
@echo "Installation options:"
@echo " PREFIX=/path Change installation prefix (default: /usr/local)"
@echo " USER_PREFIX=/path Change user prefix (default: ~/.local)"
@echo ""
@echo "Examples:"
@echo " make install PREFIX=/opt"
@echo " sudo make install"
@echo " make install-user"
@echo " make check # Run before committing"
install:
@echo "Installing bash-logger to $(DESTDIR)$(BINDIR)..."
install -d "$(DESTDIR)$(BINDIR)"
install -m 644 "$(LIBRARY)" "$(DESTDIR)$(BINDIR)/$(LIBRARY)"
@echo "Installing documentation to $(DESTDIR)$(DOCDIR)..."
@install -d "$(DESTDIR)$(DOCDIR)"
@for doc in $(DOCS); do \
if [ -f "$$doc" ]; then \
install -m 644 "$$doc" "$(DESTDIR)$(DOCDIR)/"; \
fi; \
done
@echo ""
@echo "Installation complete!"
@echo ""
@echo "To use bash-logger, add this to your script:"
@echo " source $(LIBDIR)/logging.sh"
@echo ""
@echo "Or add to your ~/.bashrc:"
@echo " source $(LIBDIR)/logging.sh"
install-user:
@echo "Installing bash-logger to $(USER_BINDIR)..."
install -d "$(USER_BINDIR)"
install -m 644 "$(LIBRARY)" "$(USER_BINDIR)/$(LIBRARY)"
@echo "Installing documentation to $(USER_DOCDIR)..."
@install -d "$(USER_DOCDIR)"
@for doc in $(DOCS); do \
if [ -f "$$doc" ]; then \
install -m 644 "$$doc" "$(USER_DOCDIR)/"; \
fi; \
done
@echo ""
@echo "Installation complete!"
@echo ""
@echo "To use bash-logger, add this to your script:"
@echo " source $(USER_LIBDIR)/logging.sh"
@echo ""
@echo "Or add to your ~/.bashrc:"
@echo " source $(USER_LIBDIR)/logging.sh"
uninstall:
@echo "Removing bash-logger installation from $(DESTDIR)$(PREFIX)..."
rm -f "$(DESTDIR)$(LIBDIR)/$(LIBRARY)"
rmdir "$(DESTDIR)$(LIBDIR)" 2>/dev/null || true
rm -rf "$(DESTDIR)$(DOCDIR)"
@echo "Uninstall complete!"
uninstall-user:
@echo "Removing bash-logger installation from $(USER_PREFIX)..."
rm -f "$(USER_LIBDIR)/$(LIBRARY)"
rmdir "$(USER_LIBDIR)" 2>/dev/null || true
rm -rf "$(USER_DOCDIR)"
@echo "Uninstall complete!"
test:
@if [ -d tests ]; then \
echo "Running test suite..."; \
if [ -f tests/run_tests.sh ]; then \
if [ ! -x tests/run_tests.sh ]; then \
chmod +x tests/run_tests.sh || { echo "Error: Cannot make test runner executable"; exit 1; }; \
fi; \
./tests/run_tests.sh; \
elif command -v bats >/dev/null 2>&1; then \
bats tests/; \
else \
echo "No test runner found. Install bats or create tests/run_tests.sh"; \
exit 1; \
fi; \
else \
echo "No tests directory found"; \
exit 1; \
fi
test-quiet:
@output=$$(./tests/run_tests.sh 2>&1) || { echo "$$output"; exit 1; }
test-junit:
@echo "Running tests with JUnit XML output..."
@if [ ! -x tests/run_tests.sh ]; then \
chmod +x tests/run_tests.sh || { echo "Error: Cannot make test runner executable"; exit 1; }; \
fi
@./tests/run_tests.sh --junit
coverage:
@if ! command -v kcov >/dev/null 2>&1; then \
echo "Error: kcov not found."; \
echo "Install with: sudo dnf install kcov (Fedora) or sudo apt install kcov (Debian/Ubuntu)"; \
exit 1; \
fi
@echo "Running tests with kcov coverage..."
@if [ ! -x tests/run_tests.sh ]; then \
chmod +x tests/run_tests.sh || { echo "Error: Cannot make test runner executable"; exit 1; }; \
fi
@TEST_PARALLEL_JOBS=1 kcov --include-path=./logging.sh coverage-report ./tests/run_tests.sh
@echo ""
@echo "✓ Coverage report generated in coverage-report/"
sonar:
@if ! command -v sonar-scanner >/dev/null 2>&1; then \
echo "Error: sonar-scanner not found."; \
echo "Install from: https://docs.sonarqube.org/latest/analyzing-source-code/scanners/sonarscanner/"; \
exit 1; \
fi
@if ! command -v secret-tool >/dev/null 2>&1; then \
echo "Error: secret-tool not found (needed for SonarQube token)."; \
echo "Install with: sudo dnf install libsecret (Fedora) or sudo apt install libsecret-tools (Debian/Ubuntu)"; \
exit 1; \
fi
@echo "Syncing version from logging.sh to sonar-project.properties..."
@VERSION=$$(grep 'readonly BASH_LOGGER_VERSION=' logging.sh | sed 's/.*BASH_LOGGER_VERSION="\([^"]*\)".*/\1/') && \
sed -i.bak "s|^sonar.projectVersion=.*|sonar.projectVersion=$$VERSION|" sonar-project.properties && rm -f sonar-project.properties.bak && \
echo " Version set to: $$VERSION"
@echo "Running SonarQube scanner..."
@SONAR_TOKEN=$$(secret-tool lookup service sonarqube account scanner) sonar-scanner
sonar-analysis: coverage test-junit sonar
@echo ""
@echo "✓ Full SonarQube analysis complete!"
demo: demos
demos:
@if [ -d demo-scripts ]; then \
echo "Running demo scripts..."; \
if [ -f demo-scripts/run_demos.sh ]; then \
if [ ! -x demo-scripts/run_demos.sh ]; then \
chmod +x demo-scripts/run_demos.sh || { echo "Error: Cannot make demo runner executable"; exit 1; }; \
fi; \
./demo-scripts/run_demos.sh all; \
else \
echo "Error: demo-scripts/run_demos.sh not found"; \
exit 1; \
fi; \
else \
echo "No demo-scripts directory found"; \
exit 1; \
fi
lint-shell:
@if ! command -v pre-commit >/dev/null 2>&1; then \
echo "Error: pre-commit not found."; \
echo "Install with: pip install pre-commit"; \
exit 1; \
fi
@echo "Running shellcheck (via pre-commit)..."
@pre-commit run shellcheck --all-files
lint-markdown:
@if ! command -v pre-commit >/dev/null 2>&1; then \
echo "Error: pre-commit not found."; \
echo "Install with: pip install pre-commit"; \
exit 1; \
fi
@echo "Running markdownlint (via pre-commit)..."
@pre-commit run markdownlint --all-files
lint: lint-shell lint-markdown
@echo ""
@echo "✓ All linting passed!"
pre-commit:
@if ! command -v pre-commit >/dev/null 2>&1; then \
echo "Error: pre-commit not found."; \
echo "Install with: pip install pre-commit"; \
exit 1; \
fi
@echo "Running pre-commit hooks on all files..."
@pre-commit run --all-files
check: lint-shell lint-markdown test-quiet
@echo ""
@echo "✓ All checks passed!"
clean:
@echo "Cleaning temporary files..."
@find . -name "*.log" -type f -delete 2>/dev/null || true
@find . -name "*~" -type f -delete 2>/dev/null || true
@find . -name ".*.swp" -type f -delete 2>/dev/null || true
@rm -rf coverage-report/ 2>/dev/null || true
@rm -rf test-reports/ 2>/dev/null || true
@echo "✓ Clean complete!"