[mw-devel] MW3 r1332 - in trunk: . src src/server src/webclient

arthur at sucs.org arthur at sucs.org
Wed Feb 13 18:09:35 GMT 2013


Author: arthur
Date: 2013-02-13 18:09:35 +0000 (Wed, 13 Feb 2013)
New Revision: 1332

Modified:
   trunk/Makefile.common
   trunk/src/Makefile
   trunk/src/ipc.h
   trunk/src/server/Makefile
   trunk/src/server/servsock.c
   trunk/src/socket.c
   trunk/src/socket.h
   trunk/src/webclient/Makefile
Log:
Makefile factorisation, and rewrite of FOURCC macros


Modified: trunk/Makefile.common
===================================================================
--- trunk/Makefile.common	2013-02-13 11:52:15 UTC (rev 1331)
+++ trunk/Makefile.common	2013-02-13 18:09:35 UTC (rev 1332)
@@ -28,3 +28,73 @@
 
 # The non source files that should get installed
 INSTALLFILES = colour help login.banner scripthelp talkhelp wizhelp COPYING INSTALL LICENSE README
+
+LOGDIR := $(localstatedir)/log/mw
+MSGDIR := $(localstatedir)/run/mw
+STATEDIR := $(localstatedir)/lib/mw
+HOMEPATH := $(libdir)/mw
+
+GCCMAJOR := $(echo __GNUC__ | $compiler -E -xc - | tail -n 1)
+GCCMINOR := $(echo __GNUC_MINOR__ | $compiler -E -xc - | tail -n 1)
+GCCVER := $(shell printf "%02d%02d" $(GCCMAJOR) $(GCCMINOR))
+
+
+ifeq ($(JSFLAGS),)
+	#Fedora
+	JSFLAGS=$(shell pkg-config --cflags libjs 2>/dev/null)
+	JSLIBS=$(shell pkg-config --libs-only-l libjs 2>/dev/null)
+	JSSCRIPTTYPE=JSObject # Some idiot made the script APIs different without changing the version
+endif
+ifeq ($(JSFLAGS),)
+	#Debian
+	JSFLAGS=$(shell pkg-config --cflags mozilla-js)
+	JSLIBS=$(shell pkg-config --libs-only-l mozilla-js)
+	JSSCRIPTTYPE=JSScript
+endif
+
+# cflags for standard 'cc' compiler
+CFLAGS+= -Wall -Wshadow -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Wwrite-strings -Wcast-align -Wbad-function-cast -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -pedantic -std=gnu99 -D_GNU_SOURCE $(JSFLAGS) -DJSSCRIPTTYPE=$(JSSCRIPTTYPE)
+
+# until gcc catches up (4.7.x is good)
+CFLAGS += $(shell if [ $(GCCVER) -lt 0406 ] ; then echo "-Wno-multichar"; fi )
+
+ifdef WITHPIE
+CFLAGS += -fpie
+LDFLAGS += -pie
+endif
+
+# info strings, do not edit.
+DEFS:= -DBUILD_DATE=\"$(shell date +%Y%m%d)\"
+DEFS+= -DBUILD_USER=\"$(shell whoami | awk -f $(DEPTH)src/capitalise.awk)\"
+DEFS+= -DVER_MAJ=\"$(VERSION_MAJOR)\"
+DEFS+= -DVER_MIN=\"$(VERSION_MINOR)\"
+DEFS+= -DVER_TWK=\"$(VERSION_TWEAK)\"
+DEFS+= -DHOMEPATH=\"$(HOMEPATH)\"
+DEFS+= -DLOGDIR=\"$(LOGDIR)\"
+DEFS+= -DSTATEDIR=\"$(STATEDIR)\"
+DEFS+= -DMSGDIR=\"$(MSGDIR)\"
+
+### uncomment for gdb debugging
+LDFLAGS+= -ggdb -g
+CFLAGS+= -ggdb -g -D__NO_STRING_INLINE -fstack-protector-all
+
+### Optimisation - uncomment for release & extra testing
+CFLAGS+=-O0
+
+CFLAGS += $(DEFS)
+
+### The magic which lets us autogenerate dependencies
+CFLAGS += -MMD
+
+CODE=$(wildcard *.c)
+HDRS=$(wildcard *.h)
+
+all: build
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+-include $(CODE:.c=.d)
+
+.PHONY: build install clean test
+

Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	2013-02-13 11:52:15 UTC (rev 1331)
+++ trunk/src/Makefile	2013-02-13 18:09:35 UTC (rev 1332)
@@ -1,68 +1,11 @@
 SRCROOT = $(CURDIR)/..
