Linux Audio

Check our new training course

Loading...
v4.17
  1#!/bin/sh
 
  2
  3# Script to create/update include/generated/autoksyms.h and dependency files
  4#
  5# Copyright:	(C) 2016  Linaro Limited
  6# Created by:	Nicolas Pitre, January 2016
  7#
  8# This program is free software; you can redistribute it and/or modify
  9# it under the terms of the GNU General Public License version 2 as
 10# published by the Free Software Foundation.
 11
 12# Create/update the include/generated/autoksyms.h file from the list
 13# of all module's needed symbols as recorded on the third line of
 14# .tmp_versions/*.mod files.
 15#
 16# For each symbol being added or removed, the corresponding dependency
 17# file's timestamp is updated to force a rebuild of the affected source
 18# file. All arguments passed to this script are assumed to be a command
 19# to be exec'd to trigger a rebuild of those files.
 20
 21set -e
 22
 23cur_ksyms_file="include/generated/autoksyms.h"
 24new_ksyms_file="include/generated/autoksyms.h.tmpnew"
 25
 26info() {
 27	if [ "$quiet" != "silent_" ]; then
 28		printf "  %-7s %s\n" "$1" "$2"
 29	fi
 30}
 31
 32info "CHK" "$cur_ksyms_file"
 33
 34# Use "make V=1" to debug this script.
 35case "$KBUILD_VERBOSE" in
 36*1*)
 37	set -x
 38	;;
 39esac
 40
 41# We need access to CONFIG_ symbols
 42case "${KCONFIG_CONFIG}" in
 43*/*)
 44	. "${KCONFIG_CONFIG}"
 45	;;
 46*)
 47	# Force using a file from the current directory
 48	. "./${KCONFIG_CONFIG}"
 49esac
 50
 51# Generate a new ksym list file with symbols needed by the current
 52# set of modules.
 53cat > "$new_ksyms_file" << EOT
 54/*
 55 * Automatically generated file; DO NOT EDIT.
 56 */
 57
 58EOT
 59[ "$(ls -A "$MODVERDIR")" ] &&
 60for mod in "$MODVERDIR"/*.mod; do
 61	sed -n -e '3{s/ /\n/g;/^$/!p;}' "$mod"
 62done | sort -u |
 63while read sym; do
 64	if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then
 65		sym="${sym#_}"
 66	fi
 67	echo "#define __KSYM_${sym} 1"
 68done >> "$new_ksyms_file"
 69
 70# Special case for modversions (see modpost.c)
 71if [ -n "$CONFIG_MODVERSIONS" ]; then
 72	echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
 73fi
 74
 75# Extract changes between old and new list and touch corresponding
 76# dependency files.
 77changed=$(
 78count=0
 79sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
 80sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
 81while read sympath; do
 82	if [ -z "$sympath" ]; then continue; fi
 83	depfile="include/ksym/${sympath}.h"
 84	mkdir -p "$(dirname "$depfile")"
 85	touch "$depfile"
 86	# Filesystems with coarse time precision may create timestamps
 87	# equal to the one from a file that was very recently built and that
 88	# needs to be rebuild. Let's guard against that by making sure our
 89	# dep files are always newer than the first file we created here.
 90	while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
 91		touch "$depfile"
 92	done
 93	echo $((count += 1))
 94done | tail -1 )
 95changed=${changed:-0}
 96
 97if [ $changed -gt 0 ]; then
 98	# Replace the old list with tne new one
 99	old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
100	new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
101	info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
102	info "UPD" "$cur_ksyms_file"
103	mv -f "$new_ksyms_file" "$cur_ksyms_file"
104	# Then trigger a rebuild of affected source files
105	exec $@
106else
107	rm -f "$new_ksyms_file"
108fi
v5.4
 1#!/bin/sh
 2# SPDX-License-Identifier: GPL-2.0-only
 3
 4# Script to create/update include/generated/autoksyms.h and dependency files
 5#
 6# Copyright:	(C) 2016  Linaro Limited
 7# Created by:	Nicolas Pitre, January 2016
 8#
 
 
 
 9
10# Create/update the include/generated/autoksyms.h file from the list
11# of all module's needed symbols as recorded on the second line of *.mod files.
 
12#
13# For each symbol being added or removed, the corresponding dependency
14# file's timestamp is updated to force a rebuild of the affected source
15# file. All arguments passed to this script are assumed to be a command
16# to be exec'd to trigger a rebuild of those files.
17
18set -e
19
20cur_ksyms_file="include/generated/autoksyms.h"
21new_ksyms_file="include/generated/autoksyms.h.tmpnew"
22
23info() {
24	if [ "$quiet" != "silent_" ]; then
25		printf "  %-7s %s\n" "$1" "$2"
26	fi
27}
28
29info "CHK" "$cur_ksyms_file"
30
31# Use "make V=1" to debug this script.
32case "$KBUILD_VERBOSE" in
33*1*)
34	set -x
35	;;
36esac
37
38# We need access to CONFIG_ symbols
39. include/config/auto.conf
 
 
 
 
 
 
 
40
41# Generate a new ksym list file with symbols needed by the current
42# set of modules.
43cat > "$new_ksyms_file" << EOT
44/*
45 * Automatically generated file; DO NOT EDIT.
46 */
47
48EOT
49sed 's/ko$/mod/' modules.order |
50xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- |
51sort -u |
52sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$new_ksyms_file"
 
 
 
 
 
 
53
54# Special case for modversions (see modpost.c)
55if [ -n "$CONFIG_MODVERSIONS" ]; then
56	echo "#define __KSYM_module_layout 1" >> "$new_ksyms_file"
57fi
58
59# Extract changes between old and new list and touch corresponding
60# dependency files.
61changed=$(
62count=0
63sort "$cur_ksyms_file" "$new_ksyms_file" | uniq -u |
64sed -n 's/^#define __KSYM_\(.*\) 1/\1/p' | tr "A-Z_" "a-z/" |
65while read sympath; do
66	if [ -z "$sympath" ]; then continue; fi
67	depfile="include/ksym/${sympath}.h"
68	mkdir -p "$(dirname "$depfile")"
69	touch "$depfile"
70	# Filesystems with coarse time precision may create timestamps
71	# equal to the one from a file that was very recently built and that
72	# needs to be rebuild. Let's guard against that by making sure our
73	# dep files are always newer than the first file we created here.
74	while [ ! "$depfile" -nt "$new_ksyms_file" ]; do
75		touch "$depfile"
76	done
77	echo $((count += 1))
78done | tail -1 )
79changed=${changed:-0}
80
81if [ $changed -gt 0 ]; then
82	# Replace the old list with tne new one
83	old=$(grep -c "^#define __KSYM_" "$cur_ksyms_file" || true)
84	new=$(grep -c "^#define __KSYM_" "$new_ksyms_file" || true)
85	info "KSYMS" "symbols: before=$old, after=$new, changed=$changed"
86	info "UPD" "$cur_ksyms_file"
87	mv -f "$new_ksyms_file" "$cur_ksyms_file"
88	# Then trigger a rebuild of affected source files
89	exec $@
90else
91	rm -f "$new_ksyms_file"
92fi