Commit c73d5b10 authored by Andrew Price's avatar Andrew Price
Browse files

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
parent 1be3f67d
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -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
+48 −23
Original line number Diff line number Diff line
@@ -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
@@ -30,20 +30,32 @@ 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)
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)

+1 −0
Original line number Diff line number Diff line
#!/usr/bin/make -f
#export DH_VERBOSE=1
export RELEASE_BUILD=1

%:
	dh $@
+1 −1
Original line number Diff line number Diff line
@@ -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
+2 −5
Original line number Diff line number Diff line
@@ -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

Loading