Question

I've made a simple Makefile for an application and after install I need to restart udev rules.

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

The problem is that when I type make postinstall is shows me this error:

#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

I don't know where the problem is. I compare the result of uname -v with Debian to perform udev restart or udevcontrol reload_rules if it is an Opensuse OS.

Thanks in advance and sorry for my English.

Was it helpful?

Solution

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

OTHER TIPS

You can't use make internal commands (like ifeq) within rule definition block. Use either shell's if or use ifeq outside of rule to generate some variables values, like

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

Also worth noting that else statement isn't exactly standard and may be missing in some versions of make.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top