wcte12xp, wctdm24xxp: spin_lock_bh -> spin_lock_irqsave
[asterisk-tools:sruffells-dahdi-linux.git] / Makefile
1 #
2 # Makefile for DAHDI Linux kernel modules
3 #
4 # Copyright (C) 2001-2009 Digium, Inc.
5 #
6 #
7
8 PWD:=$(shell pwd)
9
10 DAHDI_MODULES_EXTRA:=$(MODULES_EXTRA:%=%.o) $(SUBDIRS_EXTRA:%=%/)
11
12 # If you want to build for a kernel other than the current kernel, set KVERS
13 ifndef KVERS
14 KVERS:=$(shell uname -r)
15 endif
16 ifndef KSRC
17   ifneq (,$(wildcard /lib/modules/$(KVERS)/build))
18     KSRC:=/lib/modules/$(KVERS)/build
19   else
20     KSRC_SEARCH_PATH:=/usr/src/linux
21     KSRC:=$(shell for dir in $(KSRC_SEARCH_PATH); do if [ -d $$dir ]; then echo $$dir; break; fi; done)
22   endif
23 endif
24 KVERS_MAJ:=$(shell echo $(KVERS) | cut -d. -f1-2)
25 KINCLUDES:=$(KSRC)/include
26
27 # We use the kernel's .config file as an indication that the KSRC
28 # directory is indeed a valid and configured kernel source (or partial
29 # source) directory.
30 #
31 # We also source it, as it has the format of Makefile variables list.
32 # Thus we will have many CONFIG_* variables from there.
33 KCONFIG:=$(KSRC)/.config
34 ifneq (,$(wildcard $(KCONFIG)))
35   HAS_KSRC:=yes
36   include $(KCONFIG)
37 else
38   HAS_KSRC:=no
39 endif
40
41 CHECKSTACK=$(KSRC)/scripts/checkstack.pl
42
43 # Set HOTPLUG_FIRMWARE=no to override automatic building with hotplug support
44 # if it is enabled in the kernel.
45
46 ifeq (yes,$(HAS_KSRC))
47   HOTPLUG_FIRMWARE:=$(shell if grep -q '^CONFIG_FW_LOADER=[ym]' $(KCONFIG); then echo "yes"; else echo "no"; fi)
48 endif
49
50 UDEV_DIR:=/etc/udev/rules.d
51
52 MODULE_ALIASES:=wcfxs wctdm8xxp wct2xxp
53
54 INST_HEADERS:=kernel.h user.h fasthdlc.h wctdm_user.h dahdi_config.h
55
56 DAHDI_BUILD_ALL:=m
57
58 KMAKE=$(MAKE) -C $(KSRC) SUBDIRS=$(PWD)/drivers/dahdi DAHDI_INCLUDE=$(PWD)/include DAHDI_MODULES_EXTRA="$(DAHDI_MODULES_EXTRA)" HOTPLUG_FIRMWARE=$(HOTPLUG_FIRMWARE)
59
60 ROOT_PREFIX:=
61
62 ASCIIDOC:=asciidoc
63 ASCIIDOC_CMD:=$(ASCIIDOC) -n -a toc -a toclevels=4
64
65 GENERATED_DOCS:=README.html
66
67 ifneq ($(wildcard .version),)
68   DAHDIVERSION:=$(shell cat .version)
69 else
70 ifneq ($(wildcard .svn),)
71   DAHDIVERSION:=$(shell build_tools/make_version . dahdi/linux)
72 endif
73 endif
74
75 all: modules
76
77 modules: prereq
78 ifeq (no,$(HAS_KSRC))
79         @echo "You do not appear to have the sources for the $(KVERS) kernel installed."
80         @exit 1
81 endif
82         $(KMAKE) modules DAHDI_BUILD_ALL=$(DAHDI_BUILD_ALL)
83
84 include/dahdi/version.h: FORCE
85         @DAHDIVERSION="${DAHDIVERSION}" build_tools/make_version_h > $@.tmp
86         @if cmp -s $@.tmp $@ ; then :; else \
87                 mv $@.tmp $@ ; \
88         fi
89         @rm -f $@.tmp
90
91 prereq: include/dahdi/version.h firmware-loaders
92
93 stackcheck: $(CHECKSTACK) modules
94         objdump -d drivers/dahdi/*.ko drivers/dahdi/*/*.ko | $(CHECKSTACK)
95
96 install: all install-modules install-devices install-include install-firmware install-xpp-firm
97         @echo "###################################################"
98         @echo "###"
99         @echo "### DAHDI installed successfully."
100         @echo "### If you have not done so before, install the package"
101         @echo "### dahdi-tools."
102         @echo "###"
103         @echo "###################################################"
104
105 uninstall: uninstall-modules uninstall-devices uninstall-include uninstall-firmware
106
107 install-modconf:
108         build_tools/genmodconf $(BUILDVER) "$(ROOT_PREFIX)" "$(filter-out dahdi dahdi_dummy xpp dahdi_transcode dahdi_dynamic,$(BUILD_MODULES)) $(MODULE_ALIASES)"
109         @if [ -d /etc/modutils ]; then \
110                 /sbin/update-modules ; \
111         fi
112
113 install-xpp-firm:
114         $(MAKE) -C drivers/dahdi/xpp/firmwares install
115
116 install-firmware:
117 ifeq ($(HOTPLUG_FIRMWARE),yes)
118         $(MAKE) -C drivers/dahdi/firmware hotplug-install DESTDIR=$(DESTDIR) HOTPLUG_FIRMWARE=$(HOTPLUG_FIRMWARE)
119 endif
120
121 uninstall-firmware:
122         $(MAKE) -C drivers/dahdi/firmware hotplug-uninstall DESTDIR=$(DESTDIR)
123
124 firmware-loaders:
125         $(MAKE) -C drivers/dahdi/firmware firmware-loaders
126
127 install-include:
128         for hdr in $(INST_HEADERS); do \
129                 install -D -m 644 include/dahdi/$$hdr $(DESTDIR)/usr/include/dahdi/$$hdr; \
130         done
131         @rm -rf $(DESTDIR)/usr/include/zaptel
132
133 uninstall-include:
134         for hdr in $(INST_HEADERS); do \
135                 rm -f $(DESTDIR)/usr/include/dahdi/$$hdr; \
136         done
137         -rmdir $(DESTDIR)/usr/include/dahdi
138
139 install-devices:
140         install -d $(DESTDIR)$(UDEV_DIR)
141         build_tools/genudevrules > $(DESTDIR)$(UDEV_DIR)/dahdi.rules
142         install -m 644 drivers/dahdi/xpp/xpp.rules $(DESTDIR)$(UDEV_DIR)/
143
144 uninstall-devices:
145         rm -f $(DESTDIR)$(UDEV_DIR)/dahdi.rules
146
147 install-modules: modules
148 ifndef DESTDIR
149         @if modinfo zaptel > /dev/null 2>&1; then \
150                 echo -n "Removing Zaptel modules for kernel $(KVERS), please wait..."; \
151                 build_tools/uninstall-modules zaptel $(KVERS); \
152                 rm -rf /lib/modules/$(KVERS)/zaptel; \
153                 echo "done."; \
154         fi
155         build_tools/uninstall-modules dahdi $(KVERS)
156 endif
157         $(KMAKE) INSTALL_MOD_PATH=$(DESTDIR) INSTALL_MOD_DIR=dahdi modules_install
158         [ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || :
159
160 uninstall-modules:
161 ifdef DESTDIR
162         @echo "Uninstalling modules is not supported with a DESTDIR specified."
163         @exit 1
164 else
165         @if modinfo dahdi > /dev/null 2>&1 ; then \
166                 echo -n "Removing DAHDI modules for kernel $(KVERS), please wait..."; \
167                 build_tools/uninstall-modules dahdi $(KVERS); \
168                 rm -rf /lib/modules/$(KVERS)/dahdi; \
169                 echo "done."; \
170         fi
171         [ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || :
172 endif
173
174 update:
175         @if [ -d .svn ]; then \
176                 echo "Updating from Subversion..." ; \
177                 svn update | tee update.out; \
178                 rm -f .version; \
179                 if [ `grep -c ^C update.out` -gt 0 ]; then \
180                         echo ; echo "The following files have conflicts:" ; \
181                         grep ^C update.out | cut -b4- ; \
182                 fi ; \
183                 rm -f update.out; \
184         else \
185                 echo "Not under version control";  \
186         fi
187
188 clean:
189 ifneq (no,$(HAS_KSRC))
190         $(KMAKE) clean
191 endif
192         @rm -f $(GENERATED_DOCS)
193         $(MAKE) -C drivers/dahdi/firmware clean
194
195 distclean: dist-clean
196
197 dist-clean: clean
198         @rm -f include/dahdi/version.h
199         @$(MAKE) -C drivers/dahdi/firmware dist-clean
200         @rm -f drivers/dahdi/vpmadt032_loader/*.o_shipped
201
202 firmware-download:
203         @$(MAKE) -C drivers/dahdi/firmware all
204
205 test:
206         ./test-script $(DESTDIR)/lib/modules/$(KVERS) dahdi
207
208 docs: $(GENERATED_DOCS)
209
210 README.html: README
211         $(ASCIIDOC_CMD) -o $@ $<
212
213 dahdi-api.html: drivers/dahdi/dahdi-base.c
214         build_tools/kernel-doc --kernel $(KSRC) $^ >$@
215
216 .PHONY: distclean dist-clean clean all install devices modules stackcheck install-udev update install-modules install-include uninstall-modules firmware-download install-xpp-firm firmware-loaders
217
218 FORCE: