NoPaste

phc_intel: make dkms_mkdeb schlägt fehl unter Stretch

von KBDCALLS
SNIPPET_DESC:
https://debianforum.de/forum/posting.php?mode=edit&f=33&p=1141259
SNIPPET_CREATION_TIME:
15.11.2018 11:55:21
SNIPPET_PRUNE_TIME:
Unendlich

SNIPPET_TEXT:
  1. MODULE = phc-intel
  2. VERSION = 0.3.2
  3. # If you are brave enough to use a test release, uncomment the next line.
  4. #VERSION = 0.4.0
  5.  
  6. # change KERNELSRC to the location of your kernel build tree only if
  7. # autodetection does not work, e.g.:
  8. # KERNELSRC=/usr/src/linux
  9. # or run make with KERNELSRC parameter, e.g.:
  10. # make KERNELSRC=/usr/src/linux
  11. #-------------------------------------------------------------------------------------------------#
  12.  
  13. # Some targets don't need kernel headers.
  14. ifneq ($(MAKECMDGOALS),)
  15.   ifeq ($(filter-out clean dkms_mkdeb dkms_mkrpm, $(MAKECMDGOALS)),)
  16.     SKIPKERNEL := true
  17.   endif
  18. endif
  19.  
  20. # Where are patches located?
  21. PATCH_BASE := ./inc
  22.  
  23. ifeq ($(SKIPKERNEL),)
  24.   # No need to run this multiple times on recursive make
  25.   export SKIPKERNEL := true
  26.  
  27.   KERNELSRC ?= /lib/modules/`uname -r`/build
  28.   KERNELRELEASE ?= $(shell grep '[\t ]UTS_RELEASE[\t ][\t ]*"' \
  29.     $(KERNELSRC)/include/linux/version.h \
  30.     $(KERNELSRC)/include/linux/utsrelease.h \
  31.     $(KERNELSRC)/include/generated/utsrelease.h  2>/dev/null | \
  32.     sed -e 's;[^"]*"\(.*\)";\1;g' )
  33.  
  34.   ifeq ($(KERNELRELEASE),)
  35.     $(error \
  36.     Kernel version not found, maybe you need to install appropriate kernel-headers\
  37.     or run make with KERNELSRC parameter, e.g.: make KERNELSRC=/usr/src/linux)
  38.   endif
  39.  
  40.   # Strip everything not looking like #.#.# etc. and name it KERNELVERSION.
  41.   SED_KVERSION := sed -n 's/^\([0-9]\{1,\}\(\.[0-9]\{1,\}\)\{1,\}\).*/\1/p'
  42.   ifeq ($(origin KERNELVERSION), undefined)
  43.     KERNELVERSION := $(shell echo $(KERNELRELEASE) | $(SED_KVERSION))
  44.   else
  45.     override KERNELVERSION := $(shell echo $(KERNELVERSION) | $(SED_KVERSION))
  46.   endif
  47.  
  48.   # Split KERNELVERSION. Naming scheme follows Linux kernel developement with a
  49.   # K_ prefix. EXTRAVERSION can be empty, the rest should not - But kernel 3.0
  50.   # changed the game a bit.
  51.   K_VERSION := $(shell echo $(KERNELVERSION) | cut -d'.' -f1)
  52.   K_PATCHLEVEL := $(shell echo $(KERNELVERSION) | cut -d'.' -f2)
  53.   K_SUBLEVEL := $(shell echo $(KERNELVERSION) | cut -d'.' -f3)
  54.   K_EXTRAVERSION := $(shell echo $(KERNELVERSION) | cut -d'.' -f4)
  55.  
  56.   ifeq ($(K_VERSION).$(K_PATCHLEVEL), 2.6)
  57.     # Some distributions renamed 3.x kernels to 2.6.y for some time.
  58.     ifeq ($(shell [ $(K_SUBLEVEL) -ge 41 -a $(K_SUBLEVEL) -le 46 ] && echo true), true)
  59.       SURROGATE := 3.1
  60.     else ifeq ($(K_SUBLEVEL), 40)
  61.       SURROGATE := 3.0
  62.     else
  63.       K_MAJORSUB := $(K_VERSION).$(K_PATCHLEVEL).$(K_SUBLEVEL)
  64.     endif
  65.   else ifeq ($(shell [ $(K_VERSION) -ge 3 ] && echo true), true)
  66.     # Latest available patch set in ./inc
  67.     MAX_VERSION = $(shell find $(PATCH_BASE) -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -uV | tail -n1 | cut -d'.' -f1)
  68.     MAX_PATCHSET = $(shell find $(PATCH_BASE) -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort -uV | tail -n1 | cut -d'.' -f2)
  69.     ifeq ($(shell [ $(K_VERSION) -lt $(MAX_VERSION) ] && echo true), true)
  70.       K_MAJORSUB := $(K_VERSION).$(K_PATCHLEVEL)
  71.     else ifeq ($(K_VERSION), $(MAX_VERSION))
  72.       ifeq ($(shell [ $(K_PATCHLEVEL) -gt $(MAX_PATCHSET) ] && echo true), true)
  73.         SURROGATE := $(K_VERSION).$(MAX_PATCHSET)
  74.       else
  75.         K_MAJORSUB := $(K_VERSION).$(K_PATCHLEVEL)
  76.       endif
  77.     else
  78.       # K_VERSION > MAX_VERSION
  79.       SURROGATE := $(MAX_VERSION).$(MAX_PATCHSET)
  80.     endif
  81.   else
  82.     $(error Your kernel version $(KERNELVERSION) is not supported. Please\
  83.             drop a message at http://www.linux-phc.org/forum/ if your kernel\
  84.             version is actually greater or equal to 2.6.27)
  85.   endif
  86.  
  87.   ifneq ($(SURROGATE),)
  88.     ifeq ($(origin KERNELVERSION), file)
  89.       KERNELVERSION := $(SURROGATE)
  90.     else
  91.       override KERNELVERSION := $(SURROGATE)
  92.     endif
  93.     K_MAJORSUB := $(SURROGATE)
  94.   endif
  95. endif
  96.  
  97. # Where to install module?
  98. MODULE_DEST := $(DESTDIR)/lib/modules/$(KERNELRELEASE)/extra
  99. MODULE_CONF_D := $(DESTDIR)/etc/modprobe.d
  100. MODULE_CONF := $(MODULE_CONF_D)/$(MODULE).conf
  101. # Which dkms binary to use?
  102. DKMS := $(shell for i in /usr/sbin/dkms $$(which dkms); do [ ! -d "$$i" -a -x "$$i" ] && DKMS=$$i; done; echo $$DKMS)
  103. # Where to copy dkms stuff?
  104. DKMS_DEST := $(shell [ -r /etc/dkms/framework.conf ] && . /etc/dkms/framework.conf ; echo $${source_tree:-/usr/src})
  105. DKMS_DEST := $(DKMS_DEST)/$(MODULE)-$(VERSION)
  106. # Stuff for source package creation without root privileges
  107. local_dkms := $(PWD)/.dkms
  108. local_dkmstree := $(local_dkms)
  109. local_dkmssource := $(local_dkms)/$(dir $(DKMS_DEST))
  110.  
  111. KBUILD_BASENAME=
  112.  
  113. obj-m += $(MODULE).o
  114.  
  115. CC=gcc
  116. #EXTRA_CFLAGS+=-c -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fomit-frame-pointer -fno-strict-aliasing -fno-common -pipe
  117. EXTRA_CFLAGS+=-c -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -pipe -DCONFIG_ENABLE_MUST_CHECK=y -DCONFIG_ENABLE_WARN_DEPRECATED=y
  118.  
  119. TARGET := $(MODULE).ko
  120. SOURCE := $(MODULE).c
  121.  
  122. all: .prepare $(TARGET)
  123.  
  124. gap := 15
  125. help:
  126.         @printf 'Usage: $(MAKE) [parameters] [target]\n(see $(MAKE) --help for more details)\n\nPossible targets:\n';\
  127.         printf ' %-$(gap).$(gap)s- (default target) build the kernel module\n'                  all;\
  128.         printf ' %-$(gap).$(gap)s- install the kernel module to $(MODULE_DEST)/\n'              install;\
  129.         printf ' %-$(gap).$(gap)s- uninstall the kernel module\n'                               uninstall;\
  130.         printf ' %-$(gap).$(gap)s- remove all binaries and temporary files\n'                   clean;\
  131.         printf ' %-$(gap).$(gap)s- install the module into the DKMS automated build system\n'   dkms_install;\
  132.         printf ' %-$(gap).$(gap)s- uninstall the module from DKMS automated build system\n'     dkms_uninstall;\
  133.         printf ' %-$(gap).$(gap)s- create DKMS deb source package\n'                            dkms_mkdeb;\
  134.         printf ' %-$(gap).$(gap)s- create DKMS rpm source package\n'                            dkms_mkrpm;\
  135.         printf '\nDKMS-powered targets do include all patches for every supported kernel.\n';\
  136.         printf '\nPossible parameters:\n';\
  137.         printf ' %-$(gap).$(gap)s- change location of kernel source\n %-$(gap).$(gap)s  default: %s\n' KERNELSRC '' $(KERNELSRC);\
  138.         printf ' %-$(gap).$(gap)s- use specific patch set for building kernel module\n %-$(gap).$(gap)s  default: %s\n' KERNELVERSION '' $(KERNELVERSION);\
  139.  
  140. $(TARGET): $(SOURCE)
  141.         $(MAKE) -C $(KERNELSRC) SUBDIRS=$(PWD) modules
  142.  
  143. SET := set -e
  144.  
  145. # prepare:
  146. # If KERNELVERSION is not specified outside Makefile: use latest available
  147. # patch set, regardless of actuall K_EXTRAVERSION and stuff. Only search for
  148. # exact match if user demands it.
  149. #
  150.  
  151. .prepare:
  152.         @$(SET);\
  153.         printf 'Preparing build area for $(MODULE)-$(VERSION):\nsearching for patch directory... '; \
  154.         if [ -d "$(PATCH_BASE)/$(K_MAJORSUB)" ]; then \
  155.                 DIR=$$PWD; \
  156.                 cd $(PATCH_BASE); \
  157.                 if [ "$(origin KERNELVERSION)" = file ]; then \
  158.                         PATCHDIR=$$(find -maxdepth 1 \( -name '$(K_MAJORSUB)' -o -name '$(K_MAJORSUB).*' \) -type d -printf '%f\n' | sort -uV | tail -n1) ;\
  159.                 else \
  160.                         if [ -d "$(KERNELVERSION)" ]; then \
  161.                                 PATCHDIR=$(KERNELVERSION); \
  162.                         else \
  163.                                 LIST=$$(find -maxdepth 1 \( -name '$(K_MAJORSUB)' -o -name '$(K_MAJORSUB).*' \) -type d -printf '%f\n') ;\
  164.                                 LIST="$$LIST\n$(KERNELVERSION)" ;\
  165.                                 PATCHDIR=$$(printf "$$LIST" | sort -uV | sed -n '/^'$(KERNELVERSION)'$$/{g;1!p;};h'); \
  166.                         fi; \
  167.                 fi; \
  168.                 PATCHDIR=$(PATCH_BASE)/$$PATCHDIR; \
  169.                 printf 'using %s\n' "$$PATCHDIR"; \
  170.                 cd $$DIR; \
  171.                 printf 'copying files\n'; \
  172.                 cp $$PATCHDIR/acpi-cpufreq.c phc-intel.c; \
  173.                 [ ! -e $$PATCHDIR/mperf.h ] || cp $$PATCHDIR/mperf.h .; \
  174.                 patch -p1 phc-intel.c $$PATCHDIR/linux-phc-$(VERSION).patch; \
  175.                 printf 'SUCCESS. Build area ready.\n\n'; \
  176.         else \
  177.                 printf 'FAILED. No suitable patch directory for kernel %s found.\n' "$(KERNELVERSION)"; \
  178.                 exit 1; \
  179.         fi
  180.  
  181. install: $(TARGET)
  182.         install -m 755 -o root -g root -d $(MODULE_CONF_D)
  183.         install -m 644 -o root -g root phc-intel.modprobe $(MODULE_CONF)
  184.         install -m 755 -o root -g root -d $(MODULE_DEST)
  185.         install -m 644 -o root -g root $(TARGET) $(MODULE_DEST)/
  186.         depmod $(KERNELRELEASE) -a
  187.  
  188. uninstall:
  189.         rm $(MODULE_CONF)
  190.         rm $(MODULE_DEST)/$(TARGET)
  191.         depmod $(KERNELRELEASE) -a
  192.  
  193. clean:
  194.         rm -f *~ *.o *.s *.ko *.mod.c .*.cmd *.rej *.c.orig Module.symvers Module.markers modules.order $(SOURCE) mperf.h *.deb *.rpm *.old
  195.         rm -rf .tmp_versions $(local_dkms)
  196.  
  197. .dkms_check:
  198.         @$(SET);\
  199.         [ "$(DKMS)" ] || (\
  200.                 printf 'ERROR: Unable to locate dkms.\n';\
  201.                 exit 1;\
  202.         )
  203.  
  204. .dkms_mod_check:
  205.         @$(SET);\
  206.         [ -z "$(shell $(DKMS) status -m $(MODULE))" ] || (\
  207.                 printf 'ERROR: Previous DKMS installations found. Use `$(MAKE) dkms_uninstall` to remove all of them.\n';\
  208.                 exit 1;\
  209.         )
  210.  
  211. dkms_install: .dkms_check .dkms_mod_check
  212.         @$(SET);\
  213.         for DIR in $(wildcard $(PATCH_BASE)/*); do\
  214.                 install -m 755 -o root -g root -d $(DKMS_DEST)/$$DIR;\
  215.                 install -m 644 -o root -g root $$DIR/* $(DKMS_DEST)/$$DIR;\
  216.         done;\
  217.         install -m 644 -o root -g root dkms.conf Makefile $(DKMS_DEST);\
  218.         $(DKMS) add build install -m $(MODULE) -v $(VERSION)
  219.  
  220. dkms_uninstall: .dkms_check
  221.         @$(SET);\
  222.         CANDIDATE="$$($(DKMS) status -m $(MODULE))";\
  223.         printf 'This will remove *all* dkms installations of $(MODULE) from your system:\n%s\n\nPlease type YES to confirm: ' "$$CANDIDATE";\
  224.         read input; [ "$$input" = YES ] || exit 0;\
  225.         printf '%s\n' "$$CANDIDATE" | while read head version tail; do\
  226.                 [ $$version ] || break;\
  227.                 $(DKMS) remove -m $(MODULE) -v $${version%[,:]} --all;\
  228.         done;\
  229.         rm -rf $(dir $(DKMS_DEST))$(MODULE)-*
  230.  
  231. dkms_mkdeb dkms_mkrpm: .dkms_check
  232.         @$(SET);\
  233.         KIND=$(subst dkms_,,$@);\
  234.         rm -rf $(local_dkms);\
  235.         for DIR in $(wildcard $(PATCH_BASE)/*); do\
  236.                 install -m 755 -d $(local_dkms)/$(DKMS_DEST)/$$DIR;\
  237.                 install -m 644 $$DIR/* $(local_dkms)/$(DKMS_DEST)/$$DIR;\
  238.         done;\
  239.         install -m 644 dkms.conf Makefile $(local_dkms)/$(DKMS_DEST);\
  240.         $(DKMS) add $$KIND --source-only -m $(MODULE) -v $(VERSION) --dkmstree $(local_dkmstree) --sourcetree $(local_dkmssource);\
  241.         mv $(local_dkmstree)/$(MODULE)/$(VERSION)/$${KIND#mk}/* .;\
  242.         printf '\nSource package ready to install and available at\n';\
  243.         printf ' $(PWD)/%s\n' *.$${KIND#mk} ;
  244.  
  245. brave canny:
  246.         @$(SET);\
  247.         [ $@ = canny ] && SUB=#;\
  248.         sed -i.old '/^[ \t]*# If you are brave/{n;s/^[ \t]*#*/'$$SUB'/;}' Makefile;
  249.  
  250. .NOTPARALLEL:

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN