Search code examples
stringmakefilecomparison

Makefile issue comparing strings


In my makefile I need to check if a file starts with a bash shebang.

I get that value by doing this

PROJECT_AUTOINSTALL_FIRST_LINE := $$(head -n 1 ./autoinstall_script.sh)

And then I compare it with this value:

BASH_SHEBANG = \#!/bin/bash

Then I check if they're equal by doing

ifneq ($(PROJECT_AUTOINSTALL_FIRST_LINE),$(BASH_SHEBANG))
    @${ERROR_ECHO} "The FIRST line in project autoinstall file MUST be $(BASH_SHEBANG)."
endif

The issue is that condition is always true no matter if file starts with shebang or not. I made a debug echo in order to test equality in a visual way and got this:

enter image description here

They seem to be equal at first sight but code is not telling so. Do you know what am i doing wrong?

Thanks.


Solution

  • What

    PROJECT_AUTOINSTALL_FIRST_LINE := $$(head -n 1 ./autoinstall_script.sh)
    

    does is just assign the literal string $(head -n 1 ./autoinstall_script.sh) to make variable PROJECT_AUTOINSTALL_FIRST_LINE. Not what you want. Try the following, instead:

    PROJECT_AUTOINSTALL_FIRST_LINE := $(shell head -n 1 ./autoinstall_script.sh)