Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make makefile host dependent?

Tags:

linux

makefile

I need to compile my program with or without some libraries depending on which of the two hosts it is running. I don't know what to use at the right side of HOST= in my makefile to make this work as I want it to:

   ifeq(${HOST},${ADDITIONAL_LIBS_HOST})
   ADD_LIBS= ...   

${ADDITIONAL_LIBS_HOST} is the name of host as gotten from echo ${HOSTNAME}

like image 248
morynicz Avatar asked Nov 05 '11 00:11

morynicz


1 Answers

A few thoughts:

  • This is the sort of situation GNU autoconf was designed to address. Run ./configure, figure out what libraries are available, and generate an appropriate Makefile.

  • You could get the current hostname by doing something like:

    HOST=$(shell hostname)
    

    You could then use this in your conditional.

  • You could instead have your Makefile do something like:

    include Makefile.local
    

    And then have different Makefile.local files on each host.

Re: your comment, given a Makefile like this:

HOST=$(shell hostname)

all:
    @echo $(HOST)

Will generate the following output:

$ make all
fafnir.local

(Assuming your local host is "fafnir.local". Which mine is.)

like image 68
larsks Avatar answered Sep 30 '22 07:09

larsks