[mw-devel] [Git][arthur/mw][master] Build system improvements
Andrew Price
welshbyte at sucs.org
Fri Mar 4 01:59:54 GMT 2016
Andrew Price pushed to branch master at Justin Mitchell / mw
Commits:
c73d5b10 by Andrew Price at 2016-03-04T01:58:57+00:00
Build system improvements
Various cleanups and simplifications of the makefiles, plus:
- an additional 'make RELEASE_BUILD=1' mode which switches on
optimisation and -D_FORTIFY_SOURCE=2, and switches off -Werror
- Use RELEASE_BUILD=1 in rpm and deb packaging
- Build with PIE and full RELRO by default
- Add CFLAGS_APPEND to append options instead of overriding CFLAGS
- - - - -
9 changed files:
- Makefile
- Makefile.common
- debian-template/rules
- mw.spec
- src/Makefile
- src/client/Makefile
- src/client/js.c
- src/server/Makefile
- src/utils/Makefile
Changes:
=====================================
Makefile
=====================================
--- a/Makefile
+++ b/Makefile
@@ -6,11 +6,15 @@ build:
$(MAKE) -C src $@
$(MAKE) -C po $@
-ifeq ($(GITVER),)
-# These rules can only be called from inside an exported tree
-install:
+# The non source files that should get installed
+INSTALLFILES = colour help login.banner scripthelp talkhelp wizhelp COPYING INSTALL LICENSE README
+install-home:
install -d $(DESTDIR)$(libdir)/mw
cp -a $(INSTALLFILES) $(DESTDIR)$(libdir)/mw/
+
+ifeq ($(GITVER),)
+# These rules can only be called from inside an exported tree
+install: install-home
install -d $(DESTDIR)$(initddir)
install mwserv.init $(DESTDIR)$(initddir)/mwserv
$(MAKE) -C src $@
@@ -63,4 +67,4 @@ clean:
version:
@echo $(VERSION)
-.PHONY: build clean rpm deb tarball export install version
+.PHONY: build clean rpm deb tarball export install-static install version
=====================================
Makefile.common
=====================================
--- a/Makefile.common
+++ b/Makefile.common
@@ -10,6 +10,9 @@ endif
MWVERSION = mw3-$(VERSION)
+# Build with `make RELEASE_BUILD=1` to disable debugging features and enable optimisation
+RELEASE_BUILD ?= 0
+
prefix ?= /usr
libdir ?= $(prefix)/lib
bindir ?= $(prefix)/bin
@@ -17,9 +20,6 @@ datadir ?= $(prefix)/share
localstatedir ?= /var
initddir ?= /etc/init.d
-# 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
@@ -29,21 +29,33 @@ 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))
-JSDIR=$(DEPTH)mozjs/installroot
-JSFLAGS=-include $(JSDIR)/usr/include/js-17.0/js/RequiredDefines.h -I/usr/include/nspr -I$(JSDIR)/usr/include/js-17.0
-JSOBJ=$(DEPTH)mozjs/installroot/usr/lib/libmozjs-17.0.a
-JSSCRIPTTYPE=JSScript
-
-# cflags for standard 'cc' compiler
-CFLAGS+= -Wall -Wshadow -Wmissing-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)
+JSDIR = $(DEPTH)mozjs/installroot
+JSOBJ = $(JSDIR)/usr/lib/libmozjs-17.0.a
+JSFLAGS = \
+ -include $(JSDIR)/usr/include/js-17.0/js/RequiredDefines.h \
+ -I/usr/include/nspr \
+ -I$(JSDIR)/usr/include/js-17.0
+
+WARNINGS = \
+ -Wall \
+ -Wshadow \
+ -Wmissing-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 \
# until gcc catches up (4.7.x is good)
-CFLAGS += $(shell if [ $(GCCVER) -lt 0406 ] ; then echo "-Wno-multichar"; fi )
+WARNINGS += $(shell if [ $(GCCVER) -lt 0406 ] ; then echo "-Wno-multichar"; fi )
-ifdef WITHPIE
-CFLAGS += -fpie
-LDFLAGS += -pie
-endif
+CCSEC = -fpie -fstack-protector-all
+LDSEC = -pie -Wl,-z,relro,-z,now
# info strings, do not edit.
DEFS:= -DBUILD_DATE=\"$(shell date +%Y%m%d)\"
@@ -54,17 +66,30 @@ 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
+DEFS+= -D_GNU_SOURCE
-### Optimisation - uncomment for release & extra testing
-CFLAGS+=-O0 -Werror
+# Set debugging and optimisation features depending on the build type
+MWLDFLAGS += $(LDSEC)
+ifneq ($(RELEASE_BUILD),0)
+MWLDFLAGS += -O2
+else
+MWLDFLAGS += -O0
+endif
-CFLAGS += $(DEFS)
+MWCFLAGS = -std=gnu99 -pedantic -g $(DEFS) $(JSFLAGS) $(CCSEC) $(WARNINGS)
+ifneq ($(RELEASE_BUILD),0)
+MWCFLAGS += -O2
+# This requires optimisation so add it here instead of CCSEC
+MWCFLAGS += -D_FORTIFY_SOURCE=2
+else
+MWCFLAGS += -O0 -Werror
+endif
### The magic which lets us autogenerate dependencies
-CFLAGS += -MMD
+CFLAGS = $(MWCFLAGS) -MMD
+LDFLAGS = $(MWLDFLAGS)
+# Let the user add some flags at the end
+CFLAGS_APPEND =
CODE=$(wildcard *.c)
HDRS=$(wildcard *.h)
@@ -72,7 +97,7 @@ HDRS=$(wildcard *.h)
all: build
%.o: %.c
- $(CC) $(CFLAGS) -c -o $@ $<
+ $(CC) $(CFLAGS) $(CFLAGS_APPEND) -c -o $@ $<
-include $(CODE:.c=.d)
=====================================
debian-template/rules
=====================================
--- a/debian-template/rules
+++ b/debian-template/rules
@@ -1,5 +1,6 @@
#!/usr/bin/make -f
#export DH_VERBOSE=1
+export RELEASE_BUILD=1
%:
dh $@
=====================================
mw.spec
=====================================
--- a/mw.spec
+++ b/mw.spec
@@ -22,7 +22,7 @@ architecture, intended to be used over telnet or similar.
%setup -q
%build
-make libdir="%{_libdir}" bindir="%{_bindir}"
+make libdir="%{_libdir}" bindir="%{_bindir}" RELEASE_BUILD=1
%install
make DESTDIR=$RPM_BUILD_ROOT prefix=/usr libdir="%{_libdir}" install
=====================================
src/Makefile
=====================================
--- a/src/Makefile
+++ b/src/Makefile
@@ -37,14 +37,11 @@ cleanall: clean
ifndef TESTDIR
test testclean:
- $(MAKE) TESTDIR=$(CURDIR)/mwtest $@
+ $(MAKE) TESTDIR="$(CURDIR)/mwtest" $@
else
test:
- mkdir -p "$(TESTDIR)"
+ $(MAKE) -C $(SRCROOT) DESTDIR="$(TESTDIR)" install-home
cd "$(TESTDIR)" && mkdir -p mw run/mw log/mw lib/mw
- for d in $(INSTALLFILES); do \
- cp -a ../$$d $(TESTDIR)/mw/ ; \
- done
$(MAKE) libdir="$(TESTDIR)" localstatedir="$(TESTDIR)" all
$(MAKE) -C utils libdir="$(TESTDIR)" localstatedir="$(TESTDIR)" all
=====================================
src/client/Makefile
=====================================
--- a/src/client/Makefile
+++ b/src/client/Makefile
@@ -3,7 +3,6 @@ DEPTH=../../
include ../../Makefile.common
LDLIBS+= -lreadline -ltermcap -lcrypt -lsqlite3 -lcurl -lpthread -lcrypto -ljansson -lz -lm
-LDFLAGS+= -L..
CFLAGS+= -I..
build: mw
=====================================
src/client/js.c
=====================================
--- a/src/client/js.c
+++ b/src/client/js.c
@@ -1127,11 +1127,7 @@ js_error_handler(JSContext __attribute__((unused)) *cx, const char *msg, JSError
int load_jsfile(FILE *f, const char *filename)
{
JSBool success;
-#ifdef JSSCRIPTTYPE
- JSSCRIPTTYPE *script;
-#else
-#error "JSSCRIPTTYPE not defined"
-#endif
+ JSScript *script;
jsval retval;
/* Compile the js file specified */
=====================================
src/server/Makefile
=====================================
--- a/src/server/Makefile
+++ b/src/server/Makefile
@@ -4,13 +4,9 @@ include $(DEPTH)Makefile.common
CFLAGS+= -I..
LDLIBS+= -ljansson -lsqlite3
-LDFLAGS+= -L..
build: mwserv
-### The magic which lets us autogenerate dependencies
-CFLAGS += -MMD
-
mwserv: $(CODE:.c=.o) ../libmw.a $(JSOBJ)
$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
=====================================
src/utils/Makefile
=====================================
--- a/src/utils/Makefile
+++ b/src/utils/Makefile
@@ -2,7 +2,6 @@ SRCROOT = $(CURDIR)/../..
DEPTH=../../
include ../../Makefile.common
-LDFLAGS+= -L..
CFLAGS+= -I.. -Wno-error
all: mwnci listuser fixuser del_user sizes
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/c73d5b1086860d7ab466798e57f7fe06fcd84942
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20160304/a4dbf18c/attachment-0001.html>
More information about the mw-devel
mailing list