Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a Makefile determine the system's lib directory?

While trying to install a program from source I found that it installed libraries to /usr/lib/[program]/ and because this is on a 64-bit system it didn't work. I had to copy the libraries to /usr/lib64/[program]. Note that the library files are python and therefore architecture-independent.

The Makefile has: libdir = /usr/lib

How can I make libdir equal lib64 on 64-bit systems and lib on 32-bit?

like image 649
Dave Forgac Avatar asked Jan 26 '26 12:01

Dave Forgac


2 Answers

Try this:

MACHINE := $(shell uname -m)

ifeq ($(MACHINE), x86_64)
libdir = /usr/lib64
endif
ifeq ($(MACHINE), i686)
libdir = /usr/lib
endif
like image 114
Beta Avatar answered Jan 29 '26 11:01

Beta


This is a fine solution, but if you get into situations where you have more variables to set you might consider using constructed variable names instead. I find them easier to read but YMMV.

libdir.x86_64 = /usr/lib64
libdir.i686   = /usr/lib

MACHINE := $(shell uname -m)

libdir = $(libdir.$(MACHINE))
like image 20
MadScientist Avatar answered Jan 29 '26 10:01

MadScientist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!