File: gencl.sh

package info (click to toggle)
python-bumps 0.7.11-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,264 kB
  • sloc: python: 22,226; ansic: 4,973; cpp: 4,849; xml: 493; makefile: 163; perl: 108; sh: 101
file content (50 lines) | stat: -rwxr-xr-x 1,773 bytes parent folder | download | duplicates (4)
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
#!/bin/sh
# Run the C preprocessor on an OpenCL kernel to generate a C string array
# suitable for clCreateProgramWithSource.  This allows us to create
# standalone OpenCL programs that do not depend on paths to the source
# tree (the programs will still run the OpenCL run-time compiler to
# compile the kernel, but the kernel is a string within the program, with
# no external include dependencies)
# Mark Moraes, D. E. Shaw Research

# indenting the cpp output makes errors from the OpenCL runtime compiler
# much more understandable.  User can override with whatever they want.
# The classic BSD indent (yes, the one that lived in /usr/ucb/indent once)
# defaults to -br, but recent GNU indent versions do not.  Both appear to
# accept -br, fortunately... (BSD indent does not accept -kr or -linux, alas)

PATH=$PATH:/usr/bin
export PATH
if type indent > /dev/null 2>&1; then
	: ${GENCL_INDENT="indent -br"}
else
	: ${GENCL_INDENT=cat}
fi

# We rely on gsub in awk, which exists in everything except classic
# old V7 awk (Solaris!).  If we can find gawk or nawk, we prefer those.
# http://www.shelldorado.com/articles/awkcompat.html
for f in gawk nawk awk; do
	if type "$f" > /dev/null 2>&1; then
		: ${GENCL_AWK="$f"}
		break
	fi
done
case "${GENCL_AWK}" in
'')	echo "$0: could not find awk!">&2; exit 1;;
esac
usage="Usage: $0 inputoclfilename outputfilename"
case $# in
2)	;;
*)	echo "$usage" >&2; exit 1;;
esac
case "$1" in
''|-*)	echo "Invalid or empty inputoclfilename: $1
$usage" >&2; exit 1;;
esac
set -e
${CC-cc} -xc -E -P -nostdinc -D__OPENCL_VERSION__=1 $CPPFLAGS "$1" | 
	${GENCL_INDENT} | 
	${GENCL_AWK} 'BEGIN {print "static const char *opencl_src = \"\\n\\"}
	{gsub("\\", "\\\\", $0); gsub("\"", "\\\"", $0); print $0 "\\n\\"}
	END {print "\";"}' > "$2"