Skip to content

Commit

Permalink
feat: build and release lib as a shared object
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed May 9, 2024
1 parent 15d8d7a commit dcee7bc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions sys-utils/libcmt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TOOLCHAIN_PREFIX ?= riscv64-linux-gnu-
TARGET_CC := $(TOOLCHAIN_PREFIX)gcc
TARGET_AR := $(TOOLCHAIN_PREFIX)ar
COMMON_CFLAGS := -Wvla -O2 -g -Wall -pedantic -Wextra -Isrc \
-fno-strict-aliasing -fno-strict-overflow
-fno-strict-aliasing -fno-strict-overflow -fPIC
TARGET_CFLAGS := $(COMMON_CFLAGS) -ftrivial-auto-var-init=zero -Wstrict-aliasing=3
CFLAGS := $(COMMON_CFLAGS)
CC := gcc
Expand Down Expand Up @@ -68,6 +68,7 @@ libcmt_SRC := \
libcmt_OBJDIR := build/lib
libcmt_OBJ := $(patsubst %.c,$(libcmt_OBJDIR)/%.o,$(libcmt_SRC))
libcmt_LIB := $(libcmt_OBJDIR)/libcmt.a
libcmt_SO := $(libcmt_OBJDIR)/libcmt.so

$(libcmt_OBJ): $(libcmt_OBJDIR)/%.o: %.c
@mkdir -p $(@D)
Expand All @@ -76,10 +77,13 @@ $(libcmt_OBJ): $(libcmt_OBJDIR)/%.o: %.c
$(libcmt_LIB): $(libcmt_OBJ)
$(TARGET_AR) rcs $@ $^

libcmt: $(libcmt_LIB)
install: $(libcmt_LIB)
$(libcmt_SO): $(libcmt_OBJ)
$(TARGET_CC) -shared -o $@ $^

libcmt: $(libcmt_LIB) $(libcmt_SO)
install: $(libcmt_LIB) $(libcmt_SO)
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
cp -f $< $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
cp -f $^ $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
cp -f src/*.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig
Expand All @@ -103,6 +107,7 @@ mock_SRC := \
mock_OBJDIR := build/mock
mock_OBJ := $(patsubst %.c,$(mock_OBJDIR)/%.o,$(mock_SRC))
mock_LIB := $(mock_OBJDIR)/libcmt.a
mock_SO := $(mock_OBJDIR)/libcmt.so

$(mock_OBJ): $(mock_OBJDIR)/%.o: %.c
@mkdir -p $(@D)
Expand All @@ -111,11 +116,14 @@ $(mock_OBJ): $(mock_OBJDIR)/%.o: %.c
$(mock_LIB): $(mock_OBJ)
$(AR) rcs $@ $^

mock: $(mock_LIB)
$(mock_SO): $(mock_OBJ)
$(CC) -shared -o $@ $^

mock: $(mock_LIB) $(mock_SO)

install-mock: $(mock_LIB)
install-mock: $(mock_LIB) $(mock_SO)
mkdir -p $(DESTDIR)$(PREFIX)/lib
cp -f $< $(DESTDIR)$(PREFIX)/lib
cp -f $^ $(DESTDIR)$(PREFIX)/lib
mkdir -p $(DESTDIR)$(PREFIX)/include/libcmt/
cp -f src/*.h $(DESTDIR)$(PREFIX)/include/libcmt/
mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig
Expand Down

0 comments on commit dcee7bc

Please sign in to comment.