Search code examples
makefilegnu-make

Can't assign variable inside recipe


How do I make this work? It errors out with "make: somevariable: Command not found"

sometarget:
    somevariable = somevalue

Full example:

CXXFLAGS = -I/usr/include/test -shared -fPIC

OBJ = main.o Server.o

blabla : $(OBJ) 
ifeq ($(argsexec),true) 
    # Creates an executable
    CXXFLAGS = -I/usr/include/test
    $(CXX) -o blabla $(OBJ) $(CXXFLAGS) 
else 
    # Creates a library
    DESTDIR = /home/pc
    $(CXX) -o blabla $(OBJ) $(CXXFLAGS) 
    ./bn.sh
endif

Solution

  • I found a solution using the eval function:

    $(eval variablename=whatever)
    

    This works :)

    (although I may now try to find an easier build system ;))

    Thanks everyone for reading and also of course @eriktous for writing!