File: as-modtool.m4

package info (click to toggle)
comedi 0.7.76+20090411cvs-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 7,720 kB
  • ctags: 14,291
  • sloc: ansic: 105,119; sh: 1,210; makefile: 628; perl: 457
file content (155 lines) | stat: -rw-r--r-- 4,063 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
dnl as-modtool.m4 0.0.1
dnl autostars m4 macro for building modtool, a linker for Linux kernel
dnl modules

dnl David Schleef <ds@schleef.org>
dnl Frank Mori Hess <fmhess@users.sourceforge.net>
dnl Thomas Vander Stichele <thomas@apestaart.org>

dnl $Id: as-modtool.m4,v 1.7 2006-07-10 10:06:34 abbotti Exp $

dnl AS_LINUX_MODTOOL()
dnl
dnl this macro defines:
dnl moduledir
dnl modulePROGRAMS_INSTALL
dnl modulePROGRAMS_UNINSTALL
dnl
dnl End of search list.

dnl
dnl FIXME:
dnl  How do you specify that the building of modtool should go to the
dnl  end of the configure script?
dnl

dnl SYMVERS_INCLUDES can be used to add additional .symvers files to the
dnl modpost step

AC_DEFUN([AS_LINUX_MODTOOL],
[
	AC_PATH_TOOL([STRIP], [strip])
	AC_PATH_PROG([DEPMOD], [depmod], [no], [$PATH:/sbin:/usr/sbin:/usr/local/sbin])

	dnl this can be overridden in Makefile.am
	dnl FIXME: it'd be nice if we could specify different target_PROGRAMS
	dnl and different targetdir
	moduledir="\$(modulesdir)/\$(PACKAGE)"
	modulePROGRAMS_INSTALL="\$(top_builddir)/modtool --install"
	modulePROGRAMS_UNINSTALL="\$(top_builddir)/modtool --uninstall"
	AC_SUBST(moduledir)
	AC_SUBST(modulePROGRAMS_INSTALL)

	AC_MSG_NOTICE(creating modtool)
	cat >modtool <<EOF
#!/bin/sh

set -e
#set -x

LINUX_LD="$LINUX_LD"
LINUX_MODPOST="$LINUX_MODPOST"
CC="$LINUX_CC"
INSTALL="$INSTALL"
LINUX_MODULE_EXT="$LINUX_MODULE_EXT"
STRIP="$STRIP"
CFLAGS="$CFLAGS $LINUX_CFLAGS"
LINUX_DIR="$LINUX_DIR"
LINUX_MODULE_STYLE="$LINUX_MODULE_STYLE"
DEPMOD="$DEPMOD"
LINUX_KERNELRELEASE="$LINUX_KERNELRELEASE"

mode=\$[1]
shift

case \$mode in
--link)
	# we accept -i (symvers) and -o (target) as options
	# at least -o (target) needs to be specified
	SYMVERS_INCLUDES=""
	done=false
	while test ! -z "\$[0]" -a "\$done" = "false"
	do
		case \$[1] in
		-i)
                        SYMVERS_INCLUDES="\$SYMVERS_INCLUDES \$[2]"
                        shift 2
                        ;;
                -o)
                        target=\$(echo \$[2] | sed s/.ko$//)
                        shift 2
                        ;;
                *)
                        done=true
                        ;;
                esac
        done

	case "\$LINUX_MODULE_STYLE" in
	2.6.6)
		set -x
		mkdir -p .mods

		echo \$LINUX_LD -r -o .mods/\$target.o \$[*]
		\$LINUX_LD -r -o .mods/\$target.o \$[*]

		echo "cat \$LINUX_DIR/Module.symvers \$SYMVERS_INCLUDES >.mods/symvers.tmp || touch .mods/symvers.tmp"
		cat \$LINUX_DIR/Module.symvers \$SYMVERS_INCLUDES >.mods/symvers.tmp || touch .mods/symvers.tmp

		echo "\$LINUX_MODPOST -o .mods/\$target.o.symvers.tmp -i .mods/symvers.tmp \$target.o"
		\$LINUX_MODPOST -o .mods/\$target.o.symvers.tmp -i .mods/symvers.tmp .mods/\$target.o

		echo "grep .mods/\$target .mods/\$target.o.symvers.tmp >.mods/\$target.o.symvers || true"
		grep .mods/\$target .mods/\$target.o.symvers.tmp >.mods/\$target.o.symvers || true

		echo "rm -f .mods/\$target.o.symvers.tmp .mods/symvers.tmp"
		rm -f .mods/\$target.o.symvers.tmp .mods/symvers.tmp
		
		echo \$CC \$CFLAGS -DKBUILD_MODNAME=\$target -c -o .mods/\$target.mod.o .mods/\$target.mod.c
		\$CC \$CFLAGS -DKBUILD_MODNAME=\$target -c -o .mods/\$target.mod.o .mods/\$target.mod.c

		echo \$LINUX_LD -r -o \$target.ko .mods/\$target.mod.o .mods/\$target.o
		\$LINUX_LD -r -o \$target.ko .mods/\$target.mod.o .mods/\$target.o
		set +x

		;;
	2.6.0)
		;;
	2.4.0)
		echo \$LINUX_LD -r -o \$target.ko \$[*]
		\$LINUX_LD -r -o \$target.ko \$[*]
		;;
	esac

	;;
--install)
	module_src=\$[1]
	module_dest=\`echo \$[2] | sed "s/\.ko$/\${LINUX_MODULE_EXT}/"\`
	echo \$INSTALL -m644 "\$module_src" "\$module_dest"
	\$INSTALL -m644 "\$module_src" "\$module_dest"
	\$STRIP -g "\$module_dest"
	;;
--uninstall)
	module_src=\$[1]
	module_dest=\`echo \$[2] | sed "s/\.ko$/\${LINUX_MODULE_EXT}/"\`
	echo uninstall "\$module_src" "\$module_dest"
	rm -f "\$module_dest"
	;;
--finish)
	# run depmod here
	if [ "$prefix" = "/" ] ; then
		\$DEPMOD -ae \$LINUX_KERNELRELEASE
	fi
	;;
*)
	echo Unknown mode \$mode >&2
	exit 1
esac

EOF
	chmod +x modtool


])