-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
116 lines (105 loc) · 3.62 KB
/
Makefile
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
# max number of supported w1 bus masters
CONFIG_W1_MAST_MAX ?= 5
KERN_BLD_DIR:=$(shell if [ "${KERNEL_SRC}x" = "x" ]; then echo "/lib/modules/`uname -r`/build"; else echo "${KERNEL_SRC}"; fi;)
KERN_SRC_DIR:=$(shell if [ "${KERNEL_SRC}x" = "x" ]; then echo "/lib/modules/`uname -r`/source"; else echo "${KERNEL_SRC}"; fi;)
.PHONY: all clean distclean gen-mast w1-headers install uninstall tags
obj-m = w1-gpio-cl.o
ccflags-y = -DCONFIG_W1_MAST_MAX=${CONFIG_W1_MAST_MAX}
all: gen-mast
$(MAKE) -C ${KERN_BLD_DIR} M=$(PWD) modules
clean:
-$(MAKE) -C ${KERN_BLD_DIR} M=$(PWD) clean
rm -f gen-mast.h
distclean: clean
rm -f w1 kernel-source kernel-build tags
gen-mast: w1-headers
@if [ ${CONFIG_W1_MAST_MAX} -lt 1 -o ${CONFIG_W1_MAST_MAX} -gt 100 ]; then \
echo "ERROR: Invalid CONFIG_W1_MAST_MAX"; \
exit 1; \
fi
@for i in `seq 1 ${CONFIG_W1_MAST_MAX}`; \
do \
case $$i in \
1) \
echo "/*" >[email protected]; \
echo " * This file was auto-generated." >>[email protected]; \
echo " * Don't edit it or changes will be lost." >>[email protected]; \
echo " */" >>[email protected]; \
if [ -f w1/w1_int.h ]; then \
echo "#include \"w1/w1_int.h\"" >>[email protected]; \
else \
echo "#include \"w1/w1.h\"" >>[email protected]; \
fi; \
echo >>[email protected]; \
if [ `grep -c bitbang_pullup w1/w1.h` -gt 0 ]; then \
echo "NOTE: bitbang_pullup() supported as a pullup callback"; \
echo "#ifndef CONFIG_W1_BITBANG_PULLUP" >>[email protected]; \
echo "# define CONFIG_W1_BITBANG_PULLUP 1" >>[email protected]; \
echo "#endif" >>[email protected]; \
echo >>[email protected]; \
fi; \
pf="st";; \
21|31|41|51|61|71|81|91) \
pf="st";; \
2|22|32|42|52|62|72|82|92) \
pf="nd";; \
3|23|33|43|53|63|73|83|93) \
pf="rd";; \
*) \
pf="th";; \
esac; \
echo "static char *m$$i=NULL;" >>[email protected]; \
echo "module_param(m$$i, charp, 0444);" >>[email protected]; \
echo "MODULE_PARM_DESC(m$$i, \"$$i$$pf w1 bus master specification\");" >>[email protected]; \
echo >>[email protected]; \
done; \
echo "static const char *get_mast_arg(int i)" >>[email protected]; \
echo "{" >>[email protected]; \
echo " switch (i+1)" >>[email protected]; \
echo " {" >>[email protected]; \
for i in `seq 1 ${CONFIG_W1_MAST_MAX}`; \
do \
echo " case $$i: return m$$i;" >>[email protected]; \
done; \
echo " }" >>[email protected]; \
echo " return NULL;" >>[email protected]; \
echo "}" >>[email protected]; \
echo "NOTE: [email protected] was generated";
w1-headers:
@if [ ! -L w1 ]; then \
if [ -f ${KERN_SRC_DIR}/include/linux/w1.h ]; then \
ln -s ${KERN_SRC_DIR}/include/linux w1; \
echo "NOTE: w1 -> ${KERN_SRC_DIR}/include/linux"; \
elif [ -f ${KERN_SRC_DIR}/drivers/w1/w1_int.h ]; then \
ln -s ${KERN_SRC_DIR}/drivers/w1 w1; \
echo "NOTE: w1 -> ${KERN_SRC_DIR}/drivers/w1"; \
elif [ -f ${KERN_BLD_DIR}/include/linux/w1.h ]; then \
ln -s ${KERN_BLD_DIR}/include/linux w1; \
echo "NOTE: w1 -> ${KERN_BLD_DIR}/include/linux"; \
elif [ -f ${KERN_BLD_DIR}/drivers/w1/w1_int.h ]; then \
ln -s ${KERN_BLD_DIR}/drivers/w1 w1; \
echo "NOTE: w1 -> ${KERN_BLD_DIR}/drivers/w1"; \
else \
echo "ERROR: w1 headers not found"; \
exit 1; \
fi; \
else \
echo "NOTE: ./w1 symlink is already set and will not be updated. \
Remove it and restart the compilation process in case you want to re-run the \
kernel sources examination."; \
fi;
install:
install -m644 $(obj-m:.o=.ko) /lib/modules/`uname -r`/kernel/drivers/w1/masters
depmod
uninstall:
rm -f /lib/modules/`uname -r`/kernel/drivers/w1/masters/$(obj-m:.o=.ko)
depmod
tags:
@if [ ! -L kernel-source ]; then \
ln -s ${KERN_SRC_DIR} kernel-source; \
fi; \
if [ ! -L kernel-build -a "${KERNEL_SRC}x" = "x" ]; then \
ln -s ${KERN_BLD_DIR} kernel-build; \
fi; \
echo "Generating tags..."; \
ctags -R --c-kinds=+px --c++-kinds=+px .;