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):
--- /dev/null
+# 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
--- /dev/null
+# 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
--- /dev/null
+# 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
--- /dev/null
+# 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).
+++ /dev/null
-# 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
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