Makefile questions - what is "$ +" and where are the .c files / dependencies called here?

I came across this Makefile (found it on an open source project called sendip)

I have two confusion regarding this file -

  • Where are the .c

    files listed as dependencies here? While all types of libraries ipv6.so

    , tcp.so

    generated excellent, but which line is responsible for this?

I think this is the line ..... Right?

%.so: %.c $(LIBS)
                    $(CC) -o $@ $(CFLAGS) $(LIBCFLAGS) $+ $(LIBS)

      

but $(LIBS)

only list some .o files. It $+

does something?

2. I've never heard of $+

. I tried to find it and stumbled on many others, such as $?

, $@

, $<

, etc., but never seen it. I think it behaves like $?

, but in doing so it also requires parameters to be specified .c

.

Makefile:

#configureable stuff 

PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man/man1
LIBDIR ?= $(PREFIX)/lib/sendip

#For most systems, this works
INSTALL ?= install

#For Solaris, you may need
#INSTALL=/usr/ucb/install

CFLAGS= -fPIC -fsigned-char -pipe -Wall -Wpointer-arith -Wwrite-strings \
-Wstrict-prototypes -Wnested-externs -Winline -Werror -g -Wcast-align \
-DSENDIP_LIBS=\"$(LIBDIR)\"

#-Wcast-align causes problems on solaris, but not serious ones

LDFLAGS=        -g -rdynamic -lm -ldl
#LDFLAGS_SOLARIS= -g -lsocket -lnsl -lm
LDFLAGS_SOLARIS= -g -lsocket -lnsl -lm -ldl
LDFLAGS_LINUX= -g  -rdynamic -lm -ldl
LIBCFLAGS= -shared
CC=     gcc-4.4

PROGS= sendip
BASEPROTOS= ipv4.so ipv6.so
IPPROTOS= tcp.so udp.so icmp.so
UDPPROTOS= rip.so ripng.so ntp.so
TCPPROTOS= bgp.so
PROTOS= $(BASEPROTOS) $(IPPROTOS) $(UDPPROTOS) $(TCPPROTOS)
LIBS= libsendipaux.a
LIBOBJS= csum.o compact.o protoname.o headers.o parseargs.o 
         cryptomod.o crc32.o
SUBDIRS= mec

all:    $(LIBS) subdirs sendip $(PROTOS) sendip.1 sendip.spec

#there has to be a nice way to do this

sendip: sendip.o        gnugetopt.o gnugetopt1.o compact.o
    sh -c "if [ `uname` = Linux ] ; then \
$(CC) -o $@ $(LDFLAGS_LINUX) $(CFLAGS) $+ ; \
elif [ `uname` = SunOS ] ; then \
   $(CC) -o $@ $(LDFLAGS_SOLARIS) $(CFLAGS) $+ ;\
else \
$(CC) -o $@ $(LDFLAGS) $(CFLAGS) $+ ; \
fi"

libsendipaux.a: $(LIBOBJS)
    ar vr $@ $?

subdirs:
    for subdir in $(SUBDIRS) ; do \
            cd $$subdir ;\
            make  ;\
            cd ..  ;\
            done

protoname.o:    mec/protoname.c
    $(CC) -o $@ -c -I. $(CFLAGS) $+

headers.o:      mec/headers.c
    $(CC) -o $@ -c -I. $(CFLAGS) $+

parseargs.o:    mec/parseargs.c
    $(CC) -o $@ -c -I. $(CFLAGS) $+

cryptomod.o:    mec/cryptomod.c
    $(CC) -o $@ -c -I. $(CFLAGS) $+

crc32.o: mec/crc32table.h mec/crc32.c
    $(CC) -o $@ -c -I. $(CFLAGS) mec/crc32.c

mec/crc32table.h: mec/gen_crc32table
    mec/gen_crc32table > mec/crc32table.h

sendip.1:       ./help2man $(PROGS) $(PROTOS) subdirs VERSION
                    ./help2man -n "Send arbitrary IP packets" -N >sendip.1

      

+3


source to share


3 answers


Yes you are right.

When a target definition starts with a symbol %

, it defines a target pattern, not a specific pattern. Thus, %.so

means a target for creating all .so files needed for other purposes or required by the user. %.c

is also a pattern and means all .c

files.



So $(CC) -o $@ $(CFLAGS) $(LIBCFLAGS) $+ $(LIBS)

means that the command output will have the name of the generated target ($ @ -> name of the object that matches the pattern) ... and $+

means all files that match the pattern prerequisite

(i.e.:) %.c

.

Take a look at the GNU manual, in particular, on the catalog of rules to know that $+

, $^

...

+4


source


Some of them are extensions to GNU Make (aka "gmake"):



GNU make does its job in two different phases. In the first step, it reads all makefiles, includes makefiles, etc. and assimilates all the variables and their values, implicit and explicit rules and creates a dependency graph of all goals and their prerequisites. In a second step, make uses these internal structures to determine which targets need to be rebuilt and invokes the rules needed to do so.

... We say that decomposition occurs immediately if it occurs during the first phase: in this case, make will expand any variables or functions in that section of the construct as the makefile is parsed. We say that the expansion is deferred if the expansion is not performed immediately. Expansion of the deferred construct is not performed until the construct appears later in the immediate context or until the second phase.

+1


source


make [1]: *** [Makefile: 490: network layer /icmpv6/IPv6NDMessage_m.h] Error 1 Please, someone can suggest how to fix this error.

0


source







All Articles