[Swan] confused by Makefile

D. Hugh Redelmeier hugh at mimosa.com
Wed Oct 2 23:54:45 EEST 2013


I'm looking at lib/libswan/Makefile.

Tuomo updated the method that headerfile dependencies are figured out.  
That's a good thing.

I'm trying to understand the rule for building Makefile.depend.

Here's a version that I've hacked on.

Makefile.depend: $(SRCS) $(LOGSRCS) ${LIBRESWANSRCDIR}/lib/libswan/Makefile
        pwd
        echo $(addprefix ${LIBRESWANSRCDIR}/lib/libswan/,$(SRCS))
        echo $(wildcard $(addprefix ${LIBRESWANSRCDIR}/lib/libswan/,$(SRCS)))
        echo
        echo $(addprefix ${KLIPSSRCDIR}/,$(SRCS))
        echo $(wildcard $(addprefix ${KLIPSSRCDIR}/,$(SRCS)))
        echo
        echo $(addprefix ${LIBRESWANSRCDIR}/lib/libswan/,$(LOGSRCS))
        echo $(wildcard $(addprefix ${LIBRESWANSRCDIR}/lib/libswan/,$(LOGSRCS)))
        echo
        (ls $(wildcard $(addprefix ${LIBRESWANSRCDIR}/lib/libswan/,$(SRCS))) \
            $(wildcard $(addprefix ${KLIPSSRCDIR}/,$(SRCS))) \
            $(wildcard $(addprefix ${LIBRESWANSRCDIR}/lib/libswan/,$(LOGSRCS))) \
        | grep '\.c' | xargs ${CC} -MM ${CFLAGS} ${PORTINCLUDE} ${ALLFLAGS}) >Makefile.depend

The pwd and the echos are added by me to understand what's happening.

It turns out the the wildcard function is simply used to filter out
filenames that don't actually correspond to files.

The reason that this is needed is that $(SRCS) lists files that might
exist in one of two directories, ${LIBRESWANSRCDIR}/lib/libswan/ or 
${KLIPSSRCDIR}/; the recipe builds both paths and uses $(wildcard ...) to 
prune the ones that don't exist.

To me, it would be much cleaner to have two lists: one for files in
each directory.  Or to have the directory explicitly in the filename.

I don't really understand how make works these days.  The rule uses 
$(SRCS) as dependencies, does make look in all the right places, or is 
this wrong?  (See the first line quoted above.)


More information about the Swan mailing list