0

我为应用程序制作了一个简单的 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 操作系统)。

在此先感谢并为我的英语感到抱歉。

4

2 回答 2

0

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

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

还值得注意的是,该else语句并不完全是标准的,在某些版本的make.

Why do you want this, btw? I'd consider really bad practice if make install does something other then just installing (copying) files.

于 2013-10-03T15:43:00.570 回答
0

ifeq is a make command. All lines in the makefile (in a recipe context) are passed to the shell. So make is passing ifeq to the shell and the shell is telling you that it has no idea what you're talking about.

You should write this using shell syntax, not make syntax.

Also it's rarely useful to use $(shell ...) functions inside a make recipe. The make recipe will be run by the shell, so when you use $(shell ...) you're just doubling the amount of shells that are running. Plus a command like $(shell ls -l) is not going to work, because $(shell ...) is like backtick and replaces the function with the stdout of the command. That'll be an error in this situation.

I would write it as:

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
于 2013-10-03T15:44:56.587 回答