Results 1 to 3 of 3

Thread: [makefiles] How to edit commands / use conditional statements

  1. #1
    Join Date
    Feb 2007
    Beans
    239
    Distro
    Ubuntu

    [makefiles] How to edit commands / use conditional statements

    I want to run different compiler flags depending on which system I'm on (e.g. school machines or laptop).

    However I can't get it to run correctly.

    Code:
    ifeq (`hostname`,machine.school.edu)
        CC:= -I /lusr/opt/boost1_38/
    else
        CC:= -std=gnu++0x
    endif
    The conditional statement never evaluates true for some reason.

  2. #2
    Join Date
    May 2006
    Beans
    1,787

    Re: [makefiles] How to edit commands / use conditional statements

    Quote Originally Posted by AncientPC View Post
    I want to run different compiler flags depending on which system I'm on (e.g. school machines or laptop).

    However I can't get it to run correctly.

    Code:
    ifeq (`hostname`,machine.school.edu)
        CC:= -I /lusr/opt/boost1_38/
    else
        CC:= -std=gnu++0x
    endif
    The conditional statement never evaluates true for some reason.
    I think the problem is that the backquote construction doesn't belong to 'make', so it will be comparing the strings "`hostname`" and "machine.school.edu", which are not equal. Backquotes work in commands, because then they are passed to the shell. You can do

    Code:
    ifeq ($(shell hostname),machine.school.edu)
        CC:= -I /lusr/opt/boost1_38/
    else
        CC:= -std=gnu++0x
    endif

  3. #3
    Join Date
    Feb 2007
    Beans
    239
    Distro
    Ubuntu

    Re: [makefiles] How to edit commands / use conditional statements

    Quote Originally Posted by Arndt View Post
    I think the problem is that the backquote construction doesn't belong to 'make', so it will be comparing the strings "`hostname`" and "machine.school.edu", which are not equal. Backquotes work in commands, because then they are passed to the shell. You can do

    Code:
    ifeq ($(shell hostname),machine.school.edu)
        CC:= -I /lusr/opt/boost1_38/
    else
        CC:= -std=gnu++0x
    endif
    That works perfectly, thanks!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •