1 # SPDX-License-Identifier: GPL-2.0
2 CC
= $(CROSS_COMPILE
)gcc
3 BUILD_OUTPUT
:= $(CURDIR
)
6 DAY
:= $(shell date
+%Y.
%m.
%d
)
7 SNAPSHOT
= turbostat-
$(DAY
)
9 ifeq ("$(origin O)", "command line")
13 turbostat
: turbostat.c
14 override CFLAGS
+= -O2
-Wall
-Wextra
-I..
/..
/..
/include
15 override CFLAGS
+= -DMSRHEADER
='"../../../../arch/x86/include/asm/msr-index.h"'
16 override CFLAGS
+= -DINTEL_FAMILY_HEADER
='"../../../../arch/x86/include/asm/intel-family.h"'
17 override CFLAGS
+= -DBUILD_BUG_HEADER
='"../../../../include/linux/build_bug.h"'
18 override CFLAGS
+= -D_FILE_OFFSET_BITS
=64
19 override CFLAGS
+= -D_FORTIFY_SOURCE
=2
22 @mkdir
-p
$(BUILD_OUTPUT
)
23 $(CC
) $(CFLAGS
) $< -o
$(BUILD_OUTPUT
)/$@
$(LDFLAGS
) -lcap
-lrt
27 @
rm -f
$(BUILD_OUTPUT
)/turbostat
28 @
rm -f
$(SNAPSHOT
).
tar.gz
31 install -d
$(DESTDIR
)$(PREFIX
)/bin
32 install $(BUILD_OUTPUT
)/turbostat
$(DESTDIR
)$(PREFIX
)/bin
/turbostat
33 install -d
$(DESTDIR
)$(PREFIX
)/share
/man
/man8
34 install -m
644 turbostat
.8 $(DESTDIR
)$(PREFIX
)/share
/man
/man8
39 @cp turbostat Makefile turbostat.c turbostat
.8 ..
/..
/..
/..
/arch
/x86
/include/asm
/intel-family.h
$(SNAPSHOT
)
41 @sed
-e
's/^#include <linux\/bits.h>/#include "bits.h"/' ..
/..
/..
/..
/arch
/x86
/include/asm
/msr-index.h
> $(SNAPSHOT
)/msr-index.h
42 @echo
'#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))' >> $(SNAPSHOT
)/msr-index.h
43 @echo
"#define BIT(x) (1 << (x))" > $(SNAPSHOT
)/bits.h
44 @echo
"#define BIT_ULL(nr) (1ULL << (nr))" >> $(SNAPSHOT
)/bits.h
45 @echo
"#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (sizeof(long) * 8 - 1 - (h))))" >> $(SNAPSHOT
)/bits.h
46 @echo
"#define GENMASK_ULL(h, l) (((~0ULL) << (l)) & (~0ULL >> (sizeof(long long) * 8 - 1 - (h))))" >> $(SNAPSHOT
)/bits.h
48 @echo
'#define BUILD_BUG_ON(cond) do { enum { compile_time_check ## __COUNTER__ = 1/(!(cond)) }; } while (0)' > $(SNAPSHOT
)/build_bug.h
49 @echo
'#define __must_be_array(arr) 0' >> $(SNAPSHOT
)/build_bug.h
51 @echo PWD
=.
> $(SNAPSHOT
)/Makefile
52 @echo
"CFLAGS += -DMSRHEADER='\"msr-index.h\"'" >> $(SNAPSHOT
)/Makefile
53 @echo
"CFLAGS += -DINTEL_FAMILY_HEADER='\"intel-family.h\"'" >> $(SNAPSHOT
)/Makefile
54 @echo
"CFLAGS += -DBUILD_BUG_HEADER='\"build_bug.h\"'" >> $(SNAPSHOT
)/Makefile
55 @sed
-e
's/.*MSRHEADER.*//' -e
's/.*INTEL_FAMILY_HEADER.*//' -e
's/.*BUILD_BUG_HEADER.*//' Makefile
>> $(SNAPSHOT
)/Makefile
57 @
rm -f
$(SNAPSHOT
).
tar.gz
58 tar cvzf
$(SNAPSHOT
).
tar.gz
$(SNAPSHOT
)