1# The Art of C++ 2# Copyright (c) 2014-2020 Dr. Colin Hirsch and Daniel Frey 3# Please see LICENSE for license or visit https://github.com/taocpp/PEGTL 4 5.SUFFIXES: 6.SECONDARY: 7 8ifeq ($(OS),Windows_NT) 9UNAME_S := $(OS) 10ifeq ($(shell gcc -dumpmachine),mingw32) 11MINGW_CXXFLAGS = -U__STRICT_ANSI__ 12endif 13else 14UNAME_S := $(shell uname -s) 15endif 16 17# For Darwin (Mac OS X / macOS) we assume that the default compiler 18# clang++ is used; when $(CXX) is some version of g++, then 19# $(CXXSTD) has to be set to -std=c++17 (or newer) so 20# that -stdlib=libc++ is not automatically added. 21 22ifeq ($(CXXSTD),) 23CXXSTD := -std=c++17 24ifeq ($(UNAME_S),Darwin) 25CXXSTD += -stdlib=libc++ 26endif 27endif 28 29# Ensure strict standard compliance and no warnings, can be 30# changed if desired. 31 32CPPFLAGS ?= -pedantic 33CXXFLAGS ?= -Wall -Wextra -Wshadow -Werror -O3 $(MINGW_CXXFLAGS) 34 35CLANG_TIDY ?= clang-tidy 36 37HEADERS := $(shell find include -name '*.hpp') 38SOURCES := $(shell find src -name '*.cpp') 39DEPENDS := $(SOURCES:%.cpp=build/%.d) 40BINARIES := $(SOURCES:%.cpp=build/%) 41 42CLANG_TIDY_HEADERS := $(filter-out include/tao/pegtl/internal/file_mapper_win32.hpp include/tao/pegtl/contrib/internal/endian_win.hpp,$(HEADERS)) 43 44UNIT_TESTS := $(filter build/src/test/%,$(BINARIES)) 45 46.PHONY: all 47all: compile check 48 49.PHONY: compile 50compile: $(BINARIES) 51 52.PHONY: check 53check: $(UNIT_TESTS) 54 @set -e; for T in $(UNIT_TESTS); do echo $$T; $$T > /dev/null; done 55 56build/%.valgrind: build/% 57 valgrind --error-exitcode=1 --leak-check=full $< 58 @touch $@ 59 60.PHONY: valgrind 61valgrind: $(UNIT_TESTS:%=%.valgrind) 62 @echo "All $(words $(UNIT_TESTS)) valgrind tests passed." 63 64build/%.clang-tidy: % .clang-tidy 65 $(CLANG_TIDY) -quiet $< -- $(CXXSTD) -Iinclude $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) 2>/dev/null 66 @mkdir -p $(@D) 67 @touch $@ 68 69.PHONY: clang-tidy 70clang-tidy: $(CLANG_TIDY_HEADERS:%=build/%.clang-tidy) $(SOURCES:%=build/%.clang-tidy) 71 @echo "All $(words $(CLANG_TIDY_HEADERS) $(SOURCES)) clang-tidy tests passed." 72 73.PHONY: clean 74clean: 75 @rm -rf build/* 76 @find . -name '*~' -delete 77 78build/%.d: %.cpp Makefile 79 @mkdir -p $(@D) 80 $(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) -MM -MQ $@ $< -o $@ 81 82build/%: %.cpp build/%.d 83 $(CXX) $(CXXSTD) -Iinclude $(CPPFLAGS) $(CXXFLAGS) $< $(LDFLAGS) -o $@ 84 85.PHONY: amalgamate 86amalgamate: build/amalgamated/pegtl.hpp 87 88build/amalgamated/pegtl.hpp: $(HEADERS) 89 @mkdir -p $(@D) 90 @rm -rf build/include 91 @cp -a include build/ 92 @rm -rf build/include/tao/pegtl/contrib/icu 93 @sed -i -e 's%^#%//#%g' $$(find build/include -name '*.hpp') 94 @sed -i -e 's%^//#include "%#include "%g' $$(find build/include -name '*.hpp') 95 @for i in $$(find build/include -name '*.hpp'); do echo "#pragma once" >tmp.out; echo "#line 1" >>tmp.out; cat $$i >>tmp.out; mv tmp.out $$i; done 96 @echo '#include "tao/pegtl.hpp"' >build/include/amalgamated.hpp 97 @( cd build/include ; for i in tao/pegtl/contrib/*.hpp; do echo "#include \"$$i\""; done ) >>build/include/amalgamated.hpp 98 @echo -e "/*\n\nWelcome to the Parsing Expression Grammar Template Library (PEGTL)." >$@ 99 @echo -e "See https://github.com/taocpp/PEGTL/ for more information, documentation, etc.\n" >>$@ 100 @echo -e "The library is licensed as follows:\n" >>$@ 101 @cat LICENSE >>$@ 102 @echo -e "\n*/\n" >>$@ 103 @( cd build/include ; g++ -E -C -nostdinc amalgamated.hpp ) >>$@ 104 @sed -i -e 's%^//#%#%g' $@ 105 @sed -i -e 's%^# \([0-9]* "[^"]*"\).*%#line \1%g' $@ 106 @sed -i -e 's%^// Copyright.*%%g' $@ 107 @sed -i -e 's%^// Please.*%%g' $@ 108 @echo "Generated/updated $@ successfully." 109 110ifeq ($(findstring $(MAKECMDGOALS),clean),) 111-include $(DEPENDS) 112endif 113