How do you define multiple variables using make's pattern specific variable values feature https://www.gnu.org/software/make/manual/html_node/Pattern_002dspecific.html#Pattern_002dspecific? For example, suppose that LIBDIR and RPATH have already been defined, and I want to set the following:
LDFLAGS += -L$(LIBDIR) $(RPATH)
LDLIBS += -lsomelibrary
for builds that match the pattern utest%. So for example,
utest% : -L$(LIBDIR) $(RPATH)
would get me halfway there, but then how to define the second variable?
I thought that maybe using multi-line variables https://www.gnu.org/software/make/manual/html_node/Multi_002dLine.html would work, but I can't quite get there. I've tried:
define linking_vars :=
LDFLAGS := -L$(LIBDIR) $(RPATH)
LDLIBS := -lsomelibrary
endef
utest% : $(linking_vars)
and also
define newline =
endef
utest_% : LDFLAGS := -L$(LIBDIR) $(RPATH) $(newline) LDLIBS := -lsomelibrary
but I haven't had any luck yet.
I'm not entirely sure I understand what you want to do, but it sounds as if this might do it:
utest% : LDFLAGS += -L$(LIBDIR) $(RPATH)
utest% : LDLIBS += -lsomelibrary
Related
I have two files:
main.c will become module calc, it will use API in expression.c.
livepatch-calc.c will become module livepatch-calc.
I have following makefile and work well
obj-m += calc.o
obj-m += livepatch-calc.o
calc-objs += main.o expression.o
ccflags-y := -std=gnu99 -Wno-declaration-after-statement
Currently, I need call expression's API in livepatch-calc.c. So, I have new makefile like:
obj-m += calc.o
obj-m += livepatch-calc.o
calc-objs += main.o expression.o
livepatch-calc-objs += expression.o
ccflags-y := -std=gnu99 -Wno-declaration-after-statement
Unfortunately, when I make it. Warning message show up:
WARNING: modpost: missing MODULE_LICENSE() in ..../livepatch-calc.o
I wondering are there anything wrong in my makefile?
I'm trying to compile a Fortran program that uses the PLASMA libraries. Compilation fails with undefined reference to `__plasma_MOD_plasma_init'. Inside plasma.h (which i assume plasma.mod is the interface for), plasma_init is defined with one argument whereas it is called with two in the Fortran program. When removing the second argument though, i get Error: Missing actual argument for argument ‘info’ at (1). I haven't been able to make sense of this, so hopefully someone here can.
I'm using PLASMA 2.8.0 and gcc 6.3.0 20170516.
Here's the makefile. I tried including the pkgconfig which contains plasma.pc because i thought the function's implementation was missing.
#LIB_ROOT = path to the lib
INCLUDE_PLASMA := $(LIB_ROOT)/plasma_2.8.0/include
LIB_PLASMA := $(LIB_ROOT)/plasma_2.8.0/lib/pkgconfig
example: example.f90
gfortran -o example example.f90 -I$(INCLUDE_PLASMA) -L$(LIB_PLASMA)
Here's the minimal Fortran code :
program example
use plasma
implicit none
integer :: a = 1
integer :: info = 1
call plasma_init(a, info)
end program
In plasma.h, plasma_init is defined as:
int PLASMA_Init(int cores);
I solved my issue by correctly linking to the required libraries, here's the new makefile:
PLASMA_BUILD = [some directories]/plasma-installer_2.8.0/build
LIB_PLASMA := $(PLASMA_BUILD)/plasma_2.8.0/lib # contains libplasma.a, libcoreblas.a and libcoreblasqw.a
LIB_QUARK := $(PLASMA_BUILD)/plasma_2.8.0/quark # contains libquark.a
LIB_LAPACK := $(PLASMA_BUILD)/lapack-3.6.0 # contains liblapack.a and liblapacke.a
PLASMA_INTERFACE = $(PLASMA_BUILD)/plasma_2.8.0/control # contains plasma.mod
example: example.f90
gfortran -o example example.f90 -lpthread \
-L$(LIB_PLASMA) -lplasma -lcoreblas -lcoreblasqw \
-L$(LIB_QUARK) -lquark \
-L$(LIB_LAPACK) -llapacke -llapack \
-I$(PLASMA_INTERFACE)
I have some trouble with making Makefile. This is a part of Makefile.
dirs := fwd common bp bp_manager $(XRTE_HASH)
VPATH_ = $(foreach dir,$(dirs),$(SRCDIR)/$(dir))
INC_ = $(foreach dir,$(dirs),$(wildcard $(dir)/*.h))
CFLAGS_ = $(foreach dir,$(dirs),-I$(SRCDIR)/$(dir))
SRCS-y_ = $(foreach dir,$(dirs),$(notdir $(wildcard $(dir)/*.c)))
VPATH += $(VPATH_)
INC += $(INC_)
CFLAGS += $(CFLAGS_)
SRCS-y += $(SRCS-y_)
check:
echo $(CFLAGS)
echo $(SRCS-y)
VPATH and INC worked as I intended.
CFLAGS doesn't contain CFLAGS_
SRCS-y was printed as I inteded, but it has no effect when do "make" - SRCS-y_ was same with null.
CFLAGS and SRCS-y is okay when set manually (without function).
I thought Makefile is almost same with csh.
Can you explain me why the "make" ignores functions?
Thanks.
CFLAGS_ is just a string. $(CFLAGS_) is a variable's value. So you should have:
CFLAGS += $(CFLAGS_)
SRCS-y += $(SRCS-y_)
I am a newbie for Makefile. Optimizing my code Makefile code.
I have following code which is messy, Is there any better way of writing this.(for more clarity added space before each line)
ifdef X
ifndef Y
LNFLAGS + = -m32
else
ifndef Z
LNFLAGS + = -m32
endif
endif
endif
I have a makefile that lists the source files: (shortened to relevant)
SRCFOLDER=src/
SOURCES= main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
and I would like to concate the strings together, but for each one in SOURCES. As you can see above, I do it for OBJECTS, but I want to do it like this: (pseudocode)
foreach(src in SOURCES)
src = concate(SRCFOLDER, src)
so that if SOURCES was main.cpp window.cpp, the result would be src/main.cpp src/window.cpp.
I tried this:
SOURCES=$(SOURCES:*=$(SRCFOLDER)/*)
but I get this error:
makefile:12: *** Recursive variable `SOURCES' references itself (eventually). Stop.
SRCFOLDER := src
SOURCES := main.cpp window.cpp
SOURCES := $(addprefix $(SRCFOLDER)/, $(SOURCES))