Makefile question - how to do this?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

 

I have what should be a simple question, but I just can't seem to fine the answer.

In a Makefile, I have the following line:

 

libdir=/usr/lib/x86_64-linux-gnu

 

I also wish to be able to compile the same code on a Raspberry Pi, so when I do I use this line instead:

 

libdir=/usr/lib/arm-linux-gnueabihf

 

However, I need to edit the Makefile by hand to do this.

Is there any way that I can get these strings (highlighted in red) automatically? I do rebuild the Makefile using autoconf.

I looked at uname and it's output isn't usable (even if I hack out pieces and concatenate them).

 

Thanks!

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I believe you can check for the existence of the directories...

 

Edit: adding:

Something like this:  (may be gnu-make dependent?(

TESTDIR := $(firstword $(wildcard ../../../tools/*))
ifeq (,$(TESTDIR))
# no such directory  Try elsewhere...
#  :
endif

 

Additional edit:  An advantage (I think?) of this over the various suggestions used $(shell ...) is that it doesn't depend on having a unix-like "sh" available.

Last Edited: Wed. Dec 30, 2020 - 09:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use the ifeq command with the shell command (running uname -m to get the machine type) to conditionally set libdir:

 

https://www.gnu.org/software/make/manual/html_node/Conditional-Example.html

https://www.gnu.org/software/make/manual/html_node/Shell-Function.html

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I went through an old book on libtool a few months back; programs like avrdude use it and can be compiled on many platforms.

 

https://www.gnu.org/software/libtool/

 

While looking at a different libc, I ran into the Meson build system, and that seems like it might be a better option, but I have not even read a book on it yet.

 

https://mesonbuild.com/

 

Finally, what I have done to find a serial port, you will have to spin it to fit the need.

 

detect_PORT := $(shell sh -c 'ls /dev/ttyAMA0 2>/dev/null || echo not')
ifeq ($(detect_PORT),/dev/ttyAMA0)
	UPDI_PORT = /dev/ttyAMA0
endif
detect_PORT := $(shell sh -c 'ls /dev/ttyUSB0 2>/dev/null || echo not')
ifeq ($(detect_PORT),/dev/ttyUSB0)
	UPDI_PORT = /dev/ttyUSB0
endif

 

UPDI_PORT ends up with /dev/ttyAMA0 on a R-Pi and /dev/ttyUSB0 on my Ubuntu machine that has an FTDI part connected.