From 7310e9c77bfc8be87fe5491d0c15b3f8c6b3548f Mon Sep 17 00:00:00 2001 From: Andy Green Date: Mon, 1 Nov 2010 09:12:17 +0000 Subject: [PATCH] refactor-into-dirs.patch Signed-off-by: Andy Green --- Makefile | 25 +++++++++++---------- README-test-server | 9 ++++---- lib/Makefile | 15 +++++++++++++ libwebsockets.c => lib/libwebsockets.c | 0 libwebsockets.h => lib/libwebsockets.h | 0 md5.c => lib/md5.c | 0 kernel-doc => scripts/kernel-doc | 0 test-server/Makefile | 14 ++++++++++++ favicon.ico => test-server/favicon.ico | Bin test-server.c => test-server/test-server.c | 2 +- test.html => test-server/test.html | 2 +- 11 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 lib/Makefile rename libwebsockets.c => lib/libwebsockets.c (100%) rename libwebsockets.h => lib/libwebsockets.h (100%) rename md5.c => lib/md5.c (100%) rename kernel-doc => scripts/kernel-doc (100%) create mode 100644 test-server/Makefile rename favicon.ico => test-server/favicon.ico (100%) rename test-server.c => test-server/test-server.c (99%) rename test.html => test-server/test.html (94%) diff --git a/Makefile b/Makefile index 84a6f90f..bf67643d 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,17 @@ -CFLAGS= -Wall -Werror -rdynamic -fPIC -c - +export CFLAGS= -Wall -Werror -rdynamic -fPIC -c all: - gcc $(CFLAGS) libwebsockets.c - gcc $(CFLAGS) md5.c - gcc libwebsockets.o md5.o --shared -o libwebsockets.so - - gcc $(CFLAGS) test-server.c - gcc test-server.o ./libwebsockets.so -o test-server - ./kernel-doc -text libwebsockets.c test-server.c > \ - libwebsockets-api-doc.txt + make -C lib + make -C test-server + ./scripts/kernel-doc -text \ + ./lib/libwebsockets.c \ + ./test-server/test-server.c > libwebsockets-api-doc.txt clean: - rm -f *.o *.so test-server - + make -C lib clean + make -C test-server clean + +install: + make -C lib install + make -C test-server install + diff --git a/README-test-server b/README-test-server index abeb07e7..bc9af549 100644 --- a/README-test-server +++ b/README-test-server @@ -2,7 +2,8 @@ Using test-server as a quickstart --------------------------------- $ make -$ ./test-server +$ sudo make install +$ libwebsockets-test-server should be enough to get a test server listening on port 7861. @@ -10,9 +11,9 @@ If you point your browser (eg, Chrome) to http://127.0.0.1:7681 -It will fetch "test.html", and then run the script in there -on the browser to open a websocket connection. Incrementing -numbers should appear in the browser display. +It will fetch "./test-server/test.html", and then run the +script in there on the browser to open a websocket connection. +Incrementing numbers should appear in the browser display. test-server.c is all that is needed to use libwebsockets for serving both the script html over http and websockets. diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 00000000..be381c3c --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,15 @@ +export LDIR=$(shell if [ -z "gcc --print-search-dirs | grep libraries | sed s/\\//\\n/g | grep lib64 | grep 64 | head -n1" ] ; then echo lib; else echo lib64 ; fi ) + +all: + gcc $(CFLAGS) libwebsockets.c + gcc $(CFLAGS) md5.c + gcc libwebsockets.o md5.o --shared -o libwebsockets.so + +clean: + rm -f *.o *.so + +install: + cp -rf libwebsockets.so $(DESTDIR)/usr/$(LDIR) + cp -rf libwebsockets.h $(DESTDIR)/usr/include + + diff --git a/libwebsockets.c b/lib/libwebsockets.c similarity index 100% rename from libwebsockets.c rename to lib/libwebsockets.c diff --git a/libwebsockets.h b/lib/libwebsockets.h similarity index 100% rename from libwebsockets.h rename to lib/libwebsockets.h diff --git a/md5.c b/lib/md5.c similarity index 100% rename from md5.c rename to lib/md5.c diff --git a/kernel-doc b/scripts/kernel-doc similarity index 100% rename from kernel-doc rename to scripts/kernel-doc diff --git a/test-server/Makefile b/test-server/Makefile new file mode 100644 index 00000000..61a6a98f --- /dev/null +++ b/test-server/Makefile @@ -0,0 +1,14 @@ +all: + gcc $(CFLAGS) test-server.c + gcc test-server.o \ + -L ../lib \ + -lwebsockets \ + -o libwebsockets-test-server + +clean: + rm -f *.o libwebsockets-test-server + +install: + cp -f libwebsockets-test-server $(DESTDIR)/usr/bin + + diff --git a/favicon.ico b/test-server/favicon.ico similarity index 100% rename from favicon.ico rename to test-server/favicon.ico diff --git a/test-server.c b/test-server/test-server.c similarity index 99% rename from test-server.c rename to test-server/test-server.c index a37aa121..2245a67e 100644 --- a/test-server.c +++ b/test-server/test-server.c @@ -4,7 +4,7 @@ #include #include -#include "libwebsockets.h" +#include "../lib/libwebsockets.h" /* * libwebsocket Example server Copyright 2010 Andy Green diff --git a/test.html b/test-server/test.html similarity index 94% rename from test.html rename to test-server/test.html index 59ad43f3..905a0c57 100644 --- a/test.html +++ b/test-server/test.html @@ -30,7 +30,7 @@ function got_packet(msg){ // alert('got packet' + msg.data); - document.write(msg.data + "\n"); + document.body.textContent = msg.data + "\n"; }