【问题标题】:Restart udev on Makefile在 Makefile 上重新启动 udev
【发布时间】:2013-10-03 15:34:46
【问题描述】:

我为应用程序制作了一个简单的 Makefile,安装后我需要重新启动 udev 规则。

INSTALLDIR=/pkt/bin
OS:=$(shell uname -v)
LBITS:=$(shell getconf LONG_BIT)
LIBDIR=/usr/lib

ifeq ($(LBITS),64)
    LIBDIR64=/usr/lib64
else
    LIBDIR64=/usr/lib
endif

all: usbupdater

configuracion.o: configuracion.cpp
    g++ -c configuracion.cpp

main.o: main.cpp
    g++ -c main.cpp

usbupdater: main.o configuracion.o
    @echo "$(PATH)"
    @echo "$(LIBDIR)"
    g++ main.o configuracion.o $(LIBDIR)/libReadINI.a $(LIBDIR64)/chilkat/li
bchilkat-9.4.1.a -lpthread -lresolv -o usbupdater 

clean:
    rm -rf *.o *.cgh $(INSTALLDIR)/usbupdater
install:
    mv usbupdater $(INSTALLDIR)/usbupdater
    cp -rf 99-persistent-usb.rules /etc/udev/rules.d/99-persistent-usb.rules

postinstall:
    @echo "$(OS)"
    ifeq ($(findstring Debian,$(OS)),Debian) \
        @echo "Estoy dentro del if"
        $(shell '/etc/init.d/udev' restart) \
    else \
        @echo "Estoy dentro del else"
        $(shell ls -l) \
    endif

问题是当我输入 make postinstall 时会显示这个错误:

#1 SMP Debian 3.2.46-1+deb7u1
ifeq (Debian,Debian) \
        @echo "Estoy dentro del if"
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
make: *** [postinstall] Error 2

我不知道问题出在哪里。我将 uname -v 的结果与 Debian 进行比较,以执行 udev restart 或 udevcontrol reload_rules 如果它是 Opensuse 操作系统。

提前感谢我的英语。

【问题讨论】:

    标签: makefile udev


    【解决方案1】:

    ifeq 是一个 make 命令。 makefile 中的所有行(在配方上下文中)都传递给 shell。所以 make 将 ifeq 传递给 shell,shell 告诉你它不知道你在说什么。

    你应该使用 shell 语法来编写这个,而不是 make 语法。

    此外,在 make 配方中使用 $(shell ...) 函数也很少有用。 make 配方将由 shell 运行,因此当您使用 $(shell ...) 时,您只是将运行的 shell 数量增加了一倍。再加上像$(shell ls -l) 这样的命令是行不通的,因为$(shell ...) 就像反引号,并用命令的标准输出替换了函数。在这种情况下,这将是一个错误。

    我会这样写:

    postinstall:
            @echo "$(OS)"
            @case '$(OS)' in \
            (*Debian*) \
                echo "Estoy dentro del if"; \
                /etc/init.d/udev restart ;; \
            (*) \
                echo "Estoy dentro del else"; \
                ls -l ;; \
            esac
    

    【讨论】:

      【解决方案2】:

      您不能在规则定义块中使用 make 内部命令(如 ifeq)。使用 shell 的 if 或在规则之外使用 ifeq 来生成一些变量值,例如

      ifeq($(blah-blah), blah)
         BUILD_CMD:=foo
      endif
      

      另外值得注意的是,else 语句并不完全是标准的,并且在 make 的某些版本中可能会丢失。

      你为什么想要这个,顺便说一句?如果 make install 除了安装(复制)文件之外还做其他事情,我会认为这是非常糟糕的做法。

      【讨论】:

      • 据我所知,没有不支持 simple else 命令。
      • 我一直认为ifeq是相当标准的,但看来和你说的一样。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2011-11-02
      • 2022-09-28
      相关资源
      最近更新 更多