Browse Source

Choose appropriate build configuration automatically.

This could help prevent certain users, who do not read/follow the build
instructions, from becoming vexed.
Davin McCall 5 years ago
parent
commit
06571cbc6c
7 changed files with 81 additions and 45 deletions
  1. 7 5
      BUILD.txt
  2. 16 0
      configs/mconfig.Darwin
  3. 16 0
      configs/mconfig.FreeBSD
  4. 16 0
      configs/mconfig.Linux
  5. 16 0
      configs/mconfig.OpenBSD
  6. 0 40
      mconfig
  7. 10 0
      src/Makefile

+ 7 - 5
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):

+ 16 - 0
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

+ 16 - 0
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

+ 16 - 0
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

+ 16 - 0
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).

+ 0 - 40
mconfig

@@ -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

+ 10 - 0
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