├── LICENSE ├── Makefile ├── README.md └── TODO.md /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) <2017>, Alexander Kuleshov 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | (1) Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | (2) Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in 12 | the documentation and/or other materials provided with the 13 | distribution. 14 | 15 | (3)The name of the author may not be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 23 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 28 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # gcc-version - returns version of installed gcc 2 | # 3 | # Usage: 4 | # 5 | # $(call gcc-version) 6 | # 7 | # ifeq "$(GCC_VERSION)" "7.1.1" 8 | # CFLAGS += -Wexpansion-to-defined 9 | # endif 10 | define gcc-version 11 | $(eval GCC_VERSION = $(shell gcc --version | sed -n -e 's/.*\([0-9]\.[0-9]\.[0-9]\).*/\1/p')) 12 | endef 13 | 14 | # clang-version - returns version of installed clang 15 | # 16 | # Usage: 17 | # 18 | # $(call clang-version) 19 | # 20 | # ifeq "$(CLANG_VERSION)" "4.0.0" 21 | # CFLAGS += -fstrict-vtable-pointers 22 | # endif 23 | define clang-version 24 | $(eval CLANG_VERSION = $(shell clang --version | sed -n -e 's/.*\([0-9]\.[0-9]\.[0-9]\).*/\1/p')) 25 | endef 26 | 27 | # gcc-supports-flags - returns 0 if the passed flag is not supported by gcc. 28 | # 29 | # Usage: 30 | # 31 | # $(call gcc-supports-flag,EXPANSION_TO_DEFINED_WARN,-Wexpansion-to-defined) 32 | # 33 | # ifeq "$(EXPANSION_TO_DEFINED_WARN)" "1" 34 | # CFLAGS += -Wexpansion-to-defined 35 | # endif 36 | define gcc-supports-flag 37 | $(eval $1 = $(shell echo "" | gcc $2 2>&1 | grep -q "unrecognized command"; echo "$$?")) 38 | endef 39 | 40 | # g++-supports-flag - returns 0 if the passed flag is not supported by g++. 41 | # 42 | # Usage: 43 | # 44 | # $(call g++-supports-flag,EXPANSION_TO_DEFINED_WARN,-Wexpansion-to-defined) 45 | # 46 | # ifeq "$(EXPANSION_TO_DEFINED_WARN)" "1" 47 | # CFLAGS += -Wexpansion-to-defined 48 | # endif 49 | define g++-supports-flag 50 | $(eval $1 = $(shell echo "" | g++ $2 2>&1 | grep -q "unrecognized command"; echo "$$?")) 51 | endef 52 | 53 | # clang-supports-flag - returns 0 if the passed flag is not supported by clang. 54 | # 55 | # Usage: 56 | # 57 | # $(call clang-supports-flag,EXPANSION_TO_DEFINED_WARN,-Wexpansion-to-defined) 58 | # 59 | # ifeq "$(EXPANSION_TO_DEFINED_WARN)" "1" 60 | # CFLAGS += -Wexpansion-to-defined 61 | # endif 62 | define clang-supports-flag 63 | $(eval $1 = $(shell echo "" | clang -E -c -Wfd - 2>&1 | grep -q unknown; echo "$$?")) 64 | endef 65 | 66 | # clang++-supports-flags - returns 0 if the passed flag is not supported by clang++. 67 | # 68 | # Usage: 69 | # 70 | # $(call clang++-supports-flag,EXPANSION_TO_DEFINED_WARN,-Wexpansion-to-defined) 71 | # 72 | # ifeq "$(EXPANSION_TO_DEFINED_WARN)" "1" 73 | # CFLAGS += -Wexpansion-to-defined 74 | # endif 75 | define clang++-supports-flag 76 | $(eval $1 = $(shell echo "" | clang++ -E -c -Wfd - 2>&1 | grep -q unknown; echo "$$?")) 77 | endef 78 | 79 | # print_success - prints the given message with green color. 80 | # 81 | # Usage: 82 | # 83 | # $(call print_success,"Done...") 84 | define print_success 85 | @echo -e "\033[0;32m$1\033[0m" 86 | endef 87 | 88 | # print_success - prints the given message with red color. 89 | # 90 | # Usage: 91 | # 92 | # $(call print_error,"Error: ...") 93 | define print_error 94 | @echo -e "\033[0;31m$1\033[0m" 95 | endef 96 | 97 | # print_success - prints the given message with yellow color. 98 | # 99 | # Usage: 100 | # 101 | # $(call print_warning,"Warning: ...") 102 | define print_warning 103 | @echo -e "\033[0;33m$1\033[0m" 104 | endef 105 | 106 | # 107 | # make-snippets test 108 | # 109 | test: 110 | $(call print_error,"Error: ...") 111 | $(call print_warning,"Warning: ...") 112 | $(call print_success,"Done...") 113 | @echo "Test..." 114 | 115 | clean: 116 | @echo "Clean..." 117 | 118 | .PHONY: test clean 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # make-snippets 2 | 3 | Set of reusable [make](https://en.wikipedia.org/wiki/Make_(software)) snippets. 4 | 5 | Avilable snippets: 6 | 7 | * gcc-version - to get version of [gcc](https://gcc.gnu.org/) 8 | * clang-version - to get version of [clang](https://clang.llvm.org/) 9 | * gcc-supports-flags - gcc-supports-flags - returns 0 if the passed flag is not supported by gcc. 10 | * g++-supports-flags - returns 0 if the passed flag is not supported by g++. 11 | * clang-supports-flags - gcc-supports-flags - returns 0 if the passed flag is not supported by clang. 12 | * clang++-supports-flags - returns 0 if the passed flag is not supported by clang++. 13 | * print_success - prints the given message with green color. 14 | * print_warning - prints the given message with yellow color. 15 | * print_error - prints the given message with red color. 16 | 17 | ## Contributing 18 | 19 | Feel free to ad your favorite. 20 | 21 | ## License 22 | 23 | [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) 24 | 25 | ## Author 26 | 27 | [@0xAX](https://twitter.com/0xAX) -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | * Add same snippets for BSD make --------------------------------------------------------------------------------