Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build shared library for Windows in Makefile #174

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,31 @@ MINOR=3
PATCH=1

OS := $(shell uname)

# Normalize different Windows versions
ifneq (,$(findstring MINGW,$(OS)))
override OS := WINNT
endif
ifneq (,$(findstring MSYS,$(OS)))
override OS := WINNT
endif

ifeq ($(OS),Darwin) # MacOS X
SHLIB_EXT = dylib
SHLIB_VERS_EXT = $(MAJOR).dylib
SHLIB_VERS_EXT = .$(MAJOR).$(SHLIB_EXT)
else ifeq ($(OS), WINNT)
SHLIB_EXT = dll
SHLIB_VERS_EXT = -$(MAJOR).$(SHLIB_EXT)
else # GNU/Linux, at least (Windows should probably use cmake)
SHLIB_EXT = so
SHLIB_VERS_EXT = so.$(MAJOR).$(MINOR).$(PATCH)
SHLIB_VERS_EXT = .$(SHLIB_EXT).$(MAJOR).$(MINOR).$(PATCH)
endif

# installation directories (for 'make install')
prefix=/usr/local
libdir=$(prefix)/lib
includedir=$(prefix)/include
pkgconfigdir=$(libdir)/pkgconfig
pkgconfigdir=$(prefix)/lib/pkgconfig

pkglibdir=$(libdir:$(prefix)/%=%)
pkgincludedir=$(includedir:$(prefix)/%=%)
Expand All @@ -51,7 +63,7 @@ pkgincludedir=$(includedir:$(prefix)/%=%)
all: libutf8proc.a libutf8proc.$(SHLIB_EXT)

clean:
rm -f utf8proc.o libutf8proc.a libutf8proc.$(SHLIB_VERS_EXT) libutf8proc.$(SHLIB_EXT)
rm -f utf8proc.o libutf8proc.a libutf8proc$(SHLIB_VERS_EXT) libutf8proc.$(SHLIB_EXT)
rm -f libutf8proc.pc
ifneq ($(OS),Darwin)
rm -f libutf8proc.so.$(MAJOR)
Expand Down Expand Up @@ -94,6 +106,13 @@ libutf8proc.$(MAJOR).dylib: utf8proc.o
libutf8proc.dylib: libutf8proc.$(MAJOR).dylib
ln -f -s libutf8proc.$(MAJOR).dylib $@

libutf8proc-$(MAJOR).dll: utf8proc.o
$(CC) $(LDFLAGS) $(LDFLAG_SHARED) -o $@ $(SOFLAG) -Wl,libutf8proc-$(MAJOR).dll utf8proc.o
chmod a-x $@

libutf8proc.dll: libutf8proc-$(MAJOR).dll
ln -f -s libutf8proc-$(MAJOR).dll $@

libutf8proc.pc: libutf8proc.pc.in
sed \
-e 's#PREFIX#$(prefix)#' \
Expand All @@ -102,17 +121,19 @@ libutf8proc.pc: libutf8proc.pc.in
-e 's#VERSION#$(MAJOR).$(MINOR).$(PATCH)#' \
libutf8proc.pc.in > libutf8proc.pc

install: libutf8proc.a libutf8proc.$(SHLIB_EXT) libutf8proc.$(SHLIB_VERS_EXT) libutf8proc.pc
install: libutf8proc.a libutf8proc.$(SHLIB_EXT) libutf8proc$(SHLIB_VERS_EXT) libutf8proc.pc
mkdir -m 755 -p $(DESTDIR)$(includedir)
$(INSTALL) -m 644 utf8proc.h $(DESTDIR)$(includedir)
mkdir -m 755 -p $(DESTDIR)$(libdir)
$(INSTALL) -m 644 libutf8proc.a $(DESTDIR)$(libdir)
$(INSTALL) -m 755 libutf8proc.$(SHLIB_VERS_EXT) $(DESTDIR)$(libdir)
$(INSTALL) -m 755 libutf8proc$(SHLIB_VERS_EXT) $(DESTDIR)$(libdir)
mkdir -m 755 -p $(DESTDIR)$(pkgconfigdir)
$(INSTALL) -m 644 libutf8proc.pc $(DESTDIR)$(pkgconfigdir)/libutf8proc.pc
ln -f -s libutf8proc.$(SHLIB_VERS_EXT) $(DESTDIR)$(libdir)/libutf8proc.$(SHLIB_EXT)
ifneq ($(OS),Darwin)
ln -f -s libutf8proc.$(SHLIB_VERS_EXT) $(DESTDIR)$(libdir)/libutf8proc.so.$(MAJOR)
ln -f -s libutf8proc$(SHLIB_VERS_EXT) $(DESTDIR)$(libdir)/libutf8proc.$(SHLIB_EXT)
ifneq ($(OS), WINNT)
ifneq ($(OS),Darwin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in Make conditionals only work at top level?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should work also inside a rule, if this is what you mean: https://www.gnu.org/software/make/manual/html_node/Conditional-Example.html. Or are you asking about the nested conditionals?

ln -f -s libutf8proc$(SHLIB_VERS_EXT) $(DESTDIR)$(libdir)/libutf8proc.so.$(MAJOR)
endif
endif

MANIFEST.new:
Expand Down