Stefan Schuermans commited on 2017-09-23 20:43:55
Showing 9 changed files, with 100 additions and 38 deletions.
... | ... |
@@ -5,45 +5,60 @@ |
5 | 5 |
|
6 | 6 |
CC:=gcc |
7 | 7 |
CFLAGS:=-Wall -Wextra -Werror -fPIC -O2 -I.. |
8 |
-LIB_LFLAGS:= |
|
9 |
-BIN_LFLAGS:=-L. -Wl,-rpath,'$$ORIGIN' |
|
8 |
+LIB_LDFLAGS:= |
|
9 |
+LIB_LDLIBS:= |
|
10 |
+BIN_LDFLAGS:=-L. |
|
11 |
+BIN_LDLIBS:= |
|
10 | 12 |
AR:=ar |
11 | 13 |
RANLIB:=ranlib |
12 | 14 |
|
13 |
-ifneq ($(MAKECMDGOALS),clean) |
|
14 |
-include ../version.mk |
|
15 |
-include ../config/config.mk |
|
15 |
+-include ../version.mk |
|
16 |
+-include ../config/config.mk |
|
17 |
+ |
|
18 |
+LIB_OBJS:=BlinkenColorizer.o BlinkenFrame.o BlinkenMovie.o \ |
|
19 |
+ BlinkenProto.o Tools.o |
|
20 |
+ |
|
21 |
+ifeq ($(BLINKENLIB_CFG_MNG),1) |
|
22 |
+LIB_OBJS+=BlinkenMng.o |
|
23 |
+LIB_LDLIBS+=-lmng -lz |
|
16 | 24 |
endif |
17 | 25 |
|
26 |
+ifeq ($(BLINKENLIB_CFG_GIF),1) |
|
27 |
+LIB_OBJS+=BlinkenGif.o |
|
28 |
+LIB_LDLIBS+=-lgif |
|
29 |
+endif |
|
30 |
+ |
|
31 |
+ifeq ($(BLINKENLIB_CFG_WIN),1) |
|
32 |
+LIB_LDLIBS+=-lws2_32 |
|
33 |
+BIN_LDLIBS+=-lws2_32 |
|
34 |
+SHLIBEXT:=dll |
|
35 |
+else |
|
18 | 36 |
ifeq ($(BLINKENLIB_CFG_OSX),1) |
19 |
-SHLIBEXT:=dylib |
|
20 | 37 |
CFLAGS+=-I/sw/include |
21 |
-LFLAGS+=-L/sw/lib |
|
22 |
-SONAMEOPT= |
|
38 |
+LIB_LDFLAGS+=-L/sw/lib |
|
39 |
+BIN_LDFLAGS+=-L/sw/lib -Wl,-rpath,'$$ORIGIN' |
|
40 |
+SHLIBEXT:=dylib |
|
23 | 41 |
else |
42 |
+LIB_LDFLAGS+=-Wl,-soname,libBlinkenLib.$(SHLIBEXT).$(VERSION_MAJOR) |
|
43 |
+BIN_LDFLAGS+=-Wl,-rpath,'$$ORIGIN' |
|
24 | 44 |
SHLIBEXT:=so |
25 |
-SONAMEOPT:=-Wl,-soname,libBlinkenLib.$(SHLIBEXT).$(VERSION_MAJOR) |
|
26 | 45 |
endif |
27 |
- |
|
28 |
-ifeq ($(BLINKENLIB_CFG_MNG),1) |
|
29 |
-BLINKEN_MNG_H:=BlinkenMng.h |
|
30 |
-BLINKEN_MNG_O:=BlinkenMng.o |
|
31 |
-LMNG:=-lmng -lz |
|
32 | 46 |
endif |
33 | 47 |
|
34 |
-ifeq ($(BLINKENLIB_CFG_GIF),1) |
|
35 |
-BLINKEN_GIF_H:=BlinkenGif.h |
|
36 |
-BLINKEN_GIF_O:=BlinkenGif.o |
|
37 |
-LGIF:=-lgif |
|
38 |
-endif |
|
48 |
+.PHONY: all clean |
|
49 |
+.SUFFIXES: |
|
50 |
+SUFFIXES:= |
|
51 |
+.SECONDARY: |
|
39 | 52 |
|
40 |
-LIB_OBJS:=BlinkenColorizer.o BlinkenFrame.o BlinkenMovie.o \ |
|
41 |
- $(BLINKEN_MNG_O) $(BLINKEN_GIF_O) \ |
|
42 |
- BlinkenProto.o Tools.o |
|
53 |
+all: libBlinkenLib.a \ |
|
54 |
+ libBlinkenLib.$(SHLIBEXT).$(VERSION_MAJOR) \ |
|
55 |
+ libBlinkenLib.$(SHLIBEXT).$(VERSION) libBlinkenLib.$(SHLIBEXT) |
|
43 | 56 |
|
44 |
-.phony: all clean |
|
57 |
+all: BlinkenConv BlinkenSend BlinkenRecv |
|
45 | 58 |
|
46 |
-all: libBlinkenLib.a libBlinkenLib.$(SHLIBEXT).$(VERSION_MAJOR) libBlinkenLib.$(SHLIBEXT).$(VERSION) libBlinkenLib.$(SHLIBEXT) BlinkenConv BlinkenSend BlinkenRecv BlinkenOutput BlinkenDeviceOutput |
|
59 |
+ifeq ($(BLINKENLIB_CFG_WIN),0) |
|
60 |
+all: BlinkenOutput BlinkenDeviceOutput |
|
61 |
+endif |
|
47 | 62 |
|
48 | 63 |
config.h: ../config/config.h |
49 | 64 |
cp $< $@ |
... | ... |
@@ -57,7 +72,10 @@ BlinkenProto.o: BlinkenProto.c BlinkenProto.h BlinkenProtoIntern.h |
57 | 72 |
BlinkenFrame.o: BlinkenFrame.c BlinkenConstants.h BlinkenColorizer.h BlinkenFrame.h BlinkenProto.h BlinkenProtoIntern.h Tools.h |
58 | 73 |
$(CC) $(CFLAGS) -c -o $@ $< |
59 | 74 |
|
60 |
-BlinkenMovie.o: BlinkenMovie.c BlinkenConstants.h BlinkenColorizer.h BlinkenFrame.h BlinkenProto.h BlinkenMovie.h $(BLINKEN_MNG_H) $(BLINKEN_GIF_H) Tools.h config.h |
|
75 |
+BlinkenGif.o: BlinkenGif.c BlinkenConstants.h BlinkenColorizer.h BlinkenFrame.h BlinkenProto.h BlinkenMovie.h Tools.h config.h |
|
76 |
+ $(CC) $(CFLAGS) -c -o $@ $< |
|
77 |
+ |
|
78 |
+BlinkenMovie.o: BlinkenMovie.c BlinkenConstants.h BlinkenColorizer.h BlinkenFrame.h BlinkenProto.h BlinkenMovie.h BlinkenGif.h BlinkenMng.h Tools.h config.h |
|
61 | 79 |
$(CC) $(CFLAGS) -c -o $@ $< |
62 | 80 |
|
63 | 81 |
BlinkenMng.o: BlinkenMng.c BlinkenConstants.h BlinkenColorizer.h BlinkenFrame.h BlinkenProto.h BlinkenMovie.h Tools.h config.h |
... | ... |
@@ -71,7 +89,7 @@ libBlinkenLib.a: $(LIB_OBJS) |
71 | 89 |
$(RANLIB) $@ |
72 | 90 |
|
73 | 91 |
libBlinkenLib.$(SHLIBEXT).$(VERSION): $(LIB_OBJS) |
74 |
- $(CC) -shared $(SONAMEOPT) $(LIB_LFLAGS) -o $@ $+ $(LMNG) $(LGIF) |
|
92 |
+ $(CC) -shared $(LIB_LDFLAGS) -o $@ $+ $(LIB_LDLIBS) |
|
75 | 93 |
|
76 | 94 |
libBlinkenLib.$(SHLIBEXT).$(VERSION_MAJOR): libBlinkenLib.$(SHLIBEXT).$(VERSION) |
77 | 95 |
rm -f $@ |
... | ... |
@@ -88,31 +106,31 @@ BlinkenConv.o: BlinkenConv.c BlinkenLib.h config.h BlinkenColorizer.h BlinkenPro |
88 | 106 |
$(CC) $(CFLAGS) -c -o $@ $< |
89 | 107 |
|
90 | 108 |
BlinkenConv: BlinkenConv.o libBlinkenLib.$(SHLIBEXT) |
91 |
- $(CC) $(BIN_LFLAGS) -o $@ $< -lBlinkenLib |
|
109 |
+ $(CC) $(BIN_LDFLAGS) -o $@ $< -lBlinkenLib $(BIN_LDLIBS) |
|
92 | 110 |
|
93 | 111 |
BlinkenSend.o: BlinkenSend.c BlinkenLib.h config.h BlinkenColorizer.h BlinkenProto.h BlinkenFrame.h BlinkenMovie.h Tools2.h |
94 | 112 |
$(CC) $(CFLAGS) -c -o $@ $< |
95 | 113 |
|
96 | 114 |
BlinkenSend: BlinkenSend.o Tools2.o libBlinkenLib.$(SHLIBEXT) |
97 |
- $(CC) $(BIN_LFLAGS) -o $@ $(filter %.o,$^) -lBlinkenLib |
|
115 |
+ $(CC) $(BIN_LDFLAGS) -o $@ $(filter %.o,$^) -lBlinkenLib $(BIN_LDLIBS) |
|
98 | 116 |
|
99 | 117 |
BlinkenRecv.o: BlinkenRecv.c BlinkenLib.h config.h BlinkenColorizer.h BlinkenProto.h BlinkenFrame.h BlinkenMovie.h Tools2.h |
100 | 118 |
$(CC) $(CFLAGS) -c -o $@ $< |
101 | 119 |
|
102 | 120 |
BlinkenRecv: BlinkenRecv.o Tools2.o libBlinkenLib.$(SHLIBEXT) |
103 |
- $(CC) $(BIN_LFLAGS) -o $@ $(filter %.o,$^) -lBlinkenLib |
|
121 |
+ $(CC) $(BIN_LDFLAGS) -o $@ $(filter %.o,$^) -lBlinkenLib $(BIN_LDLIBS) |
|
104 | 122 |
|
105 | 123 |
BlinkenOutput.o: BlinkenOutput.c BlinkenLib.h config.h BlinkenColorizer.h BlinkenProto.h BlinkenFrame.h BlinkenMovie.h |
106 | 124 |
$(CC) $(CFLAGS) -c -o $@ $< |
107 | 125 |
|
108 | 126 |
BlinkenOutput: BlinkenOutput.o libBlinkenLib.$(SHLIBEXT) |
109 |
- $(CC) $(BIN_LFLAGS) -o $@ $< -lBlinkenLib |
|
127 |
+ $(CC) $(BIN_LDFLAGS) -o $@ $< -lBlinkenLib $(BIN_LDLIBS) |
|
110 | 128 |
|
111 | 129 |
BlinkenDeviceOutput.o: BlinkenDeviceOutput.c BlinkenLib.h config.h BlinkenColorizer.h BlinkenProto.h BlinkenFrame.h BlinkenMovie.h |
112 | 130 |
$(CC) $(CFLAGS) -c -o $@ $< |
113 | 131 |
|
114 | 132 |
BlinkenDeviceOutput: BlinkenDeviceOutput.o libBlinkenLib.$(SHLIBEXT) |
115 |
- $(CC) $(BIN_LFLAGS) -o $@ $< -lBlinkenLib |
|
133 |
+ $(CC) $(BIN_LDFLAGS) -o $@ $< -lBlinkenLib $(BIN_LDLIBS) |
|
116 | 134 |
|
117 | 135 |
clean: |
118 | 136 |
rm -f BlinkenConv BlinkenSend BlinkenRecv BlinkenOutput BlinkenDeviceOutput libBlinkenLib.$(SHLIBEXT)* libBlinkenLib.a *.o config.h |
... | ... |
@@ -8,6 +8,7 @@ |
8 | 8 |
#include <string.h> |
9 | 9 |
#ifdef WIN32 |
10 | 10 |
#include <winsock2.h> |
11 |
+#include <ws2tcpip.h> |
|
11 | 12 |
#else |
12 | 13 |
#include <sys/types.h> |
13 | 14 |
#include <sys/socket.h> |
... | ... |
@@ -17,6 +18,31 @@ |
17 | 18 |
|
18 | 19 |
#include "Tools2.h" |
19 | 20 |
|
21 |
+#ifdef WIN32 |
|
22 |
+static int inet_pton(int af, const char *src, void *dst) |
|
23 |
+{ |
|
24 |
+ struct sockaddr_storage ss; |
|
25 |
+ int size = sizeof(ss); |
|
26 |
+ char src_copy[INET6_ADDRSTRLEN + 1]; |
|
27 |
+ |
|
28 |
+ ZeroMemory(&ss, sizeof(ss)); |
|
29 |
+ strncpy (src_copy, src, sizeof(src_copy)); |
|
30 |
+ src_copy[sizeof(src_copy) - 1] = 0; |
|
31 |
+ |
|
32 |
+ if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) { |
|
33 |
+ switch(af) { |
|
34 |
+ case AF_INET: |
|
35 |
+ *(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr; |
|
36 |
+ return 1; |
|
37 |
+ case AF_INET6: |
|
38 |
+ *(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr; |
|
39 |
+ return 1; |
|
40 |
+ } |
|
41 |
+ } |
|
42 |
+ return 0; |
|
43 |
+} |
|
44 |
+#endif |
|
45 |
+ |
|
20 | 46 |
// convert text to IPv4 address |
21 | 47 |
int txt2addr(char *text, struct sockaddr_in *addr) |
22 | 48 |
{ |
... | ... |
@@ -10,6 +10,8 @@ PACK_FILES:=BlinkenLib ChangeLog config examples install Makefile |
10 | 10 |
|
11 | 11 |
.PHONY: all conf clean distclean install uninstall update pack |
12 | 12 |
.SUFFIXES: |
13 |
+SUFFIXES:= |
|
14 |
+.SECONDARY: |
|
13 | 15 |
|
14 | 16 |
all: conf |
15 | 17 |
$(MAKE) -C BlinkenLib all |
... | ... |
@@ -17,12 +19,11 @@ all: conf |
17 | 19 |
conf: |
18 | 20 |
$(MAKE) -C config all |
19 | 21 |
|
20 |
-clean: conf |
|
22 |
+clean: |
|
21 | 23 |
$(MAKE) -C BlinkenLib clean |
22 | 24 |
|
23 | 25 |
distclean: clean |
24 | 26 |
$(MAKE) -C config clean |
25 |
- rm -rf tmp |
|
26 | 27 |
|
27 | 28 |
install: all |
28 | 29 |
$(MAKE) -C install install |
... | ... |
@@ -23,3 +23,8 @@ cleaning source tree completely |
23 | 23 |
run "make distclean" |
24 | 24 |
this cleans all autodetected settings and all objects, libraries and binaries |
25 | 25 |
|
26 |
+cross-compiling for Windows |
|
27 |
+--------------------------- |
|
28 |
+clean source tree completely |
|
29 |
+run "make CC=x86_64-w64-mingw32-gcc" in this directory |
|
30 |
+ |
... | ... |
@@ -7,12 +7,18 @@ CC:=gcc |
7 | 7 |
INCDIR:=-I/sw/include |
8 | 8 |
LIBDIR:=-L/sw/lib |
9 | 9 |
|
10 |
-CFGS:=$(addsuffix .cfg, osx mng gif gif4 gif5) |
|
10 |
+CFGS:=$(addsuffix .cfg,win osx mng gif gif4 gif5) |
|
11 | 11 |
|
12 |
-.phony: all clean |
|
12 |
+.PHONY: all clean |
|
13 |
+.SUFFIXES: |
|
14 |
+SUFFIXES:= |
|
15 |
+.SECONDARY: |
|
13 | 16 |
|
14 | 17 |
all: config.cfg config.mk config.h |
15 | 18 |
|
19 |
+win.cfg: |
|
20 |
+ if echo '#include <windows.h>' | $(CC) -E -x c - >/dev/null 2>/dev/null; then echo "WIN=1"; else echo "WIN=0"; fi >$@ |
|
21 |
+ |
|
16 | 22 |
osx.cfg: |
17 | 23 |
echo "OSX=" | tr -d '\n' >$@ |
18 | 24 |
(if [ "$$(uname -s)" == "Darwin" ]; then echo "1"; else echo "0"; fi) >>$@ |
... | ... |
@@ -32,7 +38,7 @@ gif.cfg: gif4.cfg gif5.cfg |
32 | 38 |
((cat $^ | grep -q 1 && echo "1") || echo "0") >>$@ |
33 | 39 |
|
34 | 40 |
config.cfg: $(CFGS) |
35 |
- cat $+ >config.cfg |
|
41 |
+ cat $^ >config.cfg |
|
36 | 42 |
|
37 | 43 |
config.mk: config.cfg |
38 | 44 |
sed 's/^\([A-Z0-9]*\)=\([01]\)$$/BLINKENLIB_CFG_\1:=\2/' <$< >$@ |
... | ... |
@@ -45,5 +51,5 @@ config.h: config.cfg Makefile ../version.mk |
45 | 51 |
grep '^VERSION_[A-Z]*:=[0-9]*' ../version.mk | sed 's/^/#define BLINKENLIB_/;s/:=/ /' >>$@ |
46 | 52 |
|
47 | 53 |
clean: |
48 |
- rm -f $(CFGS) config.mk config.h |
|
54 |
+ rm -f $(CFGS) config.cfg config.mk config.h |
|
49 | 55 |
|
... | ... |
@@ -33,7 +33,10 @@ HEADERS:=BlinkenLib.h BlinkenMovie.h BlinkenFrame.h BlinkenColorizer.h \ |
33 | 33 |
LIBS:=libBlinkenLib.a libBlinkenLib.$(SHLIBEXT).$(VERSION) |
34 | 34 |
EXECS:=BlinkenConv BlinkenSend BlinkenRecv BlinkenOutput |
35 | 35 |
|
36 |
-.phony: install uninstall |
|
36 |
+.PHONY: install uninstall |
|
37 |
+.SUFFIXES: |
|
38 |
+SUFFIXES:= |
|
39 |
+.SECONDARY: |
|
37 | 40 |
|
38 | 41 |
install: |
39 | 42 |
$(INSTALL) -d $(PREFIX)/include/BlinkenLib |
40 | 43 |