Reputation: 5444
I have been provided the following Makefile. I am supposed to compile a somewhat complicated project but the Makefile itself doesn't do it, even though I am trying to modify it to make it work. I am studying the GNU manual but the Makefile I have is written in a very old style and I am not able to fix it. Could someone help me translating it to today standards while maintaining functionality?
The line:
$(EXE): $(OBJS)
bla=;
for file in $(OBJS); do bla="$$bla ` $$file`"; done; \
$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(ADDLIBS) $(LIBS)
Is the one I am mainly interested in.
This is the complete Makefile:
# //////////////// NOMBRE DEL PROYECTO ///////////////////
#
P=project
#
EXE=$(P)
OBJS=main.o model.o param.o head.h
ADDLIBS=-D.
ADDINCFLAGS=-I.
SRCDIR=/root/projects/project
##########
CXX=g++
CXXFLAGS=-O3 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -I$(COININCDIR)
CXXLINKFLAGS=-Wl,--rpath -Wl,/installed/CoinAll/lib
CC=gcc
CFLAGS=-03 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wsequence-point -Wreturn-type -Wcast-qual -Wall
COININCDIR=/installed/CoinAll/include/coin
COINLIBDIR=/installed/CoinAll/lib
LIBS=-L$(COINLIBDIR) -lCbc -lCgl -lOsiClp -lOsi -lClp -lCoinUtils -lm \
`cat $(COINLIBDIR)/cgl_addlibs.txt` \
`cat $(COINLIBDIR)/clp_addlibs.txt` \
`cat $(COINLIBDIR)/coinutils_addlibs.txt`
# LIBS=-L$(COINLIBDIR) -lClp -lCoinUtils \
# -lm `cat $(COINLIBDIR)/coinutils_addlibs.txt`
INCL=-I`$(COININCDIR)`$(ADDINCFLAGS)
all: $(EXE)
.SUFFIXES: .cpp .c .o .obj
$(EXE): $(OBJS)
bla=;
for file in $(OBJS); do bla="$$bla ` $$file`"; done; \
$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(ADDLIBS) $(LIBS)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
.cpp.obj:
$(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then '$<'; else '$(SRCDIR)/$<'; fi`
.c.o:
$(CC) $(CFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
.c.obj:
$(CC) $(CFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then '$<'; else '$(SRCDIR)/$<'; fi`
Upvotes: 2
Views: 132
Reputation: 80931
The first question is are the entries in `$(OBJS) really commands that are intended to be run for their output and then have their output used in the link line?
Because if not then the backticks are incorrect and the entire loop can be dropped and that body replaced with:
$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $(OBJS) $(ADDLIBS) $(LIBS)
Given that the value of $(OBJS)
is main.o model.o param.o head.h
(and ignoring the fact that having a .h
file in a list of objects is bizarre) I think that the above is likely correct.
But, just for completeness, let us assume that it isn't and that those objects do, in fact, wish to be executed for output. In that case the body could be replaced by:
$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $(patsubst %,`%`,$(OBJS)) $(ADDLIBS) $(LIBS)
Two last comments. There is no reason to have the space inside the backticks (assuming they are correct in the first place) and there is likely no reason to pre-declare $bla=
like that.
Upvotes: 1