+DEPTH=../
 include ../Makefile.common
 
-LOGDIR := $(localstatedir)/log/mw
-MSGDIR := $(localstatedir)/run/mw
-STATEDIR := $(localstatedir)/lib/mw
-HOMEPATH := $(libdir)/mw
-
-ifeq ($(JSFLAGS),)
-#Fedora
-JSFLAGS=$(shell pkg-config --cflags libjs 2>/dev/null)
-JSLIBS=$(shell pkg-config --libs-only-l libjs 2>/dev/null)
-JSSCRIPTTYPE=JSObject # Some idiot made the script APIs different without changing the version
-endif
-ifeq ($(JSFLAGS),)
-#Debian
-JSFLAGS=$(shell pkg-config --cflags mozilla-js)
-JSLIBS=$(shell pkg-config --libs-only-l mozilla-js)
-JSSCRIPTTYPE=JSScript
-endif
-
-# cflags for standard 'cc' compiler
-CFLAGS+= -Wall -Wshadow -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Wwrite-strings -Wcast-align -Wbad-function-cast -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -pedantic -std=gnu99 -D_GNU_SOURCE $(JSFLAGS) -DJSSCRIPTTYPE=$(JSSCRIPTTYPE)
 LDLIBS+= -lreadline -ltermcap -lcrypt $(JSLIBS) -lsqlite3 -lcurl -lpthread -lcrypto -ljansson
 
-ifdef WITHPIE
-CFLAGS += -fpie
-LDFLAGS += -pie
-endif
-
-# info strings, do not edit.
-DEFS:= -DBUILD_DATE=\"$(shell date +%Y%m%d)\"
-DEFS+= -DBUILD_USER=\"$(shell whoami | awk -f capitalise.awk)\"
-DEFS+= -DVER_MAJ=\"$(VERSION_MAJOR)\"
-DEFS+= -DVER_MIN=\"$(VERSION_MINOR)\"
-DEFS+= -DVER_TWK=\"$(VERSION_TWEAK)\"
-DEFS+= -DHOMEPATH=\"$(HOMEPATH)\"
-DEFS+= -DLOGDIR=\"$(LOGDIR)\"
-DEFS+= -DSTATEDIR=\"$(STATEDIR)\"
-DEFS+= -DMSGDIR=\"$(MSGDIR)\"
-
-### uncomment for gdb debugging
-LDFLAGS+= -ggdb -g
-CFLAGS+= -ggdb -g -D__NO_STRING_INLINE -fstack-protector-all
-
-### Optimisation - uncomment for release & extra testing
-CFLAGS+=-O0
-
-CFLAGS += $(DEFS)
-
 build: mw
 
-### The magic which lets us autogenerate dependencies
-CFLAGS += -MMD
-
-CODE=$(wildcard *.c)
-HDRS=$(wildcard *.h)
-
-%.o: %.c
-	$(CC) $(CFLAGS) -c -o $@ $<
-	
--include $(CODE:.c=.d)
-
-.PHONY: build install clean test
-
 mw: user.o main.o read.o add.o folders.o new.o perms.o edit.o mod.o who.o\
 echo.o getpass.o mesg.o strings.o special.o Parse.o\
 newmain.o init.o talker.o talker_privs.o colour.o bork.o rooms.o alarm.o\

Modified: trunk/src/ipc.h
===================================================================
--- trunk/src/ipc.h	2013-02-13 11:52:15 UTC (rev 1331)
+++ trunk/src/ipc.h	2013-02-13 18:09:35 UTC (rev 1332)
@@ -6,10 +6,17 @@
 #include "user.h"
 #include "socket.h"
 
