| 1 |
############################################################################### |
| 2 |
# Makefile script for PQoS sample application |
| 3 |
# |
| 4 |
# @par |
| 5 |
# BSD LICENSE |
| 6 |
# |
| 7 |
# Copyright(c) 2014-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 |
OBJDIR = obj |
| 40 |
LIBDIR ?= ../lib |
| •41 |
LDFLAGS += -L$(LIBDIR) -pie -z noexecstack -z relro -z now |
| 42 |
LDLIBS = -lpqos -lpthread |
| •43 |
CFLAGS += -I$(LIBDIR) \ |
| 44 |
-W -Wall -Wextra -Wstrict-prototypes -Wmissing-prototypes \ |
| 45 |
-Wmissing-declarations -Wold-style-definition -Wpointer-arith \ |
| 46 |
-Wcast-qual -Wundef -Wwrite-strings \ |
| 47 |
-Wformat -Wformat-security -fstack-protector-strong -fPIE \ |
| 48 |
-Wunreachable-code -Wsign-compare -Wno-endif-labels \ |
| 49 |
-fcf-protection=full |
| 50 |
ifneq ($(EXTRA_CFLAGS),) |
| 51 |
CFLAGS += $(EXTRA_CFLAGS) |
| 52 |
endif |
| 53 |
ifneq ($(EXTRA_LDFLAGS),) |
| 54 |
LDFLAGS += $(EXTRA_LDFLAGS) |
| 55 |
endif |
| 56 |
|
| 57 |
# ICC and GCC options |
| 58 |
ifeq ($(CC),icc) |
| 59 |
else |
| 60 |
CFLAGS += -Wcast-align \ |
| 61 |
-Wnested-externs \ |
| 62 |
-Wmissing-noreturn |
| 63 |
endif |
| 64 |
|
| 65 |
IS_GCC = $(shell $(CC) -v 2>&1 | grep -c "^gcc version ") |
| 66 |
IS_CLANG = $(shell $(CC) -v 2>&1 | grep -c "^clang version ") |
| 67 |
|
| 68 |
# GCC-only options |
| 69 |
ifeq ($(IS_GCC),1) |
| 70 |
CFLAGS += -fno-strict-overflow \ |
| 71 |
-fno-delete-null-pointer-checks \ |
| 72 |
-fwrapv \ |
| 73 |
-fstack-clash-protection \ |
| 74 |
-fcf-protection=full |
| 75 |
endif |
| 76 |
|
| 77 |
ifeq ($(shell uname), FreeBSD) |
| 78 |
LDLIBS += -lrt |
| 79 |
endif |
| 80 |
|
| 81 |
# DEBUG build |
| 82 |
ifeq ($(DEBUG),y) |
| 83 |
CFLAGS += -g -ggdb -O0 -DDEBUG |
| 84 |
else |
| 85 |
CFLAGS += -g -O2 -D_FORTIFY_SOURCE=2 |
| 86 |
endif |
| 87 |
|
| 88 |
# RMID CUSTOM |
| 89 |
ifeq ($(RMID_CUSTOM),y) |
| 90 |
CFLAGS += -DPQOS_RMID_CUSTOM |
| 91 |
endif |
| 92 |
|
| 93 |
# Build targets and dependencies |
| 94 |
APP = pqos |
| 95 |
MAN = pqos.8 |
| 96 |
|
| 97 |
# XXX: modify as desired |
| 98 |
PREFIX ?= /usr/local |
| •99 |
BIN_DIR = $(DESTDIR)/usr/sbin |
| 100 |
MAN_DIR = $(DESTDIR)/usr/share/man/man8 |
| 101 |
|
| 102 |
SRCS = $(sort $(wildcard *.c)) |
| 103 |
OBJS = $(addprefix $(OBJDIR)/,$(SRCS:.c=.o)) |
| 104 |
DEPFILES = $(addprefix $(OBJDIR)/,$(SRCS:.c=.d)) |
| 105 |
|
| 106 |
all: $(APP) |
| 107 |
|
| 108 |
dump: |
| 109 |
echo $(SRCS) |
| 110 |
echo $(OBJS) |
| 111 |
|
| 112 |
$(APP): $(OBJS) |
| 113 |
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ |
| 114 |
|
| 115 |
$(OBJDIR)/%.o: %.c $(OBJDIR)/%.d |
| 116 |
@mkdir -p $(@D) |
| 117 |
$(CC) $(CFLAGS) -c -o $@ $< |
| 118 |
|
| 119 |
$(OBJDIR)/%.d: %.c |
| 120 |
@mkdir -p $(@D) |
| 121 |
set -e; rm -f $@; \ |
| 122 |
$(CC) -MM -MP -MF $@ $(CFLAGS) $< > $@.$$$$; \ |
| 123 |
sed 's/$(@F:.d=.o)/$(@F)/' < $@.$$$$ > $@; \ |
| 124 |
rm -f $@.$$$$ |
| 125 |
|
| 126 |
.PHONY: clean install uninstall |
| 127 |
|
| 128 |
install: $(APP) $(MAN) |
| 129 |
ifeq ($(shell uname), FreeBSD) |
| 130 |
install -d $(BIN_DIR) |
| 131 |
install -d $(MAN_DIR) |
| 132 |
install $(APP) $(BIN_DIR) |
| 133 |
install $(APP)-msr $(BIN_DIR) |
| 134 |
install -m 0444 $(MAN) $(MAN_DIR) |
| 135 |
ln -f -s $(MAN) $(MAN_DIR)/$(APP)-msr.8 |
| 136 |
else |
| 137 |
install -D $(APP) $(BIN_DIR)/$(APP) |
| 138 |
install -D $(APP)-msr $(BIN_DIR)/$(APP)-msr |
| 139 |
install -D $(APP)-os $(BIN_DIR)/$(APP)-os |
| 140 |
install -m 0444 $(MAN) -D $(MAN_DIR)/$(MAN) |
| 141 |
ln -f -s $(MAN) $(MAN_DIR)/$(APP)-msr.8 |
| 142 |
ln -f -s $(MAN) $(MAN_DIR)/$(APP)-os.8 |
| 143 |
endif |
| 144 |
|
| 145 |
uninstall: |
| 146 |
-rm $(BIN_DIR)/$(APP) |
| 147 |
-rm $(MAN_DIR)/$(MAN) |
| 148 |
-rm $(BIN_DIR)/$(APP)-msr |
| 149 |
-rm $(MAN_DIR)/$(APP)-msr.8 |
| 150 |
ifneq ($(shell uname), FreeBSD) |
| 151 |
-rm $(BIN_DIR)/$(APP)-os |
| 152 |
-rm $(MAN_DIR)/$(APP)-os.8 |
| 153 |
endif |
| 154 |
|
| 155 |
clean: |
| 156 |
-rm -rf $(OBJDIR) |
| 157 |
-rm -f $(APP) ./*.d ./*.o ./*~ |
| 158 |
|
| 159 |
CHECKPATCH?=checkpatch.pl |
| 160 |
.PHONY: checkpatch |
| 161 |
checkpatch: |
| 162 |
$(CHECKPATCH) --no-tree --no-signoff --emacs \ |
| 163 |
--ignore CODE_INDENT,INITIALISED_STATIC,LEADING_SPACE,SPLIT_STRING,UNSPECIFIED_INT,ARRAY_SIZE,\ |
| 164 |
SPDX_LICENSE_TAG,CONST_STRUCT,SPACING,\ |
| 165 |
PREFER_DEFINED_ATTRIBUTE_MACRO\ |
| 166 |
-f main.c -f main.h -f monitor.c -f monitor.h -f alloc.c -f alloc.h -f profiles.c -f profiles.h \ |
| 167 |
-f cap.h -f cap.c -f common.h -f common.c \ |
| 168 |
-f monitor_csv.c -f monitor_csv.h \ |
| 169 |
-f monitor_text.c -f monitor_text.h \ |
| 170 |
-f monitor_utils.c -f monitor_utils.h \ |
| 171 |
-f monitor_xml.c -f monitor_xml.h |
| 172 |
|
| 173 |
CLANGFORMAT?=clang-format |
| 174 |
.PHONY: clang-format |
| 175 |
clang-format: |
| 176 |
@for file in $(SRCS); do \ |
| 177 |
echo "Checking style $$file"; \ |
| 178 |
$(CLANGFORMAT) -style=file "$$file" | diff "$$file" - | tee /dev/stderr | [ $$(wc -c) -eq 0 ] || \ |
| 179 |
{ echo "ERROR: $$file has style problems"; exit 1; } \ |
| 180 |
done |
| 181 |
|
| 182 |
CODESPELL?=codespell |
| 183 |
.PHONY: codespell |
| 184 |
codespell: |
| 185 |
$(CODESPELL) . -q 2 -L clos -w |
| 186 |
|
| 187 |
|
| 188 |
.PHONY: style |
| 189 |
style: |
| 190 |
$(MAKE) checkpatch |
| 191 |
$(MAKE) clang-format |
| 192 |
$(MAKE) codespell |
| 193 |
|
| 194 |
CPPCHECK?=cppcheck |
| 195 |
.PHONY: cppcheck |
| 196 |
cppcheck: |
| 197 |
$(CPPCHECK) --enable=warning,portability,performance,unusedFunction,missingInclude \ |
| 198 |
--std=c99 -I$(LIBDIR) --template=gcc \ |
| 199 |
--suppress=missingIncludeSystem \ |
| 200 |
$(SRCS) |
| 201 |
|
| 202 |
# if target not clean then make dependencies |
| 203 |
ifneq ($(MAKECMDGOALS),clean) |
| 204 |
-include $(DEPFILES) |
| 205 |
endif |