| 1 |
############################################################################### |
| 2 |
# Makefile script for Membw tool |
| 3 |
# |
| 4 |
# @par |
| 5 |
# BSD LICENSE |
| 6 |
# |
| 7 |
# Copyright(c) 2018-2026 Intel Corporation. All rights reserved. |
| 8 |
# |
| 9 |
# Redistribution and use in source and binary forms, with or without |
| 10 |
# modification, are permitted provided that the following conditions |
| 11 |
# are met: |
| 12 |
# |
| 13 |
# * Redistributions of source code must retain the above copyright |
| 14 |
# notice, this list of conditions and the following disclaimer. |
| 15 |
# * Redistributions in binary form must reproduce the above copyright |
| 16 |
# notice, this list of conditions and the following disclaimer in |
| 17 |
# the documentation and/or other materials provided with the |
| 18 |
# distribution. |
| 19 |
# * Neither the name of Intel Corporation nor the names of its |
| 20 |
# contributors may be used to endorse or promote products derived |
| 21 |
# from this software without specific prior written permission. |
| 22 |
# |
| 23 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 26 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 27 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 28 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 29 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 30 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 31 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 33 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 |
# |
| 35 |
############################################################################### |
| 36 |
|
| 37 |
include ../../pre-build.mk |
| 38 |
|
| 39 |
APP = membw |
| 40 |
MAN = membw.8 |
| 41 |
|
| 42 |
# XXX: modify as desired |
| 43 |
PREFIX ?= /usr/local |
| •44 |
BIN_DIR = $(DESTDIR)/usr/bin |
| 45 |
MAN_DIR = $(DESTDIR)/usr/share/man/man8 |
| 46 |
|
| •47 |
CFLAGS += -W -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes \ |
| 48 |
-Wmissing-declarations -Wold-style-definition -Wpointer-arith \ |
| 49 |
-Wcast-qual -Wundef -Wwrite-strings \ |
| 50 |
-Wformat -Wformat-security -fstack-protector-strong -fPIE \ |
| 51 |
-Wunreachable-code -Wsign-compare -Wno-endif-labels \ |
| 52 |
-Winline -msse4.2 \ |
| 53 |
-fcf-protection=full |
| 54 |
|
| 55 |
ifneq ($(EXTRA_CFLAGS),) |
| 56 |
CFLAGS += $(EXTRA_CFLAGS) |
| 57 |
endif |
| 58 |
ifneq ($(EXTRA_LDFLAGS),) |
| 59 |
LDFLAGS += $(EXTRA_LDFLAGS) |
| 60 |
endif |
| 61 |
|
| 62 |
ifeq ($(DEBUG),y) |
| 63 |
CFLAGS += -O0 -g -DDEBUG |
| 64 |
else |
| 65 |
CFLAGS += -O3 -g -D_FORTIFY_SOURCE=2 |
| 66 |
endif |
| 67 |
|
| 68 |
HAS_AVX512 := $(shell $(CC) -mavx512f -dM -E - < /dev/null 2> /dev/null | grep -c "AVX512F") |
| 69 |
ifeq ($(HAS_AVX512),1) |
| 70 |
CFLAGS += -mavx512f |
| 71 |
endif |
| 72 |
|
| 73 |
HAS_CLWB := $(shell $(CC) -mclwb -dM -E - < /dev/null 2> /dev/null | grep -c "CLWB") |
| 74 |
ifeq ($(HAS_CLWB),1) |
| 75 |
CFLAGS += -mclwb |
| 76 |
endif |
| 77 |
|
| 78 |
IS_GCC = $(shell $(CC) -v 2>&1 | grep -c "^gcc version ") |
| 79 |
IS_CLANG = $(shell $(CC) -v 2>&1 | grep -c "^clang version ") |
| 80 |
|
| 81 |
# GCC-only options |
| 82 |
ifeq ($(IS_GCC),1) |
| 83 |
CFLAGS += -fno-strict-overflow \ |
| 84 |
-fno-delete-null-pointer-checks \ |
| 85 |
-fwrapv \ |
| 86 |
-fno-expensive-optimizations \ |
| 87 |
-fstack-clash-protection \ |
| 88 |
-fcf-protection=full |
| 89 |
endif |
| 90 |
|
| 91 |
SRCS = $(sort $(wildcard *.c)) |
| 92 |
OBJS = $(SRCS:.c=.o) |
| 93 |
DEPFILES = $(SRCS:.c=.d) |
| 94 |
|
| 95 |
all: $(APP) |
| 96 |
|
| 97 |
$(APP): $(OBJS) |
| 98 |
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ |
| 99 |
|
| 100 |
%.o: %.c %.d |
| 101 |
|
| 102 |
%.d: %.c |
| 103 |
$(CC) -MM -MP -MF $@ $(CFLAGS) $< |
| 104 |
cat $@ | sed 's/$(@:.d=.o)/$@/' >> $@ |
| 105 |
|
| 106 |
|
| 107 |
install: $(APP) $(MAN) |
| 108 |
ifeq ($(shell uname), FreeBSD) |
| 109 |
install -d $(BIN_DIR) |
| 110 |
install -d $(MAN_DIR) |
| 111 |
install -s $(APP) $(BIN_DIR) |
| 112 |
install -m 0444 $(MAN) $(MAN_DIR) |
| 113 |
else |
| 114 |
install -D -s $(APP) $(BIN_DIR)/$(APP) |
| 115 |
install -m 0444 $(MAN) -D $(MAN_DIR)/$(MAN) |
| 116 |
endif |
| 117 |
|
| 118 |
uninstall: |
| 119 |
-rm $(BIN_DIR)/$(APP) |
| 120 |
-rm $(MAN_DIR)/$(MAN) |
| 121 |
|
| 122 |
|
| 123 |
.PHONY: clean |
| 124 |
clean: |
| 125 |
-rm -f $(APP) $(OBJS) $(DEPFILES) ./*~ |
| 126 |
|
| 127 |
CHECKPATCH?=checkpatch.pl |
| 128 |
.PHONY: checkpatch |
| 129 |
checkpatch: |
| 130 |
$(CHECKPATCH) --no-tree --no-signoff --emacs \ |
| 131 |
--ignore CODE_INDENT,INITIALISED_STATIC,LEADING_SPACE \ |
| 132 |
--ignore SPLIT_STRING,UNSPECIFIED_INT,ARRAY_SIZE,COMPLEX_MACRO \ |
| 133 |
--ignore STORAGE_CLASS,SPDX_LICENSE_TAG,CONST_STRUCT,SPACING \ |
| 134 |
-f membw.c |
| 135 |
|
| 136 |
CLANGFORMAT?=clang-format |
| 137 |
.PHONY: clang-format |
| 138 |
clang-format: |
| 139 |
@for file in $(wildcard *.[ch]); do \ |
| 140 |
echo "Checking style $$file"; \ |
| 141 |
$(CLANGFORMAT) -style=file "$$file" | diff "$$file" - | tee /dev/stderr | [ $$(wc -c) -eq 0 ] || \ |
| 142 |
{ echo "ERROR: $$file has style problems"; exit 1; } \ |
| 143 |
done |
| 144 |
|
| 145 |
CODESPELL?=codespell |
| 146 |
.PHONY: codespell |
| 147 |
codespell: |
| 148 |
$(CODESPELL) . -q 2 |
| 149 |
|
| 150 |
|
| 151 |
.PHONY: style |
| 152 |
style: |
| 153 |
$(MAKE) checkpatch |
| 154 |
$(MAKE) clang-format |
| 155 |
$(MAKE) codespell |
| 156 |
|
| 157 |
CPPCHECK?=cppcheck |
| 158 |
.PHONY: cppcheck |
| 159 |
cppcheck: |
| 160 |
$(CPPCHECK) --enable=warning,portability,performance,unusedFunction,missingInclude \ |
| 161 |
--suppress=missingIncludeSystem \ |
| 162 |
--std=c99 --template=gcc \ |
| 163 |
membw.c |
| 164 |
|
| 165 |
# if target not clean then make dependencies |
| 166 |
ifneq ($(MAKECMDGOALS),clean) |
| 167 |
-include $(DEPFILES) |
| 168 |
endif |
| 169 |
|