refactor-into-dirs.patch

Signed-off-by: Andy Green <andy@warmcat.com>
diff --git a/Makefile b/Makefile
index 84a6f90..bf67643 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 abeb07e..bc9af54 100644
--- a/README-test-server
+++ b/README-test-server
@@ -2,7 +2,8 @@
 ---------------------------------
 
 $ 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 @@
 
   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 0000000..be381c3
--- /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 0000000..61a6a98
--- /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
Binary files differ
diff --git a/test-server.c b/test-server/test-server.c
similarity index 98%
rename from test-server.c
rename to test-server/test-server.c
index a37aa12..2245a67 100644
--- a/test-server.c
+++ b/test-server/test-server.c
@@ -4,7 +4,7 @@
 #include <getopt.h>
 #include <string.h>
 
-#include "libwebsockets.h"
+#include "../lib/libwebsockets.h"
 
 /*
  * libwebsocket Example server  Copyright 2010 Andy Green <andy@warmcat.com>
diff --git a/test.html b/test-server/test.html
similarity index 93%
rename from test.html
rename to test-server/test.html
index 59ad43f..905a0c5 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";
 	
 }  
 </script>