1# SPDX-License-Identifier: GPL-2.0 2CC = $(CROSS_COMPILE)gcc 3BUILD_OUTPUT := $(CURDIR) 4PREFIX ?= /usr 5DESTDIR ?= 6DAY := $(shell date +%Y.%m.%d) 7SNAPSHOT = turbostat-$(DAY) 8 9ifeq ("$(origin O)", "command line") 10 BUILD_OUTPUT := $(O) 11endif 12 13turbostat : turbostat.c 14override CFLAGS += -O2 -Wall -Wextra -I../../../include 15override CFLAGS += -DMSRHEADER='"../../../../arch/x86/include/asm/msr-index.h"' 16override CFLAGS += -DINTEL_FAMILY_HEADER='"../../../../arch/x86/include/asm/intel-family.h"' 17override CFLAGS += -D_FILE_OFFSET_BITS=64 18override CFLAGS += -D_FORTIFY_SOURCE=2 19 20%: %.c 21 @mkdir -p $(BUILD_OUTPUT) 22 $(CC) $(CFLAGS) $< -o $(BUILD_OUTPUT)/$@ $(LDFLAGS) -lcap -lrt 23 24.PHONY : clean 25clean : 26 @rm -f $(BUILD_OUTPUT)/turbostat 27 @rm -f $(SNAPSHOT).tar.gz 28 29install : turbostat 30 install -d $(DESTDIR)$(PREFIX)/bin 31 install $(BUILD_OUTPUT)/turbostat $(DESTDIR)$(PREFIX)/bin/turbostat 32 install -d $(DESTDIR)$(PREFIX)/share/man/man8 33 install -m 644 turbostat.8 $(DESTDIR)$(PREFIX)/share/man/man8 34 35snapshot: turbostat 36 @rm -rf $(SNAPSHOT) 37 @mkdir $(SNAPSHOT) 38 @cp turbostat Makefile turbostat.c turbostat.8 ../../../../arch/x86/include/asm/intel-family.h $(SNAPSHOT) 39 40 @sed -e 's/^#include <linux\/bits.h>/#include "bits.h"/' ../../../../arch/x86/include/asm/msr-index.h > $(SNAPSHOT)/msr-index.h 41 @echo '#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))' >> $(SNAPSHOT)/msr-index.h 42 @echo "#define BIT(x) (1 << (x))" > $(SNAPSHOT)/bits.h 43 @echo "#define BIT_ULL(nr) (1ULL << (nr))" >> $(SNAPSHOT)/bits.h 44 @echo "#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (sizeof(long) * 8 - 1 - (h))))" >> $(SNAPSHOT)/bits.h 45 @echo "#define GENMASK_ULL(h, l) (((~0ULL) << (l)) & (~0ULL >> (sizeof(long long) * 8 - 1 - (h))))" >> $(SNAPSHOT)/bits.h 46 47 @echo PWD=. > $(SNAPSHOT)/Makefile 48 @echo "CFLAGS += -DMSRHEADER='\"msr-index.h\"'" >> $(SNAPSHOT)/Makefile 49 @echo "CFLAGS += -DINTEL_FAMILY_HEADER='\"intel-family.h\"'" >> $(SNAPSHOT)/Makefile 50 @sed -e's/.*MSRHEADER.*//' -e's/.*INTEL_FAMILY_HEADER.*//' Makefile >> $(SNAPSHOT)/Makefile 51 52 @rm -f $(SNAPSHOT).tar.gz 53 tar cvzf $(SNAPSHOT).tar.gz $(SNAPSHOT) 54