-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathextract_headers.sh
executable file
·54 lines (42 loc) · 1.5 KB
/
extract_headers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
if [ "x$1" = "x" ]; then
echo "Usage: $(basename $0) <path of NVIDIA open-gpu-kernel-modules project>"
exit 1
fi
OUTPUT_DIR=nvidia-include
DIR=$1
NEWLINE=$'\n'
DIRS=""
INC_DIRS=""
INC_FILES="#ifndef NVIDIA_H_${NEWLINE}#define NVIDIA_H_${NEWLINE}"
while IFS= read -r line; do
#echo got line: $line
if [[ $line =~ ^d\ .+ ]]; then
DIRS="$DIRS$DIR/${line//d /}${NEWLINE}"
INC_DIRS="$INC_DIRS -I$DIR/${line//d /}"
elif [[ $line =~ ^f\ .+ ]]; then
INC_FILES="${INC_FILES}#include <${line//f /}>${NEWLINE}"
elif [[ $line =~ ^#.+ ]]; then
INC_FILES="${INC_FILES}${line}${NEWLINE}"
fi
done < headers.in
INC_FILES="${INC_FILES}#endif${NEWLINE}"
#echo got dirs: "$DIRS"
#echo got inc dirs: $INC_DIRS
#echo got inc files: "$INC_FILES"
mkdir -p ${OUTPUT_DIR}
echo "${INC_FILES}" > ${OUTPUT_DIR}/nvidia.h
INCLUDED_FILES=$(cpp $INC_DIRS -H ${OUTPUT_DIR}/nvidia.h 2>&1 1>/dev/null | grep -E '^\.' | grep -Eo "$DIR.*")
for f in $INCLUDED_FILES; do
for d in $DIRS; do
if [[ "$f" == "$d"* ]]; then
dest_file=${OUTPUT_DIR}/${f//$d/}
mkdir -p $(dirname ${dest_file})
echo Copying ${dest_file}
cp $f ${dest_file}
fi
done
done
#fixup nvidia-drm-ioctl.h as it includes a kernel header, and we'd like it to be able to choose
mv ${OUTPUT_DIR}/nvidia-drm-ioctl.h ${OUTPUT_DIR}/nvidia-drm-ioctl.h.bak
sed 's$#include <drm/drm.h>$#include <drm.h>$' < ${OUTPUT_DIR}/nvidia-drm-ioctl.h.bak > ${OUTPUT_DIR}/nvidia-drm-ioctl.h