Makefile: add shared lib

This commit is contained in:
Mathieu Maret 2017-06-12 15:18:51 +02:00
parent 3fcfdb6720
commit 966a1e12f6

View File

@ -12,7 +12,15 @@ LDLIBS = #$(pkg-config --libs sdl)
bin = main bin = main
cxxbin = cxxmain cxxbin = cxxmain
sources = $(wildcard *.c) lib = libexample.so
#Will be compiled with -fpic
lib_src = lib.c
lib_obj = $(lib_src:%.c=%.o)
lib_dep = $(lib_src:%.c=%.d)
$(info $$lib_obj is ${lib_obj})
sources = $(filter-out $(lib_src), $(wildcard *.c))
objects = $(sources:%.c=%.o) objects = $(sources:%.c=%.o)
depends = $(sources:%.c=%.d) depends = $(sources:%.c=%.d)
@ -30,11 +38,18 @@ $(cxxbin) : $(cxx_objects)
$(cxxbin): $(cxxbin):
$(LINK.cc) $^ $(LDLIBS) -o $@ $(LINK.cc) $^ $(LDLIBS) -o $@
$(lib): CFLAGS += -fpic
$(lib): $(lib_obj)
%.so:
$(LINK.c) -shared $^ $(LDLIBS) -o $@
.PHONY: clean .PHONY: clean
clean: clean:
$(RM) $(bin) $(objects) $(depends) $(cxxbin) $(cxx_objects) $(cxx_depends) $(RM) $(bin) $(objects) $(depends) $(cxxbin) $(cxx_objects) $(cxx_depends) $(lib) $(lib_obj) $(lib_dep)
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
-include $(depends) -include $(depends)
-include $(cxx_depends) -include $(cxx_depends)
-include $(lib_dep)
endif endif