Reputation: 49473
Is it possible to get make
to check for a file before linking?
I have a makefile
system with a top level Makefile
that calls into other subdirectories and issues make
in them.
The goal of my system is:
So right now I have my child Makefile
doing a "if build fails, then parent fail, if link fails, then parent continue" sort of thing by:
#build the source code
$(CC) -o $@ -c $<
#link the executable
-$(CC) $^ -o $@ $(LIB) #the - allows the parent to continue even if this fails
And this works, however this will allow any link error to go through, I only want to allow the parent to continue if the archive $(LIB)
doesn't exist.
To clarify: Given the following directory structure:
C
├── Makefile
└── childdir
├── a.c // This source file uses functions from idontexist.a
└── Makefile
The top level Makefile is:
.PHONEY: all
all:
@echo "Start the build!" # I want to see this always
$(MAKE) --directory=childdir # then if this works, or fails because the
# .a is missing
@echo "Do more stuff!" # then I want to see this
The Makefile at childdir/
is:
LIB=idontexist.a #This doesn't exist and that's fine
EXE=target
SRC=a.c
OBJS=$(patsubst %.c,%.o,$(SRC))
%.o : %.c
$(CC) -o $@ -c $< #If this fails, I want the ENTIRE build to fail, that's
# good, I want that.
.PHONEY: all
all: $(EXE)
$(EXE):$(OBJS)
-$(CC) $^ -o $@ $(LIB) #If this fails, because $(LIB) is missing
# I don't really care, if it's because we can't find
# some symbol AND the file DOES exist, that's a problem
Upvotes: 0
Views: 197
Reputation: 101041
You can use:
LIB = $(wildcard idontexist.a)
which will expand to the filename if it exists, or empty if it doesn't.
Upvotes: 0