summaryrefslogtreecommitdiff
path: root/driver/Makefile.am
blob: 730fdde97253f58a71dfec3d17f949a7c584044b (plain)
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
if MEMCHECKER
memchecker = -DMEMORY_CHECKER
endif

if DEBUG
debug_opt = -D__DEBUG
endif

if SPARSE
sparse_output = C=2
endif

if ANDROID
android_opt = -D__ANDROID
android = yes
else
dev_path = @TARGET_DEVICE_PATH@
endif

if SLP_APP
slp_opt = -DSLP_APP
endif

if ANDROID_APP
android_app_opt = -DANDROID_APP
endif

board_opt = -DBOARD_@BOARD@

target_kernel_src = @KERNEL@
target_arch = @ARCH@
driver_module_dir = $(realpath $(srcdir))
module_name = swap_driver
cross_compiler = $(subst gcc,,$(CC))

inlude_opt = -I$(realpath $(top_srcdir)/src/modules/ksyms) -I$(realpath $(top_srcdir)/src/common) \
             -I$(realpath $(top_srcdir)/src/profile) -I$(realpath $(top_srcdir)/src/modules/kprobe) \
             -I$(realpath $(top_srcdir)/src/modules/uprobe)
extra_cflags = "$(inlude_opt) -DEC_ARCH_$(ARCH) -D__DEBUG $(memchecker) $(debug_opt) $(android_opt) $(slp_opt) $(android_app_opt) $(board_opt)"

#bin_SCRIPTS = patchko.sh insmod.sh

all-local:
	cp $(top_srcdir)/src/modules/kprobe/Module.symvers $(driver_module_dir)
	$(MAKE) CROSS_COMPILE=$(cross_compiler) ARCH=$(target_arch) extra_cflags=$(extra_cflags) $(AM_MAKEFLAGS) -C $(target_kernel_src) $(sparse_output) M=$(driver_module_dir) modules

	echo "generate data for version patching <$(OBJDUMP)><$(READELF)>"
	$(top_srcdir)/src/modules/driver/patchko.sh -g $(driver_module_dir)/$(module_name).ko $(OBJDUMP) $(READELF)

clean-local:
	$(MAKE) CROSS_COMPILE=$(cross_compiler) ARCH=$(target_arch) $(AM_MAKEFLAGS) -C $(target_kernel_src) M=$(driver_module_dir) clean

install-exec-local:

	install -m 644 $(driver_module_dir)/$(module_name).ko $(prefix)
	install -m 644 $(driver_module_dir)/$(module_name).ko.addr $(prefix)
	install -m 755 $(driver_module_dir)/patchko.sh $(prefix)/bin
	install -m 755 $(driver_module_dir)/insmod.sh $(prefix)/bin

	if [ "$(android)" != "yes" ] ; then \
	sed "s|__DEV_NAME__|`basename $(dev_path)`|" $(driver_module_dir)/$(module_name).sh | \
	sed "s|__DEV_DIR__|`dirname $(dev_path)`|" > \
	$(prefix)/$(module_name).sh ; chmod +x $(prefix)/$(module_name).sh ; \
	chmod +x $(driver_module_dir)/patchko.sh ; \
	chmod +x $(driver_module_dir)/insmod.sh ; \
	fi