-#define MKFOURCC(a,b,c,d) \
-	( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
-	| ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
+#define FOURCC(a) *(uint32_t *)&a
+#define FCC(ch4) ((((uint32_t)(ch4) & 0xFF) << 24) |     \
+		  (((uint32_t)(ch4) & 0xFF00) << 8) |    \
+		  (((uint32_t)(ch4) & 0xFF0000) >> 8) |  \
+		  (((uint32_t)(ch4) & 0xFF000000) >> 24))
 
+/* this needs gcc 4.6 or above to work */
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmultichar"
+#endif
 
 enum ipc_types {
 	IPC_NOOP	= 0,	// Just go through the motions, don't actually write anything to the FIFO
@@ -37,13 +44,18 @@
 	IPC_PROTLEVEL	= 24,
 	IPC_PROTPOWER	= 25,
 	IPC_DOING	= 26,
-	IPC_UPTIME	= MKFOURCC('U','P','T','M'),
-	IPC_SAYTOROOM	= MKFOURCC('S','A','Y','R'),
-	IPC_SAYTOUSER	= MKFOURCC('S','A','Y','U'),
-	IPC_SAYTOALL	= MKFOURCC('W','A','L','L'),
-	IPC_TALKERROR	= MKFOURCC('T','E','R','R')
+	IPC_UPTIME	= FCC('UPTM'),
+	IPC_SAYTOROOM	= FCC('SAYR'),
+	IPC_SAYTOUSER	= FCC('SAYU'),
+	IPC_SAYTOALL	= FCC('WALL'),
+	IPC_TALKERROR	= FCC('TERR')
 };
 
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
+#pragma GCC diagnostic pop
+#endif
+
+
 typedef int (send_filter)(const struct person * usr, const struct who * who, const void * info);
 
 void ipc_connect(const char *target);

Modified: trunk/src/server/Makefile
===================================================================
--- trunk/src/server/Makefile	2013-02-13 11:52:15 UTC (rev 1331)
+++ trunk/src/server/Makefile	2013-02-13 18:09:35 UTC (rev 1332)
@@ -1,36 +1,10 @@
-include ../../Makefile.common
-#libdir := /usr/lib
-#localstatedir := /var
+DEPTH=../../
+include $(DEPTH)Makefile.common
 
-LOGDIR := $(localstatedir)/log/mw
-MSGDIR := $(localstatedir)/run/mw
-STATEDIR := $(localstatedir)/lib/mw
-HOMEPATH := $(libdir)/mw
-
-# cflags for standard 'cc' compiler
-CFLAGS= -Wall -Wshadow -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Wwrite-strings -Wcast-align -Wbad-function-cast -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -pedantic --std=gnu99 -D_GNU_SOURCE -I.. -I/usr/include/postgresql
-#LDFLAGS+= -pie
-
-# info strings, do not edit.
-DEFS:= -DBUILD_DATE=\"$(shell date +%Y%m%d)\"
-DEFS+= -DBUILD_USER=\"$(shell whoami | awk -f ../capitalise.awk)\"
-DEFS+= -DVER_MAJ=\"$(VERSION_MAJOR)\"
-DEFS+= -DVER_MIN=\"$(VERSION_MINOR)\"
-DEFS+= -DVER_TWK=\"$(VERSION_TWEAK)\"
-DEFS+= -DHOMEPATH=\"$(HOMEPATH)\"
-DEFS+= -DLOGDIR=\"$(LOGDIR)\"
-DEFS+= -DSTATEDIR=\"$(STATEDIR)\"
-DEFS+= -DMSGDIR=\"$(MSGDIR)\"
-
 ### uncomment for gdb debugging
-LDFLAGS+= -ggdb -g -lcrypt -lpq -ljansson -lsqlite3
-CFLAGS+= -ggdb -g -D__NO_STRING_INLINE -fstack-protector-all
+CFLAGS+= -I..
+LDLIBS+= -lcrypt -lpq -ljansson -lsqlite3
 
-### Optimisation - uncomment for release & extra testing
-#CFLAGS+=-O3
-
-CFLAGS += $(DEFS)
-
 build: mwserv
 
 ### The magic which lets us autogenerate dependencies

Modified: trunk/src/server/servsock.c
===================================================================
--- trunk/src/server/servsock.c	2013-02-13 11:52:15 UTC (rev 1331)
+++ trunk/src/server/servsock.c	2013-02-13 18:09:35 UTC (rev 1332)
@@ -20,6 +20,7 @@
 #include "../who.h"
 #include "../rooms.h"
 #include "../talker_privs.h"
