From 06571cbc6c37c3c9cc40059d0da77d6a40b782e7 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Thu, 2 May 2019 20:39:20 +1000 Subject: [PATCH] Choose appropriate build configuration automatically. This could help prevent certain users, who do not read/follow the build instructions, from becoming vexed. --- BUILD.txt | 12 +++++++----- configs/mconfig.Darwin | 16 ++++++++++++++++ configs/mconfig.FreeBSD | 16 ++++++++++++++++ configs/mconfig.Linux | 16 ++++++++++++++++ configs/mconfig.OpenBSD | 16 ++++++++++++++++ mconfig | 40 ---------------------------------------- src/Makefile | 10 ++++++++++ 7 files changed, 81 insertions(+), 45 deletions(-) create mode 100644 configs/mconfig.Darwin create mode 100644 configs/mconfig.FreeBSD create mode 100644 configs/mconfig.Linux create mode 100644 configs/mconfig.OpenBSD delete mode 100644 mconfig diff --git a/BUILD.txt b/BUILD.txt index 08de059..1298dda 100644 --- a/BUILD.txt +++ b/BUILD.txt @@ -4,17 +4,19 @@ Building Dinit Building Dinit should be a straight-forward process. It requires GNU make and a C++11 compiler (GCC version 4.9 and later, or Clang ~5.0 and later, should be fine) -Edit the "mconfig" file to choose appropriate values for the configuration variables defined -within. In particular: +On the directly supported operating systems - Linux, OpenBSD, FreeBSD and Darwin (macOS) - a +suitable build configuration is provided and should be used automatically. For other systems, +or to fine tune or correct the configuration, create and edit the "mconfig" file (start by +copying one for a particular OS from the "configs" directory) to choose appropriate values for +the configuration variables defined within. In particular: CXX : should be set to the name of the C++ compiler (and link driver) CXXOPTS : are options passed to the compiler during compilation (see note for GCC below) LDFLAGS : are any extra flags required for linking; should not normally be needed (FreeBSD requires -lrt). -Suitable defaults for a number of systems are provided. Note that the "eg++" or "clang++" package -must be installed on OpenBSD as the default "g++" compiler is too old. Clang is part of the base -system in recent releases. +Note that the "eg++" or "clang++" package must be installed on OpenBSD as the default "g++" +compiler is too old. Clang is part of the base system in recent releases. Then, change into the "src" directory, and run "make" (or "gmake" if the system make is not GNU make, such as on most BSD systems): diff --git a/configs/mconfig.Darwin b/configs/mconfig.Darwin new file mode 100644 index 0000000..2ab837f --- /dev/null +++ b/configs/mconfig.Darwin @@ -0,0 +1,16 @@ +# Installation path options. + +SBINDIR=/sbin +MANDIR=/usr/share/man +SYSCONTROLSOCKET=/dev/dinitctl + + +# General build options. + +# MacOS: use g++ (which may alias clang++): +# Cannot use -fno-rtti: apparently prevents exception handling from working properly. +CXX=g++ +CXXOPTS=-std=c++11 -Os -Wall -flto +LDFLAGS=-flto +BUILD_SHUTDOWN=no +SANITIZEOPTS=-fsanitize=address,undefined diff --git a/configs/mconfig.FreeBSD b/configs/mconfig.FreeBSD new file mode 100644 index 0000000..36f2496 --- /dev/null +++ b/configs/mconfig.FreeBSD @@ -0,0 +1,16 @@ +# Installation path options. + +SBINDIR=/sbin +MANDIR=/usr/share/man +SYSCONTROLSOCKET=/dev/dinitctl + + +# General build options. + +# FreeBSD: use clang++ by default, supports sanitizers, requires linking with -lrt +# Cannot use -fno-rtti: apparently prevents exception handling from working properly. +CXX=clang++ +CXXOPTS=-std=c++11 -Os -Wall +LDFLAGS=-lrt +BUILD_SHUTDOWN=no +SANITIZEOPTS=-fsanitize=address,undefined diff --git a/configs/mconfig.Linux b/configs/mconfig.Linux new file mode 100644 index 0000000..d693cb0 --- /dev/null +++ b/configs/mconfig.Linux @@ -0,0 +1,16 @@ +# Installation path options. + +SBINDIR=/sbin +MANDIR=/usr/share/man +SYSCONTROLSOCKET=/dev/dinitctl + + +# General build options. + +# Linux (GCC). Note with GCC 5.x/6.x you must use the old ABI, with GCC 7.x you must use +# the new ABI. See BUILD file for more information. +CXX=g++ +CXXOPTS=-D_GLIBCXX_USE_CXX11_ABI=1 -std=c++11 -Os -Wall -fno-rtti -fno-plt -flto +LDFLAGS=-flto +BUILD_SHUTDOWN=yes +SANITIZEOPTS=-fsanitize=address,undefined diff --git a/configs/mconfig.OpenBSD b/configs/mconfig.OpenBSD new file mode 100644 index 0000000..acebd31 --- /dev/null +++ b/configs/mconfig.OpenBSD @@ -0,0 +1,16 @@ +# Installation path options. + +SBINDIR=/sbin +MANDIR=/usr/share/man +SYSCONTROLSOCKET=/dev/dinitctl + + +# General build options. Uncomment the options appropriate for your system. + +# OpenBSD, tested with GCC 4.9.3 / Clang++ 4/5 and gmake: +CXX=clang++ +CXXOPTS=-std=c++11 -Os -Wall -fno-rtti +LDFLAGS= +BUILD_SHUTDOWN=no +SANITIZEOPTS= +# (shutdown command not available for OpenBSD yet). diff --git a/mconfig b/mconfig deleted file mode 100644 index aa39107..0000000 --- a/mconfig +++ /dev/null @@ -1,40 +0,0 @@ -# Installation path options. - -SBINDIR=/sbin -MANDIR=/usr/share/man -SYSCONTROLSOCKET=/dev/dinitctl - - -# General build options. Uncomment the options appropriate for your system. - -# Linux (GCC). Note with GCC 5.x/6.x you must use the old ABI, with GCC 7.x you must use -# the new ABI. See BUILD file for more information. -CXX=g++ -CXXOPTS=-D_GLIBCXX_USE_CXX11_ABI=1 -std=c++11 -Os -Wall -fno-rtti -fno-plt -flto -LDFLAGS=-flto -BUILD_SHUTDOWN=yes -SANITIZEOPTS=-fsanitize=address,undefined - -# OpenBSD, tested with GCC 4.9.3 / Clang++ 4/5 and gmake: -#CXX=clang++ -#CXXOPTS=-std=c++11 -Os -Wall -fno-rtti -#LDFLAGS= -#BUILD_SHUTDOWN=no -#SANITIZEOPTS= -# (shutdown command not available for OpenBSD yet). - -# FreeBSD: use clang++ by default, supports sanitizers, requires linking with -lrt -# Cannot use -fno-rtti: apparently prevents exception handling from working properly. -#CXX=clang++ -#CXXOPTS=-std=c++11 -Os -Wall -#LDFLAGS=-lrt -#BUILD_SHUTDOWN=no -#SANITIZEOPTS=-fsanitize=address,undefined - -# MacOS: use g++ (which may alias clang++): -# Cannot use -fno-rtti: apparently prevents exception handling from working properly. -#CXX=g++ -#CXXOPTS=-std=c++11 -Os -Wall -flto -#LDFLAGS=-flto -#BUILD_SHUTDOWN=no -#SANITIZEOPTS=-fsanitize=address,undefined diff --git a/src/Makefile b/src/Makefile index eeacc71..2242128 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,6 +11,16 @@ objects = $(dinit_objects) dinitctl.o shutdown.o all: dinit dinitctl $(SHUTDOWN) +# Look for a suitable build config file and use it. +../mconfig: + @UNAME=`uname`;\ + if [ -f "../configs/mconfig.$$UNAME" ]; then \ + echo "Found configuration for OS: $$UNAME"; \ + ln -sf "configs/mconfig.$$UNAME" ../mconfig; \ + else \ + echo "No config available. Please create suitable mconfig file."; \ + fi + includes/mconfig.h: mconfig-gen ./mconfig-gen SBINDIR=$(SBINDIR) SYSCONTROLSOCKET=$(SYSCONTROLSOCKET) > includes/mconfig.h -- 2.25.1