Skip to content

Commit 7335585

Browse files
authored
build: arrange 'phony' statement near targets (#237)
1 parent a0ecf04 commit 7335585

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Makefile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ substitute = @sed \
5757
$(1) > $(2) \
5858
&& echo "Substituted from '$(1)' to '$(2)'."
5959

60+
.PHONY: all
6061
all: install
6162

6263
# $< - %.in file, $@ desired file %
@@ -66,15 +67,19 @@ all: install
6667
%.py: %.tmp.py
6768
$(call substitute,$<,$@)
6869

70+
.PHONY: substitute-sources
6971
substitute-sources: $(SOURCE_SUB_FILES)
7072
@echo "Substituted information about the utility in the source files."
7173

74+
.PHONY: substitute-debian
7275
substitute-debian: $(DEBIAN_SUB_FILES)
7376
@echo "Substituted information about the utility in the debian files."
7477

78+
.PHONY: substitute-docker
7579
substitute-docker: $(DOCKER_SUB_FILES)
7680
@echo "Substituted information about the utility in the docker files."
7781

82+
.PHONY: install
7883
install: substitute-sources man translate-compile
7984
python3 -m pip install --root=$(DESTDIR)/ .
8085

@@ -104,6 +109,7 @@ install: substitute-sources man translate-compile
104109

105110
install -D -m 0644 man/$(UTIL_NAME).1 $(DESTDIR)/usr/share/man/man1/$(UTIL_NAME).1
106111

112+
.PHONY: man
107113
man: substitute-sources
108114
mkdir -p man
109115
if [ ! -f man/$(UTIL_NAME).1 ]; then \
@@ -115,6 +121,7 @@ man: substitute-sources
115121
--output man/$(UTIL_NAME).1; \
116122
fi
117123

124+
.PHONY: package
118125
package: substitute-debian
119126
find $(DEBIAN_PACKAGES_PATH)/$(UTIL_NAME)* > /dev/null 2>&1 || ( \
120127
dpkg-buildpackage -jauto -b \
@@ -127,22 +134,27 @@ package: substitute-debian
127134
chown --recursive ${USER_UID}:${USER_GID} $(DEBIAN_PACKAGES_PATH) \
128135
)
129136

137+
.PHONY: test
130138
test: substitute-sources
131139
pytest test/unit test/misc --cov=src/ --cov-report xml --cov-report term
132140
make clean-cache
133141

142+
.PHONY: autotest
134143
autotest:
135144
pytest test/auto
136145
make clean-cache
137146

147+
.PHONY: pre-commit
138148
pre-commit:
139149
python3 -m pre_commit run --all-files
140150

151+
.PHONY: clean-cache
141152
clean-cache:
142153
find . -maxdepth 1 -type d | grep -E "pytest_cache" | (xargs rm -r 2> /dev/null || exit 0)
143154
find "src/$(UTIL_NAME)/" -type f -name '*.c' -exec rm --force '{}' +
144155
rm --recursive --force $(shell find -type d -iname "__pycache__")
145156

157+
.PHONY: clean
146158
clean: clean-cache
147159
rm --force --recursive man/
148160
rm --force --recursive build/
@@ -156,6 +168,7 @@ clean: clean-cache
156168
rm --force ${DEBIAN_PATH}/$(UTIL_NAME)-util.substvars
157169
rm --force --recursive src/$(UTIL_NAME).egg-info
158170

171+
.PHONY: clean-all
159172
clean-all: clean
160173
rm --force src/$(UTIL_NAME)/consts.py
161174

@@ -165,18 +178,23 @@ clean-all: clean
165178
rm --force ${DEBIAN_PATH}/preinst
166179
rm --force ${DEBIAN_PATH}/copyright
167180

181+
.PHONY: uninstall
168182
uninstall:
169183
rm --force $(DESTDIR)/usr/share/man/man1/$(UTIL_NAME).1
170184
rm --force --recursive $(DESTDIR)/$(LIB_PATH)
171185
pip3 uninstall $(UTIL_NAME) -y
172186

187+
.PHONY: reinstall
173188
reinstall: uninstall install
174189

190+
.PHONY: todo-list
175191
todo-list: clean-all
176192
@grep --color=auto -r -n 'TODO' ./* --exclude=Makefile --exclude-dir=docs
177193

194+
.PHONY: help
178195
help: general-help docker-help translate-help
179196

197+
.PHONY: general-help
180198
general-help:
181199
@echo "Usage:"
182200
@echo " make [targets] [arguments]"
@@ -205,7 +223,6 @@ general-help:
205223

206224

207225
.EXPORT_ALL_VARIABLES:
208-
.PHONY: all test man
209226

210227
include docker/docker.mk
211228
include locales/i18n.mk

docker/docker.mk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ MONGO_DOCKER_TAG := mongo:8.0.9
22
MONGO_CONTAINER_NAME := mongo-$(UTIL_NAME)-test
33

44

5+
.PHONY: docker-help
56
docker-help:
67
@echo "Docker:"
78
@echo " docker-run Runs docker container with installed util;"
@@ -18,6 +19,7 @@ docker-help:
1819
@echo " docker-help Displays information about available docker targets."
1920
@echo
2021

22+
.PHONY: docker-base-image
2123
docker-base-image: substitute-sources substitute-docker
2224
@docker image inspect $(BASE_DOCKER_TAG) > /dev/null 2>&1 || ( \
2325
echo "Building base docker image." && \
@@ -30,6 +32,7 @@ docker-base-image: substitute-sources substitute-docker
3032
. \
3133
)
3234

35+
.PHONY: docker-test-image
3336
docker-test-image: docker-base-image
3437
@docker image inspect $(TEST_DOCKER_TAG) > /dev/null 2>&1 || \
3538
docker image build \
@@ -42,6 +45,7 @@ docker-test-image: docker-base-image
4245
--file docker/test_ubuntu2204.dockerfile \
4346
.
4447

48+
.PHONY: docker-test-mongo-run
4549
docker-test-mongo-run:
4650
@docker run \
4751
--env MONGO_INITDB_ROOT_USERNAME=root \
@@ -50,17 +54,20 @@ docker-test-mongo-run:
5054
--name $(MONGO_CONTAINER_NAME) \
5155
$(MONGO_DOCKER_TAG)
5256

57+
.PHONY: docker-test-mongo-stop
5358
docker-test-mongo-stop:
5459
@docker container stop $(MONGO_CONTAINER_NAME)
5560
@docker container rm $(MONGO_CONTAINER_NAME)
5661

62+
.PHONY: docker-test
5763
docker-test: docker-test-image docker-test-mongo-run
5864
@docker run --rm \
5965
--env MONGO_HOST=$(shell docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(MONGO_CONTAINER_NAME)) \
6066
--volume $(PWD)/test:/usr/src/$(UTIL_NAME)/test \
6167
"$(TEST_DOCKER_TAG)" || (make docker-test-mongo-stop && exit 200)
6268
@make docker-test-mongo-stop
6369

70+
.PHONY: docker-autotest
6471
docker-autotest: docker-test-image docker-build-package docker-test-mongo-run
6572
@if [ $(shell find . -maxdepth 1 -type f -name .env | wc --lines) != 1 ]; then \
6673
echo "Requires '.env' file with provided GitHub token for running autotests."; \
@@ -76,6 +83,7 @@ docker-autotest: docker-test-image docker-build-package docker-test-mongo-run
7683
make docker-test-mongo-stop; \
7784
fi
7885

86+
.PHONY: docker-build-package
7987
docker-build-package: docker-test-image
8088
docker run --rm \
8189
--volume $(PWD)/$(DEBIAN_PACKAGES_PATH):/usr/src/$(UTIL_NAME)/$(DEBIAN_PACKAGES_PATH) \
@@ -85,6 +93,7 @@ docker-build-package: docker-test-image
8593
"$(TEST_DOCKER_TAG)" bash -c \
8694
"make package"
8795

96+
.PHONY: docker-image
8897
docker-image: docker-base-image docker-test-image
8998
@if [ "$(REBUILD)" = "1" ]; then \
9099
make clean-all docker-rmi ALL="$(ALL)"; \
@@ -104,13 +113,15 @@ docker-image: docker-base-image docker-test-image
104113
. \
105114
)
106115

116+
.PHONY: docker-run
107117
docker-run: docker-image
108118
@touch .env
109119
docker run --rm --tty --interactive \
110120
--env-file .env \
111121
--add-host=host.docker.internal:host-gateway \
112122
"$(DOCKER_TAG)"
113123

124+
.PHONY: docker-rmi
114125
docker-rmi:
115126
@docker rmi $(DOCKER_TAG) --force
116127
@docker rmi $(TEST_DOCKER_TAG) --force

locales/i18n.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ LOCALES_DIR := locales/
22
TRANSLATIONS_DIR := ${LOCALES_DIR}/translations
33

44

5+
.PHONY: translate-help
56
translate-help:
67
@echo "Translate:"
78
@echo " translate-extract Extracts all lines that need to be translated;"
@@ -12,6 +13,7 @@ translate-help:
1213
@echo " translate-help Displays information about available translation targets."
1314
@echo
1415

16+
.PHONY: translate-extract
1517
translate-extract:
1618
pybabel extract --mapping-file ${LOCALES_DIR}/babel.cfg \
1719
--keywords _ \
@@ -24,6 +26,7 @@ translate-extract:
2426
sed -ri '2 s/[0-9]{4}/2024-2025/' ${LOCALES_DIR}/${UTIL_NAME}.pot
2527
sed -i -e '4d;10d;$$ d' ${LOCALES_DIR}/${UTIL_NAME}.pot
2628

29+
.PHONY: translate-update
2730
translate-update: translate-extract
2831
pybabel update --input-file ${LOCALES_DIR}/${UTIL_NAME}.pot \
2932
--update-header-comment \
@@ -33,10 +36,12 @@ translate-update: translate-extract
3336
sed -i -e '8d;$$ d' ${TRANSLATIONS_DIR}/en/LC_MESSAGES/${UTIL_NAME}.po
3437
sed -i -e '8d;$$ d' ${TRANSLATIONS_DIR}/ru/LC_MESSAGES/${UTIL_NAME}.po
3538

39+
.PHONY: translate-compile
3640
translate-compile:
3741
pybabel compile --directory ${TRANSLATIONS_DIR} \
3842
--domain ${UTIL_NAME}
3943

44+
.PHONY: translate-init
4045
translate-init:
4146
@if [ -n "$(LANGUAGE)" ]; then \
4247
pybabel init --input-file ${LOCALES_DIR}/${UTIL_NAME}.pot \

0 commit comments

Comments
 (0)