+#include "../ipc.h"
 
 struct list_head connection_list;
 

Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c	2013-02-13 11:52:15 UTC (rev 1331)
+++ trunk/src/socket.c	2013-02-13 18:09:35 UTC (rev 1332)
@@ -9,12 +9,6 @@
 
 #include "socket.h"
 
-/* generate FOURCC code from a string */
-inline unsigned int FOURCC(const char *a)
-{
-	return ((a[3]<<24)|(a[2]<<16)|(a[1]<<8)|a[0]);
-}
-
 /* create an empty message */
 ipc_message_t * ipcmsg_create(uint32_t type, uint32_t src)
 {

Modified: trunk/src/socket.h
===================================================================
--- trunk/src/socket.h	2013-02-13 11:52:15 UTC (rev 1331)
+++ trunk/src/socket.h	2013-02-13 18:09:35 UTC (rev 1332)
@@ -57,7 +57,6 @@
 
 #define _MIN(a,b) (a<b)?a:b
 
-unsigned int FOURCC(const char *a);
 /* socket.c */
 ipc_message_t *ipcmsg_create(uint32_t type,uint32_t src);
 void ipcmsg_append(ipc_message_t *msg, const void *data, int len);

Modified: trunk/src/webclient/Makefile
===================================================================
--- trunk/src/webclient/Makefile	2013-02-13 11:52:15 UTC (rev 1331)
+++ trunk/src/webclient/Makefile	2013-02-13 18:09:35 UTC (rev 1332)
@@ -1,51 +1,11 @@
-include ../../Makefile.common
-#libdir := /usr/lib
-#localstatedir := /var
+DEPTH=../../
+include $(DEPTH)Makefile.common
 
-LOGDIR := $(localstatedir)/log/mw
-MSGDIR := $(localstatedir)/run/mw
-STATEDIR := $(localstatedir)/lib/mw
-HOMEPATH := $(libdir)/mw
+LDLIBS+= -lcrypt -lpq -ljansson
+CFLAGS+= -I.. -I/usr/include/postgresql
 
-# cflags for standard 'cc' compiler
-CFLAGS= -Wall -Wshadow -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith -Wwrite-strings -Wcast-align -Wbad-function-cast -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -pedantic --std=gnu99 -D_GNU_SOURCE -I.. -I/usr/include/postgresql
-#LDFLAGS+= -pie
-
-# info strings, do not edit.
-DEFS:= -DBUILD_DATE=\"$(shell date +%Y%m%d)\"
-DEFS+= -DBUILD_USER=\"$(shell whoami | awk -f ../capitalise.awk)\"
-DEFS+= -DVER_MAJ=\"$(VERSION_MAJOR)\"
-DEFS+= -DVER_MIN=\"$(VERSION_MINOR)\"
-DEFS+= -DVER_TWK=\"$(VERSION_TWEAK)\"
-DEFS+= -DHOMEPATH=\"$(HOMEPATH)\"
-DEFS+= -DLOGDIR=\"$(LOGDIR)\"
-DEFS+= -DSTATEDIR=\"$(STATEDIR)\"
-DEFS+= -DMSGDIR=\"$(MSGDIR)\"
-
-### uncomment for gdb debugging
-LDFLAGS+= -ggdb -g -lcrypt -lpq -ljansson
-CFLAGS+= -ggdb -g -D__NO_STRING_INLINE -fstack-protector-all
-
-### Optimisation - uncomment for release & extra testing
-#CFLAGS+=-O3
-
-CFLAGS += $(DEFS)
-
 build: mwpoll
 
-### The magic which lets us autogenerate dependencies
-CFLAGS += -MMD
-
-CODE=$(wildcard *.c)
-HDRS=$(wildcard *.h)
-
-%.o: %.c
-	$(CC) $(CFLAGS) -c -o $@ $<
-
--include $(CODE:.c=.d)
-
-.PHONY: build install clean test
-
 mwpoll: mwpoll.o import.o comms.o mwstring.o ../perms.o ../strings.o ../files.o ../ipc.o ../iconv.o ../special.o ../socket.o ../nonce.o
 	$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
 




More information about the mw-devel mailing list