Linux驱动 | 调试宏和多平台兼容的Makefile
程序员文章站
2024-03-23 10:10:28
...
调试宏
将头文件driver.h包含到驱动文件中。
drvier.h
#ifndef __SCULL_H__
#define __SCULL_H__
#ifdef EN_DRIVER_DEBUG
#ifdef __KERNEL__
//处于内核空间
#define PDEBUG(fmt,args...) printk(KERN_DEBUG fmt,##args)
#else
//处于用户空间
#define PDEBUG(fmt,args...) fprintf(stderr,fmt,##args)
#endif
#else
//关闭调试
#define PDEBUG(fmt,args...)
#endif
#endif
多平台兼容的Makefile
Makefile
obj-m += scull.o
PWD=$(shell pwd)
_KERDIR ?= /lib/modules/$(shell uname -r)/build
mips_KERDIR ?= /home/hjf/work/openwrt_widora/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7688/linux-3.18.29
arm_KERDIR ?= /home/hjf/work/itop_4412/iTop4412_kernel_public
mips_TOOLCHAIN ?= /home/hjf/work/openwrt_widora/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-
arm_TOOLCHAIN ?= /home/hjf/work/itop_4412/arm-linux-gcc-4.5.1/bin/arm-linux-
KERDIR ?= $($(ARCH)_KERDIR)
TOOLCHAIN ?= $($(ARCH)_TOOLCHAIN)
DEBUG ?= y
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DEN_DRIVER_DEBUG # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
EXTRA_CFLAGS += $(DEBFLAGS)
ifeq ($(ARCH),)
CROSS ?=
else
CROSS ?= ARCH=$(ARCH) CROSS_COMPILE=$(TOOLCHAIN)
endif
modules:
$(MAKE) -C $(KERDIR) M=$(PWD) $(CROSS) modules
clean:
rm -rf *.ko *.o *.mod.c *.order *.symvers
编译ARM平台:
make ARCH=arm
编译Mips平台:
make ARCH=mips
编译当前平台(一般是x86平台,默认使用gcc编译器)
make
启用调试
make DEBUG=y
上一篇: Java模拟表单post提交 HttpClient
下一篇: Unity 手机拍照以及相关问题