From 966a1e12f608beb40f50816ce1e65fa80876168d Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 12 Jun 2017 15:18:51 +0200 Subject: [PATCH] Makefile: add shared lib --- Makefile/Makefile | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Makefile/Makefile b/Makefile/Makefile index 39f865b..5cbbd04 100644 --- a/Makefile/Makefile +++ b/Makefile/Makefile @@ -12,7 +12,15 @@ LDLIBS = #$(pkg-config --libs sdl) bin = main 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) depends = $(sources:%.c=%.d) @@ -30,11 +38,18 @@ $(cxxbin) : $(cxx_objects) $(cxxbin): $(LINK.cc) $^ $(LDLIBS) -o $@ +$(lib): CFLAGS += -fpic +$(lib): $(lib_obj) + +%.so: + $(LINK.c) -shared $^ $(LDLIBS) -o $@ + .PHONY: 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) -include $(depends) -include $(cxx_depends) +-include $(lib_dep) endif