Skip to content

Commit 887065a

Browse files
committed
Refactor Makefile for improved structure and functionality
- Added POSIX compliance and clarified compatibility with various Make implementations. - Moved UCD_VERSION declaration for better organization. - Renamed `tests` target to `testsuite` for clarity and updated dependencies accordingly. - Introduced `runtestsuite` target to streamline test execution. - Enhanced `options` target to display additional build configuration details. - Consolidated linting targets under `lint` for better organization.
1 parent c335491 commit 887065a

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

Makefile

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
# lug - Embedded DSL for PE grammar parsers in C++
2+
# Copyright (c) 2017-2025 Jesse W. Towner
23
# See LICENSE file for copyright and license details
34

5+
# This is a POSIX.1-2014 compliant Makefile. It is known to work with GNU Make, NetBSD Make and PDP Make.
6+
# https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html
7+
.POSIX:
8+
.PHONY: all clean dist install uninstall options test testsuite runtestsuite samples runsamples lint clangtidy shellcheck tools unicode
9+
.SUFFIXES: .cpp .o
10+
411
# distribution version
512
VERSION = 0.5.0
613

14+
# unicode character database version
15+
UCD_VERSION = 16.0.0
16+
717
# paths
818
PREFIX = /usr/local
919

1020
# toolchain
21+
CXX = c++
1122
CXXSTD = -std=c++17
1223
CXXWARNFLAGS = -pedantic -Wall -Wconversion -Wextra -Wextra-semi -Wshadow -Wsign-conversion -Wsuggest-override -Wno-parentheses -Wno-logical-not-parentheses
1324
CXXOPTFLAGS = -Os -ffunction-sections -fdata-sections
@@ -39,9 +50,6 @@ TOOLS_OBJ = $(TOOLS:%=tools/%.o)
3950
HEADER_NAMES = detail error iostream unicode utf8 lug
4051
HEADERS = $(HEADER_NAMES:%=include/lug/%.hpp)
4152

42-
# unicode character database version
43-
UCD_VERSION = 16.0.0
44-
4553
# shell scripts
4654
SHELLSCRIPTS = runsamples.sh runtests.sh tools/fetchucd.sh
4755

@@ -51,7 +59,7 @@ DISTDOCFILES = CHANGELOG.md LICENSE.md README.md
5159
DISTPROJFILES = CMakeLists.txt Makefile runsamples.sh runtests.sh .clang-tidy .editorconfig .gitattributes .gitignore
5260
DISTFILES = $(DISTDOCFILES) $(DISTPROJFILES) $(DISTDIRS)
5361

54-
all: options samples tests
62+
all: options testsuite samples
5563

5664
.cpp.o:
5765
@echo CXX $<
@@ -65,24 +73,29 @@ $(SAMPLES_BIN): $(SAMPLES_OBJ)
6573

6674
samples: $(SAMPLES_BIN)
6775

76+
runsamples: samples $(SAMPLES_TESTPLANS)
77+
@sh runsamples.sh $(SAMPLES_TESTPLANS)
78+
6879
$(TESTS_OBJ): $(HEADERS)
6980

7081
$(TESTS_BIN): $(TESTS_OBJ)
7182
@echo LD $@
7283
@$(CXX) -o $@ $@.o $(LDFLAGS)
7384

74-
tests: $(TESTS_BIN)
85+
testsuite: $(TESTS_BIN)
7586

76-
check: tests samples $(SAMPLES_TESTPLANS)
87+
runtestsuite: testsuite
7788
@sh runtests.sh $(TESTS_BIN)
78-
@echo
79-
@sh runsamples.sh $(SAMPLES_TESTPLANS)
89+
90+
test: runtestsuite runsamples
91+
92+
clangtidy:
93+
@$(CLANGTIDY) --quiet $(CXXFLAGS:%=--extra-arg=%) $(HEADERS)
8094

8195
shellcheck:
8296
@$(SHELLCHECK) -s sh $(SHELLSCRIPTS)
8397

84-
tidy:
85-
@$(CLANGTIDY) --quiet $(CXXFLAGS:%=--extra-arg=%) $(HEADERS)
98+
lint: clangtidy shellcheck
8699

87100
$(TOOLS_OBJ): $(HEADERS)
88101

@@ -100,13 +113,16 @@ unicode: tools
100113

101114
options:
102115
@echo lug build options:
103-
@echo "CXX = $(CXX)"
104-
@echo "CXXSTD = $(CXXSTD)"
105-
@echo "CXXFLAGS = $(CXXFLAGS)"
106-
@echo "LDFLAGS = $(LDFLAGS)"
107-
@echo "CLANGTIDY = $(CLANGTIDY)"
108-
@echo "PREFIX = $(PREFIX)"
109-
@echo "UCD_VERSION = $(UCD_VERSION)"
116+
@echo "CXX = $(CXX)"
117+
@echo "CXXSTD = $(CXXSTD)"
118+
@echo "CXXWARNFLAGS = $(CXXWARNFLAGS)"
119+
@echo "CXXOPTFLAGS = $(CXXOPTFLAGS)"
120+
@echo "CXXFLAGS = $(CXXFLAGS)"
121+
@echo "LDFLAGS = $(LDFLAGS)"
122+
@echo "CLANGTIDY = $(CLANGTIDY)"
123+
@echo "SHELLCHECK = $(SHELLCHECK)"
124+
@echo "PREFIX = $(PREFIX)"
125+
@echo "UCD_VERSION = $(UCD_VERSION)"
110126

111127
clean:
112128
@echo cleaning
@@ -146,5 +162,3 @@ uninstall:
146162
@rm -f $(DESTDIR)$(PREFIX)/include/lug/unicode.hpp
147163
@rm -f $(DESTDIR)$(PREFIX)/include/lug/utf8.hpp
148164
@rmdir $(DESTDIR)$(PREFIX)/include/lug
149-
150-
.PHONY: all samples tests check shellcheck tidy tools unicode options clean dist install uninstall

0 commit comments

Comments
 (0)