build: make: support windows cross compile
Add WINDOWS_BUILD macro to enable Windows build on *NIX host.
Add optional suffix for executables.
Fix shared object suffix logic to support multiple suffixes.
Fix soname handling to always match output.
WINDOWS macro sets WINDOWS_BUILD.
WINDOWS_BUILD sets .exe executable suffix.
WINDOWS_BUILD shared mode creates dll import library.
WINDOWS_BUILD shared mode link against dll.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
diff --git a/library/Makefile b/library/Makefile
index 37ba14e..9feecb0 100644
--- a/library/Makefile
+++ b/library/Makefile
@@ -22,14 +22,22 @@
CFLAGS += -fPIC
endif
-SONAME=libmbedtls.so.7
+SOEXT=so.8
-DLEXT=so.8
+DLEXT=so
# OSX shared library extension:
# DLEXT=dylib
-# Windows shared library extension:
+#
+# if we running on Windows build
+# for Windows
+#
ifdef WINDOWS
+WINDOWS_BUILD=1
+endif
+
+# Windows shared library extension:
+ifdef WINDOWS_BUILD
DLEXT=dll
LDFLAGS += -lws2_32
endif
@@ -73,7 +81,7 @@
static: libpolarssl.a
-shared: libpolarssl.so
+shared: libpolarssl.$(DLEXT)
libpolarssl.a: libmbedtls.a
echo " LN $@ -> $?"
@@ -89,21 +97,28 @@
echo " RL $@"
$(AR) s $@
-libpolarssl.so: libmbedtls.so
+libpolarssl.$(DLEXT): libmbedtls.$(DLEXT)
echo " LN $@ -> $?"
ifndef WINDOWS
ln -sf $? $@
else
copy /y /b $? $@
endif
+ifdef WINDOWS_BUILD
+ifndef WINDOWS
+ ln -sf $?.a $@.a
+else
+ copy /y /b $?.a $@.a
+endif
+endif
-libmbedtls.${DLEXT}: $(OBJS)
+libmbedtls.$(SOEXT): $(OBJS)
echo " LD $@"
- $(CC) ${LDFLAGS} -shared -Wl,-soname,$(SONAME) -o $@ $(OBJS)
+ $(CC) ${LDFLAGS} -shared -Wl,-soname,$@ -o $@ $(OBJS)
-libmbedtls.so: libmbedtls.${DLEXT}
- echo " LN $@ -> libmbedtls.${DLEXT}"
- ln -sf libmbedtls.${DLEXT} $@
+libmbedtls.so: libmbedtls.$(SOEXT)
+ echo " LN $@ -> libmbedtls.$(SOEXT)"
+ ln -sf libmbedtls.$(SOEXT) $@
libmbedtls.dylib: $(OBJS)
echo " LD $@"
@@ -111,7 +126,7 @@
libmbedtls.dll: $(OBJS)
echo " LD $@"
- $(CC) -shared -Wl,-soname,$@ -o $@ $(OBJS) -lws2_32 -lwinmm -lgdi32
+ $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS) -lws2_32 -lwinmm -lgdi32
.c.o:
echo " CC $<"