Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Makefile, detect architecture

I want to autodetect system architecture, when i compile my program under freebsd and i want 2 includes for x64 and x32 but don't work, i tried like this :

ifeq ($(uname -a),i386)
INCDIR += -I../../x32
else
INCDIR += -I../../x64
endif

What is wrong here? When i compile on amd64 work with code below. When i compile on i388 don't work.

When i compile on amd64 with code below the makefile see x64 dir. When i compile on i386 with code below the makefile see x64 dir. Soo bassicaly that else don't have any effect ?

like image 296
Starrrks_2 Avatar asked Apr 14 '16 15:04

Starrrks_2


People also ask

What is $$ in makefile?

Double dollar sign If you want a string to have a dollar sign, you can use $$ . This is how to use a shell variable in bash or sh . Note the differences between Makefile variables and Shell variables in this next example.

What is makefile GNU?

This file documents the GNU make utility, which determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them.

How do I use IFEQ in makefile?

The ifeq directive begins the conditional, and specifies the condition. It contains two arguments, separated by a comma and surrounded by parentheses. Variable substitution is performed on both arguments and then they are compared.

How does GNU Make work?

GNU Make is a program that automates the running of shell commands and helps with repetitive tasks. It is typically used to transform files into some other form, e.g. compiling source code files into programs or libraries. It does this by tracking prerequisites and executing a hierarchy of commands to produce targets.


1 Answers

In GNU make syntax $() dereferences a variable. You rather want a shell command:

uname_p := $(shell uname -p) # store the output of the command in a variable

And then:

ifeq ($(uname_p),i386)

Alternative to multi-level ifeq using computed variable names. Here is a working makefile I used on my system:

uname_s := $(shell uname -s)
$(info uname_s=$(uname_s))
uname_m := $(shell uname -m)
$(info uname_m=$(uname_m))

# system specific variables, add more here    
INCDIR.Linux.x86_64 := -I../../x64
INCDIR.Linux.i386 := -I../../x32

INCDIR += $(INCDIR.$(uname_s).$(uname_m))
$(info INCDIR=$(INCDIR))

Which produces the following output:

$ make 
uname_s=Linux
uname_m=x86_64
INCDIR=-I../../x64
like image 197
Maxim Egorushkin Avatar answered Oct 29 '22 08:10

Maxim Egorushkin