Reputation: 1755
I'm writing a Makefile that needs to build a few different versions of a shared library against different versions of a header. Here's an example of what I'm trying to do - clearly pretty broken, but I'll edit it so that it makes more sense as some input rolls in.
libsharedlib_ver1.so and libsharedlib_ver2.so are the outputs I'd like to generate; each depend on a bunch of .o files generated from .c, but the .o files will need to have been compiled against different versions of standardheader.h.
.PHONY: clean
all default: libsharedlib_ver1.so libsharedlib_ver2.so
clean: FORCE
rm -f *.o *.so
FORCE:
OBJECTS: *.c
$(CC) -c $(CFLAGS) -I$(INCDIR) -o $@ $<
libsharedlib_ver1.so: clean OBJECTS $(INCDIR)/ver1_headers/standardheader.h
$(CC) $(CFLAGS) -shared -o $@ *.o
libsharedlib_ver2.so: clean lib $(INCDIR)/ver2_headers/standardheader.h
$(CC) $(CFLAGS) -shared -o $@ *.o
What's the right way to do this?
Upvotes: 0
Views: 169
Reputation: 100866
You'll have to compile all your object files twice, which means that either all the object files have to have different names, or you have to put them in subdirectories with different names. I prefer subdirectories. You can do something like this, using target-specific variables:
SOURCES = src1.c src2.c src3.c
all: libsharedlib_ver1.so libsharedlib_ver2.so
libsharedlib_ver1.so: HEADERS = $(INCDIR)/ver1_headers
libsharedlib_ver2.so: HEADERS = $(INCDIR)/ver2_headers
V1OBJS := $(SOURCES:%.c=ver1/%.o)
V2OBJS := $(SOURCES:%.c=ver2/%.o)
libsharedlib_ver1.so: $(V1OBJS)
libsharedlib_ver2.so: $(V2OBJS)
ver1/%.o : %.c
$(CC) $(CFLAGS) -I$(HEADERS) $(CPPFLAGS) -o $@ -c $<
ver2/%.o : %.c
$(CC) $(CFLAGS) -I$(HEADERS) $(CPPFLAGS) -o $@ -c $<
__dummy := $(shell mkdir -p ver1 ver2)
Upvotes: 1
Reputation: 2768
Normally you would use something like GNU autoconf http://www.gnu.org/software/autoconf/ to rebuild your make file for multiple versions of headers, libraries.
Upvotes: 0