Nieuws:

Welkom, Gast. Alsjeblieft inloggen of registreren.
Heb je de activerings-mail niet ontvangen?

Auteur Topic: makefile : invalid syntax in conditional  (gelezen 1424 keer)

makefile : invalid syntax in conditional
« Gepost op: 2023/07/04, 18:16:18 »
Ik probeer een makefile te maken als volgt:
PROGRAMS =  blink
all: $(PROGRAMS)
    $(PROGRAMS): % : %.o
        ld -o $@ $<
clean:
        rm -f *.o

Dit werkt goed.    :)
De filenaam "blink" staat boven in het programma.
Om de make file uit te voeren geef ik in
make

Maar nu wil ik de filenaam via de command line invoeren.
make blink

PROGRAMS =

ifneq ($(MAKECMDGOALS), clean)     <------------invalid syntax in condition   
 ifneq PROGRAMS = $(MAKECMDGOALS)
  PROGRAMS = $(MAKECMDGOALS)
 endif
endif

all: $(PROGRAMS)
    $(PROGRAMS): % : %.o
        ld -o $@ $<

clean:
        rm -f *.o


Foutmelding: makefile:4: *** invalid syntax in conditional.  Stop.     :|

(p.s. dit voorbeeld komt uit: Raspberry Pi Assembly Language Raspbian Beginners. bladzijde 87)
𝕸𝖎𝖘𝖈𝖊𝖗𝖊 𝖚𝖙𝖎𝖑𝖊 𝖉𝖚𝖑𝖈𝖎. (Ter leering ende vermaeck)
𝕹𝖎𝖑 𝖛𝖔𝖑𝖊𝖓𝖙𝖎𝖇𝖚𝖘 𝖆𝖗𝖉𝖚𝖚𝖒. (Niets is moeilijk voor hen die willen)
https://henk.oegema.com  (Op RaspberryPi2)
Registered linux user 520520.  In gebruik: Ubuntu  24.04 Hobby's: Radio Amateur callsign: PA2HO.  Interesses: Raspberry Pi & Arduino & TELLO drone (voor AI)

Re: makefile : invalid syntax in conditional
« Reactie #1 Gepost op: 2023/07/11, 18:01:41 »
Eindelijk werkt het:    :)

PROGRAMS =

ifneq ($(MAKECMDGOALS, )
ifneq PROGRAMS = $(MAKECMDGOALS, clean )
PROGRAMS = $(MAKECMDGOALS )
endif
endif

all: $(PROGRAMS)
$(PROGRAMS): % : %.o
        ld -o $@ $<

clean:
        rm -f *.o 
𝕸𝖎𝖘𝖈𝖊𝖗𝖊 𝖚𝖙𝖎𝖑𝖊 𝖉𝖚𝖑𝖈𝖎. (Ter leering ende vermaeck)
𝕹𝖎𝖑 𝖛𝖔𝖑𝖊𝖓𝖙𝖎𝖇𝖚𝖘 𝖆𝖗𝖉𝖚𝖚𝖒. (Niets is moeilijk voor hen die willen)
https://henk.oegema.com  (Op RaspberryPi2)
Registered linux user 520520.  In gebruik: Ubuntu  24.04 Hobby's: Radio Amateur callsign: PA2HO.  Interesses: Raspberry Pi & Arduino & TELLO drone (voor AI)