From 32f04d71328dc3c68392176ec22a85bb9862dbb6 Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 4 Jun 2021 17:59:09 +0100 Subject: [PATCH] now compiles to static and shared library --- .gitignore | 2 ++ Makefile | 46 +++++++++++++++++++++++++++++++------------ src/{ => test}/main.c | 0 3 files changed, 35 insertions(+), 13 deletions(-) rename src/{ => test}/main.c (100%) diff --git a/.gitignore b/.gitignore index aa7b7a7..773f4ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ cow-* +*.a +*.so obj/ diff --git a/Makefile b/Makefile index 2a56b78..1010266 100644 --- a/Makefile +++ b/Makefile @@ -41,10 +41,16 @@ OBJ = $(OBJ_C) $(OBJ_CXX) # Phonies .PHONY: release -release: | dirs $(PROJECT)-release +release: | dirs $(PROJECT)-release.a + -$(MAKE) clean-rebuild + -$(MAKE) dirs + $(MAKE) $(PROJECT)-release.so .PHONY: debug -debug: | dirs $(PROJECT)-debug +debug: | dirs $(PROJECT)-debug.a + -$(MAKE) clean-rebuild + -$(MAKE) dirs + $(MAKE) $(PROJECT)-debug.so # Targets @@ -57,22 +63,36 @@ obj/c/%.o: %.c obj/cxx/%.o: %.cpp $(CXX) -c $< $(CXXFLAGS) -o $@ $(LDFLAGS) -$(PROJECT)-release: CFLAGS+= $(RELEASE_CFLAGS) -$(PROJECT)-release: CXXFLAGS += $(RELEASE_CXXFLAGS) -$(PROJECT)-release: LDFLAGS += $(RELEASE_LDFLAGS) -$(PROJECT)-release: $(OBJ) - $(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS) +$(PROJECT)-release.a: CFLAGS+= $(RELEASE_CFLAGS) +$(PROJECT)-release.a: CXXFLAGS += $(RELEASE_CXXFLAGS) +$(PROJECT)-release.a: LDFLAGS += $(RELEASE_LDFLAGS) +$(PROJECT)-release.a: $(OBJ) + ar rcs $@ $^ + ln -sf $@ $(PROJECT).a + +$(PROJECT)-debug.a: CFLAGS+= $(DEBUG_CFLAGS) +$(PROJECT)-debug.a: CXXFLAGS += $(DEBUG_CXXFLAGS) +$(PROJECT)-debug.a: LDFLAGS += $(DEBUG_LDFLAGS) +$(PROJECT)-debug.a: $(OBJ) + ar rcs $@ $^ + +$(PROJECT)-release.so: CFLAGS+= $(RELEASE_CFLAGS) -fPIC +$(PROJECT)-release.so: CXXFLAGS += $(RELEASE_CXXFLAGS) -fPIC +$(PROJECT)-release.so: LDFLAGS += $(RELEASE_LDFLAGS) +$(PROJECT)-release.so: $(OBJ) + $(CXX) -shared $^ -o $@ $(STRIP) $@ + ln -sf $@ $(PROJECT).so -$(PROJECT)-debug: CFLAGS+= $(DEBUG_CFLAGS) -$(PROJECT)-debug: CXXFLAGS += $(DEBUG_CXXFLAGS) -$(PROJECT)-debug: LDFLAGS += $(DEBUG_LDFLAGS) -$(PROJECT)-debug: $(OBJ) - $(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS) +$(PROJECT)-debug.so: CFLAGS+= $(DEBUG_CFLAGS) -fPIC +$(PROJECT)-debug.so: CXXFLAGS += $(DEBUG_CXXFLAGS) -fPIC +$(PROJECT)-debug.so: LDFLAGS += $(DEBUG_LDFLAGS) +$(PROJECT)-debug.so: $(OBJ) + $(CXX) -shared $^ -o $@ clean-rebuild: rm -rf obj clean: clean-rebuild - rm -f $(PROJECT)-{release,debug,pgo} + rm -f $(PROJECT){,-{release,debug,pgo}}.{a,so} diff --git a/src/main.c b/src/test/main.c similarity index 100% rename from src/main.c rename to src/test/main.c