相关疑难解决方法(0)

操作系统检测makefile

我经常在几台不同的计算机和几种不同的操作系统上工作,这些操作系统是Mac OS X,Linux或Solaris.对于我正在进行的项目,我从远程git存储库中提取代码.

无论我在哪个终端,我都希望能够处理我的项目.到目前为止,我已经找到了通过每次切换计算机时更改makefile来绕过操作系统更改的方法.然而,这是乏味的,并引起一堆头痛.

如何修改我的makefile,以便它检测我正在使用哪个操作系统并相应地修改语法?

这是makefile:

cc = gcc -g
CC = g++ -g
yacc=$(YACC)
lex=$(FLEX)

all: assembler

assembler: y.tab.o lex.yy.o
        $(CC) -o assembler y.tab.o lex.yy.o -ll -l y

assembler.o: assembler.c
        $(cc) -o assembler.o assembler.c

y.tab.o: assem.y
        $(yacc) -d assem.y
        $(CC) -c y.tab.c

lex.yy.o: assem.l
        $(lex) assem.l
        $(cc) -c lex.yy.c

clean:
        rm -f lex.yy.c y.tab.c y.tab.h assembler *.o *.tmp *.debug *.acts
Run Code Online (Sandbox Code Playgroud)

makefile os-agnostic os-detection

237
推荐指数
10
解决办法
15万
查看次数

如果条件在Makefile中,则在目标内

我正在尝试设置一个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 > …
Run Code Online (Sandbox Code Playgroud)

if-statement makefile target

41
推荐指数
2
解决办法
14万
查看次数