Skip to content

Commit

Permalink
Merge pull request #33 from marcvs/add-shared-lib
Browse files Browse the repository at this point in the history
Build a shared lib
  • Loading branch information
Isty001 authored Dec 11, 2020
2 parents 8d94bb3 + dd0b435 commit 044971e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ SRCS = src/list.c \

OBJS = $(SRCS:.c=.o)

all: build/liblist.a
MAJOR_VERSION = 0
MINOR_VERSION = 1
PATCH_VERSION = 0

all: build/liblist.a build/liblist.so.$(MAJOR_VERSION)

install: all
test -d $(PREFIX)/lib || mkdir -p $(PREFIX)/lib
cp -f build/liblist.a $(PREFIX)/lib/liblist.a
cp -f build/liblist.so.$(MAJOR_VERSION) $(PREFIX)/lib/liblist.so.$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
ln -s liblist.so.$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION) $(PREFIX)/lib/liblist.so.$(MAJOR_VERSION)
ln -s liblist.so.$(MAJOR_VERSION) $(PREFIX)/lib/liblist.so
test -d $(PREFIX)/include || mkdir -p $(PREFIX)/include/
cp -f src/list.h $(PREFIX)/include/list.h

uninstall:
Expand All @@ -25,6 +34,11 @@ build/liblist.a: $(OBJS)
@mkdir -p build
$(AR) rcs $@ $^

build/liblist.so.$(MAJOR_VERSION): $(OBJS)
@mkdir -p build
ld -z now -shared -lc -soname `basename $@` src/*.o -o $@
strip --strip-unneeded --remove-section=.comment --remove-section=.note $@

bin/test: test.o $(OBJS)
@mkdir -p bin
$(CC) $^ -o $@
Expand Down

0 comments on commit 044971e

Please sign in to comment.