From 0e5893a7f7c71735536e216a3d68ebb6ca8c4971 Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Tue, 22 Nov 2022 10:20:48 +0300 Subject: [PATCH 1/2] Enable build of dynamic linked library --- Makefile | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 1dc1768..203dd74 100644 --- a/Makefile +++ b/Makefile @@ -14,29 +14,40 @@ # limitations under the License. #******************************************************************************* ARCH?=$(shell uname -m) -TARGET=lib/libxbyak_aarch64.a -all: $(TARGET) +LIBNAME=libxbyak_aarch64 +STATICTARGET=lib/$(LIBNAME).a +DYNAMICTARGET=lib/$(LIBNAME).so +# Use release version as soname +SONAME=1.0.0 +DYNAMICTARGETSOM=DYNAMICTARGET.$(SONAME) +all: $(STATICTARGET) $(DYNAMICTARGET) -CFLAGS=-std=c++11 -DNDEBUG -g -I ./xbyak_aarch64 -Wall -Wextra -fPIC +CXXFLAGS=-std=c++11 -DNDEBUG -g -I ./xbyak_aarch64 -Wall -Wextra -fPIC ifneq ($(DEBUG),1) -CFLAGS+=-O2 +CXXFLAGS+=-O2 endif LIB_OBJ=obj/xbyak_aarch64_impl.o obj/util_impl.o obj/%.o: src/%.cpp - $(CXX) $(CFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d) + $(CXX) $(CXXFLAGS) -c $< -o $@ -MMD -MP -MF $(@:.o=.d) -include obj/xbyak_aarch64_impl.d -$(TARGET): $(LIB_OBJ) +$(DYNAMICTARGET): $(DYNAMICTARGETSOM) + ln -s $(DYNAMICTARGETSOM) $(DYNAMICTARGET) + +$(DYNAMICTARGETSOM): $(LIB_OBJ) + $(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(LIBNAME).so.$(SONAME) -o $(DYNAMICTARGETSOM) + +$(STATICTARGET): $(LIB_OBJ) ar r $@ $^ -test: $(TARGET) +test: $(STATICTARGET) $(MAKE) -C test clean: - rm -rf obj/*.o obj/*.d $(TARGET) + rm -rf obj/*.o obj/*.d $(STATICTARGET) $(DYNAMICTARGET) $(DYNAMICTARGETSOM) MKDIR=mkdir -p PREFIX?=/usr/local @@ -45,10 +56,12 @@ includedir?=$(prefix)/include libdir?=$(prefix)/lib INSTALL?=install INSTALL_DATA?=$(INSTALL) -m 644 -install: $(TARGET) +install: $(STATICTARGET) $(DYNAMICTARGETSOM) $(DYNAMICTARGET) $(MKDIR) $(DESTDIR)$(includedir)/xbyak_aarch64 $(DESTDIR)$(libdir) $(INSTALL_DATA) xbyak_aarch64/*.h $(DESTDIR)$(includedir)/xbyak_aarch64 - $(INSTALL_DATA) $(TARGET) $(DESTDIR)$(libdir) + $(INSTALL_DATA) $(STATICTARGET) $(DESTDIR)$(libdir) + $(INSTALL_DATA) $(DYNAMICTARGETSOM) $(DESTDIR)$(libdir) + $(INSTALL_DATA) $(DYNAMICTARGET) $(DESTDIR)$(libdir) .PHONY: clean test From 6f1edee61072c7695cce8b2b3f45088a3eb0f96e Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Fri, 25 Nov 2022 20:43:21 +0300 Subject: [PATCH 2/2] Enable creation of static and dynamic libraries --- Makefile | 58 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 203dd74..b6e84de 100644 --- a/Makefile +++ b/Makefile @@ -14,13 +14,17 @@ # limitations under the License. #******************************************************************************* ARCH?=$(shell uname -m) -LIBNAME=libxbyak_aarch64 -STATICTARGET=lib/$(LIBNAME).a -DYNAMICTARGET=lib/$(LIBNAME).so -# Use release version as soname -SONAME=1.0.0 -DYNAMICTARGETSOM=DYNAMICTARGET.$(SONAME) -all: $(STATICTARGET) $(DYNAMICTARGET) +NAME=libxbyak_aarch64 +SONAME_MAJOR=1 +SONAME_MID=0 +SONAME_MINOR=0 +STATIC_TARGET=lib/$(NAME).a +DYNAMIC_TARGET=lib/$(NAME).so +SONAME_TARGET=$(DYNAMIC_TARGET).so.$(SONAME_MAJOR) +LINK_TARGET=$(SONAME_TARGET).$(SONAME_MID).$(SONAME_MINOR) +all: $(STATIC_TARGET) $(DYNAMIC_TARGET) +static: $(STATIC_TARGET) +dynamic: $(DYNAMIC_TARGET) CXXFLAGS=-std=c++11 -DNDEBUG -g -I ./xbyak_aarch64 -Wall -Wextra -fPIC ifneq ($(DEBUG),1) @@ -34,20 +38,23 @@ obj/%.o: src/%.cpp -include obj/xbyak_aarch64_impl.d -$(DYNAMICTARGET): $(DYNAMICTARGETSOM) - ln -s $(DYNAMICTARGETSOM) $(DYNAMICTARGET) - -$(DYNAMICTARGETSOM): $(LIB_OBJ) - $(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(LIBNAME).so.$(SONAME) -o $(DYNAMICTARGETSOM) +$(LINK_TARGET): $(LIB_OBJ) + $(CXX) $(CXXFLAGS) -shared -Wl,-soname,$(NAME).so.$(SONAME_MAJOR) -o $@ $^ -$(STATICTARGET): $(LIB_OBJ) +$(SONAME_TARGET): + ln -sf $(LINK_TARGET) $@ + +$(DYNAMIC_TARGET): + ln -sf $(SONAME_TARGET) $@ + +$(STATIC_TARGET): $(LIB_OBJ) ar r $@ $^ -test: $(STATICTARGET) +test: $(STATIC_TARGET) $(MAKE) -C test clean: - rm -rf obj/*.o obj/*.d $(STATICTARGET) $(DYNAMICTARGET) $(DYNAMICTARGETSOM) + rm -rf obj/*.o obj/*.d $(STATIC_TARGET) $(DYNAMIC_TARGET) MKDIR=mkdir -p PREFIX?=/usr/local @@ -55,13 +62,22 @@ prefix?=$(PREFIX) includedir?=$(prefix)/include libdir?=$(prefix)/lib INSTALL?=install -INSTALL_DATA?=$(INSTALL) -m 644 -install: $(STATICTARGET) $(DYNAMICTARGETSOM) $(DYNAMICTARGET) - $(MKDIR) $(DESTDIR)$(includedir)/xbyak_aarch64 $(DESTDIR)$(libdir) +INSTALL_DATA?=$(INSTALL) -m 755 +install: $(install_static) $(install_dynamic) + +install_setup: + $(MKDIR) $(DESTDIR)$(includedir)/$(NAME) $(DESTDIR)$(libdir) $(INSTALL_DATA) xbyak_aarch64/*.h $(DESTDIR)$(includedir)/xbyak_aarch64 - $(INSTALL_DATA) $(STATICTARGET) $(DESTDIR)$(libdir) - $(INSTALL_DATA) $(DYNAMICTARGETSOM) $(DESTDIR)$(libdir) - $(INSTALL_DATA) $(DYNAMICTARGET) $(DESTDIR)$(libdir) + +install_static: $(STATIC_TARGET) + $(install_setup) + $(INSTALL_DATA) $(STATIC_TARGET) $(DESTDIR)$(libdir) + +install_dynamic: $(DYNAMIC_TARGET) + $(install_setup) + $(INSTALL_DATA) $(LINK_TARGET) $(DESTDIR)$(libdir) + $(INSTALL_DATA) $(SONAME_TARGET) $(DESTDIR)$(libdir) + $(INSTALL_DATA) $(DYNAMIC_TARGET) $(DESTDIR)$(libdir) .PHONY: clean test