dahdi_dynamic: Do not call into dahdi_dynamic without holding reference.
[dahdi/linux.git] / Makefile
1 #
2 # Makefile for DAHDI Linux kernel modules
3 #
4 # Copyright (C) 2001-2010 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 else
73 ifneq ($(wildcard .git),)
74   DAHDIVERSION:=$(shell build_tools/make_version . dahdi/linux)
75 endif
76 endif
77 endif
78
79 all: modules
80
81 modules: prereq
82 ifeq (no,$(HAS_KSRC))
83         @echo "You do not appear to have the sources for the $(KVERS) kernel installed."
84         @exit 1
85 endif
86         $(KMAKE) modules DAHDI_BUILD_ALL=$(DAHDI_BUILD_ALL)
87
88 include/dahdi/version.h: FORCE
89         @DAHDIVERSION="${DAHDIVERSION}" build_tools/make_version_h > $@.tmp
90         @if cmp -s $@.tmp $@ ; then :; else \
91                 mv $@.tmp $@ ; \
92         fi
93         @rm -f $@.tmp
94
95 prereq: include/dahdi/version.h firmware-loaders
96
97 stackcheck: $(CHECKSTACK) modules
98         objdump -d drivers/dahdi/*.ko drivers/dahdi/*/*.ko | $(CHECKSTACK)
99
100 install: all install-modules install-devices install-include install-firmware install-xpp-firm
101         @echo "###################################################"
102         @echo "###"
103         @echo "### DAHDI installed successfully."
104         @echo "### If you have not done so before, install the package"
105         @echo "### dahdi-tools."
106         @echo "###"
107         @echo "###################################################"
108
109 uninstall: uninstall-modules uninstall-devices uninstall-include uninstall-firmware
110
111 install-modconf:
112         build_tools/genmodconf $(BUILDVER) "$(ROOT_PREFIX)" "$(filter-out dahdi dahdi_dummy xpp dahdi_transcode dahdi_dynamic,$(BUILD_MODULES)) $(MODULE_ALIASES)"
113         @if [ -d /etc/modutils ]; then \
114                 /sbin/update-modules ; \
115         fi
116
117 install-xpp-firm:
118         $(MAKE) -C drivers/dahdi/xpp/firmwares install
119
120 install-firmware:
121 ifeq ($(HOTPLUG_FIRMWARE),yes)
122         $(MAKE) -C drivers/dahdi/firmware hotplug-install DESTDIR=$(DESTDIR) HOTPLUG_FIRMWARE=$(HOTPLUG_FIRMWARE)
123 endif
124
125 uninstall-firmware:
126         $(MAKE) -C drivers/dahdi/firmware hotplug-uninstall DESTDIR=$(DESTDIR)
127
128 firmware-loaders:
129         $(MAKE) -C drivers/dahdi/firmware firmware-loaders
130
131 install-include:
132         for hdr in $(INST_HEADERS); do \
133                 install -D -m 644 include/dahdi/$$hdr $(DESTDIR)/usr/include/dahdi/$$hdr; \
134         done
135         @rm -rf $(DESTDIR)/usr/include/zaptel
136
137 uninstall-include:
138         for hdr in $(INST_HEADERS); do \
139                 rm -f $(DESTDIR)/usr/include/dahdi/$$hdr; \
140         done
141         -rmdir $(DESTDIR)/usr/include/dahdi
142
143 install-devices:
144         install -d $(DESTDIR)$(UDEV_DIR)
145         build_tools/genudevrules > $(DESTDIR)$(UDEV_DIR)/dahdi.rules
146         install -m 644 drivers/dahdi/xpp/xpp.rules $(DESTDIR)$(UDEV_DIR)/
147
148 uninstall-devices:
149         rm -f $(DESTDIR)$(UDEV_DIR)/dahdi.rules
150
151 install-modules: modules
152 ifndef DESTDIR
153         @if modinfo zaptel > /dev/null 2>&1; then \
154                 echo -n "Removing Zaptel modules for kernel $(KVERS), please wait..."; \
155                 build_tools/uninstall-modules zaptel $(KVERS); \
156                 rm -rf /lib/modules/$(KVERS)/zaptel; \
157                 echo "done."; \
158         fi
159         build_tools/uninstall-modules dahdi $(KVERS)
160 endif
161         $(KMAKE) INSTALL_MOD_PATH=$(DESTDIR) INSTALL_MOD_DIR=dahdi modules_install
162         [ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || :
163
164 uninstall-modules:
165 ifdef DESTDIR
166         @echo "Uninstalling modules is not supported with a DESTDIR specified."
167         @exit 1
168 else
169         @if modinfo dahdi > /dev/null 2>&1 ; then \
170                 echo -n "Removing DAHDI modules for kernel $(KVERS), please wait..."; \
171                 build_tools/uninstall-modules dahdi $(KVERS); \
172                 rm -rf /lib/modules/$(KVERS)/dahdi; \
173                 echo "done."; \
174         fi
175         [ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || :
176 endif
177
178 update:
179         @if [ -d .svn ]; then \
180                 echo "Updating from Subversion..." ; \
181                 svn update | tee update.out; \
182                 rm -f .version; \
183                 if [ `grep -c ^C update.out` -gt 0 ]; then \
184                         echo ; echo "The following files have conflicts:" ; \
185                         grep ^C update.out | cut -b4- ; \
186                 fi ; \
187                 rm -f update.out; \
188         else \
189                 echo "Not under version control";  \
190         fi
191
192 clean:
193 ifneq (no,$(HAS_KSRC))
194         $(KMAKE) clean
195 endif
196         @rm -f $(GENERATED_DOCS)
197         $(MAKE) -C drivers/dahdi/firmware clean
198
199 distclean: dist-clean
200
201 dist-clean: clean
202         @rm -f include/dahdi/version.h
203         @$(MAKE) -C drivers/dahdi/firmware dist-clean
204         @rm -f drivers/dahdi/vpmadt032_loader/*.o_shipped
205
206 firmware-download:
207         @$(MAKE) -C drivers/dahdi/firmware all
208
209 test:
210         ./test-script $(DESTDIR)/lib/modules/$(KVERS) dahdi
211
212 docs: $(GENERATED_DOCS)
213
214 README.html: README
215         $(ASCIIDOC_CMD) -o $@ $<
216
217 dahdi-api.html: drivers/dahdi/dahdi-base.c
218         build_tools/kernel-doc --kernel $(KSRC) $^ >$@
219
220 .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
221
222 FORCE: