我想设置一个Makefile来搜索和复制一些文件(if-else条件),但我无法确定到底哪里出了问题?(尽管我相当确定是因为空格/制表符的组合写在了错误的地方)
请帮我一下,好吗?
这是我目前拥有的内容:
这是我目前拥有的内容:
obj-m = linuxmon.o
KDIR = /lib/modules/$(shell uname -r)/build
UNAME := $(shell uname -m)
all:
$(info Checking if custom header is needed)
ifeq ($(UNAME), x86_64)
$(info Yes)
F1_EXISTS=$(shell [ -e /usr/include/asm/unistd_32.h ] && echo 1 || echo 0 )
ifeq ($(F1_EXISTS), 1)
$(info Copying custom header)
$(shell sed -e 's/__NR_/__NR32_/g' /usr/include/asm/unistd_32.h > unistd_32.h)
else
F2_EXISTS=$(shell [[ -e /usr/include/asm-i386/unistd.h ]] && echo 1 || echo 0 )
ifeq ($(F2_EXISTS), 1)
$(info Copying custom header)
$(shell sed -e 's/__NR_/__NR32_/g' /usr/include/asm-i386/unistd.h > unistd_32.h)
else
$(error asm/unistd_32.h and asm-386/unistd.h does not exist)
endif
endif
$(info No)
endif
@make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
rm unistd_32.h
无论如何,这将打印出"Yes" , "Copying header"两次,然后会因为sed无法读取/usr/include/asm-i386/unistd.h
而退出程序(当然它无法读取,因为我在一个x64系统上)。
可以说make
只是没有理解if/else,而是按照顺序一行行地运行所有内容。
ifeq
或ifneq
。 - s.ouchene