Search code examples
makefile

Makefile error : recipe commences before first target but not recipe or order


I wrote some variables in makefile:

N_CFLAGS   = -g \
             --strict \
             $(USER_N_FLAG) \ 
             $(USER_INC) \         <-----------ERROR!
             -D$(ALT_DEVICE_FAMILY)    \ 
             -D$(ALT_DEVICE)    \ 
             $(UART_DEFINES)    \ 
             $(ADD_CFLAGS_ARMCC)

The USER_INC is defined below:

USER_INC :=-Ilib \
           -I$(LIBS_DIR)/include \
           -I$(LIBS_DIR)/include/$(DEVICE_FAMILY) \
           -I$(LIBS_DIR)/include/$(DEVICE_FAMILY)/miscs \
           -I$(F_LIB_DIR) \
           -I$(H_LIB_DIR) \
           -I$(C_LIB_DIR)

I used to change all TAB to space. However it give me another error at the same place ***missing seperate,STOP. These lines are not orders or recipes and they are not even used. I dont know why these errors ever happened.

Do you guys have any idea on that?


Solution

  • Make the whitespace more visible, and the error becomes apparent:

    $ cat -TE Makefile
    N_CFLAGS   = -g \$
                 --strict \$
                 $(USER_N_FLAG) \ $
    ^I^I^I $(USER_INC) \         <-----------ERROR!$
                 -D$(ALT_DEVICE_FAMILY)    \ $
                 -D$(ALT_DEVICE)    \ $
                 $(UART_DEFINES)    \ $
                 $(ADD_CFLAGS_ARMCC)$
    

    Notice that space between \ and the newline? That means the backslash is escaping the space - not the newline.

    Because the next line (not part of the continuation) begins with a tab, it's interpreted as a command, but we're not inside a rule, so that's an error.

    If you can do so, configure your editor to highlight whitespace at end-of-line, and to display tabs distinctively.