summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2023-12-04 16:29:05 +0100
committerMartin Burnicki <martin.burnicki@meinberg.de>2023-12-04 16:29:05 +0100
commitebbffa36fe96289be988a1eadef3fd1597a5b651 (patch)
tree50af078754a300c8494070be18d90ba08998d417
parent82466a8af8a9f3e9238a4e747225131ad5e2a541 (diff)
downloadmbgtools-lx-ebbffa36fe96289be988a1eadef3fd1597a5b651.tar.gz
mbgtools-lx-ebbffa36fe96289be988a1eadef3fd1597a5b651.zip
Better support staged builds
Environment variables useful for staged builds: STAGED_BUILD: if defined, some system checks are skipped, and no root permissions are requested for install, so it's only possible to install to local subdirs that need to be defined, too. INSTALL_MOD_PATH: The base directory to which the kernel driver binary is installed. DESTDIR: The base directory to which the user space stuff is installed. prefix: Prefix for the 'bin' directory, e.g. '/usr' instead of '/usr/local'. DONT_BUILD_USERSPACE: If defined, only build/install the kernel driver. DONT_BUILD_DRIVER: If defined, only built/install the user space stuff. Former makefile variable 'CALLED_FROM_SPEC' is now called 'STAGED_BUILD', but a 'CALLED_FROM_SPEC' alias is provided for backward compatibility. Move udev stuff from the 'mbgclock' subdir to a new 'udev' subdirectory. Clean up makefiles and remove obsolete targets. Update .editorconfig with specs for makefiles.
-rw-r--r--.editorconfig25
-rw-r--r--Makefile313
-rw-r--r--libmbg/Makefile6
-rw-r--r--mbgclock/Makefile113
-rw-r--r--udev/55-mbgclock.rules (renamed from mbgclock/55-mbgclock.rules)0
-rw-r--r--udev/55-mbgclock.rules.before-udev-055 (renamed from mbgclock/55-mbgclock.rules.before-udev-055)0
-rw-r--r--udev/Makefile115
7 files changed, 338 insertions, 234 deletions
diff --git a/.editorconfig b/.editorconfig
index 4f7db73..666e706 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,15 +1,28 @@
-# Editor configuration file
-# https://EditorConfig.org
+# Editor configuration, see https://editorconfig.org
-# top-most EditorConfig file
+# This is the top-most editorconfig file.
root = true
-# General stype
+
+# General settings.
[*]
trim_trailing_whitespace = true
insert_final_newline = true
-# Tab indentation
-[*.{c,cpp,h}]
+
+# Source code.
+[*.{c,cpp,h,hpp}]
indent_style = space
indent_size = 2
+
+
+# Trailing spaces matter for markdown files
+[*.md]
+trim_trailing_whitespace = false
+max_line_length = off
+
+
+# Tabs matter for makefiles and .gitmodules
+[{makefile*,Makefile*,*.mk,*.mak,*.makefile,*.Makefile,GNUmakefile,BSDmakefile,Makevars*,*.gitmodules}]
+indent_style = tab
+indent_size = 2
diff --git a/Makefile b/Makefile
index 541b52d..cda3c37 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,14 @@
#########################################################################
#
-# $Id: Makefile 1.39 2022/09/07 16:55:49 martin.burnicki REL_M $
+# $Id: Makefile 1.40 2023/12/04 14:49:57 martin.burnicki REL_M $
#
# Makefile for mbgtools-lx which recurses into the subdirectories.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.40 2023/12/04 14:49:57 martin.burnicki
+# Better support for staged builds, and cleanup.
# Revision 1.39 2022/09/07 16:55:49 martin.burnicki
# Updated name of sub-makefile to be included.
# Revision 1.38 2022/07/25 16:42:04 martin.burnicki
@@ -173,10 +175,27 @@ else
endif
+# STAGED_BUILD means that binaries are build locally
+# and later installed to local directories rather than
+# system directories.
+# Formerly we used the symbol CALLED_FROM_SPEC for this
+# purpose, so for now we keep a backward-compatible alias.
+ifndef STAGED_BUILD
+ ifdef CALLED_FROM_SPEC
+ STAGED_BUILD = $(CALLED_FROM_SPEC)
+ endif
+endif
+
+
# A macro that tries to find a specific program anywhere
# on the program search path. Returns the path to the program,
# if it can be found, else an empty string.
-chk_which_exec = $(shell which $(1) 2>/dev/null || whereis -b $(1) | awk ' { print $$2 }' )
+ifndef STAGED_BUILD
+ chk_which_exec = $(shell which $(1) 2>/dev/null || whereis -b $(1) | awk ' { print $$2 }' )
+else
+ chk_which_exec = $(shell echo $(1) )
+endif
+
# A macro that tests if a specific directory exists.
# Returns the path if it exists, else an empty string.
@@ -251,7 +270,7 @@ include $(TOPDIR)/makefile-supp-syn1588.mk
# Macros useful to run individual commands as root:
-ifdef CALLED_FROM_SPEC
+ifdef STAGED_BUILD
# Fake running as root.
UID = 0
else
@@ -259,7 +278,7 @@ else
UID = $(shell id -u)
SUDO ?= $(call chk_which_exec,"sudo")
SU ?= $(call chk_which_exec,"su")
-endif # CALLED_FROM_SPEC
+endif # STAGED_BUILD
$(call debug_msg,$(INFO) UID: $(UID))
$(call debug_msg,$(INFO) SUDO: $(SUDO))
@@ -295,24 +314,38 @@ find_libdir = $(shell \
)
-prefix ?= /usr/local
-bindir ?= $(prefix)/bin
-sbindir ?= $(prefix)/sbin
+# A destination dir for staged installation, as
+# suggested by GNU conventions.
+# Prepended to the installations paths specified below,
+# but empty by default.
+DESTDIR ?=
-sysconfdir ?= /etc
+# Default installation paths according to GNU conventions.
+prefix ?= /usr/local
+exec_prefix ?= $(prefix)
+bindir ?= $(exec_prefix)/bin
+sbindir ?= $(exec_prefix)/sbin
includedir ?= $(prefix)/include
-libdir ?= $(call find_libdir,$(prefix))
+# The final part of the libdir path can be lib, lib32, or lib64,
+# so we call a function to determine the most appropriate.
+libdir ?= $(call find_libdir,$(exec_prefix))
+# The next one is non-standard, but most appropriate.
+sysconfdir ?= /etc
+
$(call debug_msg,$(INFO) prefix: $(prefix))
$(call debug_msg,$(INFO) libdir: $(libdir) MACHINE_TYPE: $(MACHINE_TYPE))
+# A macro that combines all the installation paths specified above.
+# Used to pass the settings to a sub-make.
INSTALL_PATHS = DESTDIR=$(DESTDIR)
INSTALL_PATHS += prefix=$(prefix)
+INSTALL_PATHS += exec_prefix=$(exec_prefix)
INSTALL_PATHS += bindir=$(bindir)
INSTALL_PATHS += sbindir=$(sbindir)
-INSTALL_PATHS += includedir=$(includedir)
INSTALL_PATHS += libdir=$(libdir)
+INSTALL_PATHS += includedir=$(includedir)
INSTALL_PATHS += sysconfdir=$(sysconfdir)
@@ -327,9 +360,9 @@ SO_SUBDIRS ?= $(foreach dir,$(SO_BASENAMES), libmbg_so/mbg$(dir) )
$(call debug_msg,$(INFO) SO_SUBDIRS: $(SO_SUBDIRS))
# Definitions for the static library used when building.
-MBGTOOLS_LIB_BASENAME = mbg
-MBGTOOLS_LIB_DIR = libmbg
-MBGTOOLS_LIB_FILE = lib$(MBGTOOLS_LIB_BASENAME).a
+MBGTOOLS_STATIC_LIB_DIR = libmbg
+MBGTOOLS_STATIC_LIB_BASENAME = mbg
+MBGTOOLS_STATIC_LIB_FILE = lib$(MBGTOOLS_STATIC_LIB_BASENAME).a
@@ -350,6 +383,17 @@ $(call debug_msg,$(INFO) reading top level part)
MAKECMDGOALS ?= $(.DEFAULT_GOAL)
+ifdef DONT_BUILD_LIBS
+ ifdef DONT_BUILD_TOOLS
+ DONT_BUILD_USERSPACE ?= 1
+ endif
+endif
+
+ifdef DONT_BUILD_USERSPACE
+ DONT_BUILD_LIBS ?= 1
+ DONT_BUILD_TOOLS ?= 1
+endif
+
# A routine that can be called to check if a Makefile exists
# in a specific subdirectory. It returns the subdirectory name
@@ -359,12 +403,22 @@ chk_subdir = $(shell test -f $(strip $(1))/Makefile && echo "$(1)" )
# List of subdirectories that are only built/cleaned,
# but not installed/uninstalled.
-SUBDIRS_BUILD_ONLY ?= $(MBGTOOLS_LIB_DIR)
+ifndef DONT_BUILD_USERSPACE
+ SUBDIRS_BUILD_ONLY ?= $(MBGTOOLS_STATIC_LIB_DIR)
+endif
# List of subdirectories that don't need to be built/cleaned,
# but installed/uninstalled.
-SUBDIRS_INST_ONLY ?= $(call chk_subdir, "libmbg_so/devel" )
+ifndef DONT_BUILD_USERSPACE
+ SUBDIRS_INST_ONLY ?= $(call chk_subdir, "libmbg_so/devel" )
+endif
+
+# Udev dirs are special and don't need to be built/cleaned,
+# but installed/uninstalled.
+ifndef DONT_BUILD_USERSPACE
+ SUBDIRS_UDEV += $(call chk_subdir, "udev" )
+endif
# List of subdirectories that are built/cleaned
@@ -425,7 +479,6 @@ endif # SUBDIRS_COMMON
TARGETS_BUILD := all clean distclean
TARGETS_INST := install uninstall
-
# Determine the subdirectories to be recursed into
# depending on the current goal.
ifneq ($(filter $(MAKECMDGOALS),$(TARGETS_BUILD)),)
@@ -433,20 +486,24 @@ ifneq ($(filter $(MAKECMDGOALS),$(TARGETS_BUILD)),)
endif
ifneq ($(filter $(MAKECMDGOALS),$(TARGETS_INST)),)
- SUBDIR_TARGETS += $(SUBDIRS_INST_ONLY) $(SUBDIRS_COMMON)
+ SUBDIR_TARGETS += $(SUBDIRS_INST_ONLY) $(SUBDIRS_COMMON) $(SUBDIRS_UDEV)
endif
-# For some targets we may also want to execute some additional
-# commands after the main targets have been made.
-ifeq ($(MAKECMDGOALS),all)
- PRE_TARGETS = pre_build_info
- POST_TARGETS = post_build_info
-endif
+ifndef STAGED_BUILD
-ifeq ($(MAKECMDGOALS),install)
- POST_TARGETS = post_install_info
-endif
+ # For some targets we may also want to execute some additional
+ # commands after the main targets have been made.
+ ifeq ($(MAKECMDGOALS),all)
+ PRE_TARGETS = pre_build_info
+ POST_TARGETS = post_build_info
+ endif
+
+ ifeq ($(MAKECMDGOALS),install)
+ POST_TARGETS = post_install_info
+ endif
+
+endif # STAGED_BUILD
# If the current target is uninstall, we may also want to run
@@ -469,17 +526,15 @@ $(TARGETS_BUILD) $(TARGETS_INST): $(PRE_TARGETS) $(SUBDIR_TARGETS) $(POST_TARGET
.PHONY: $(SUBDIR_TARGETS)
$(SUBDIR_TARGETS):
- ifdef SEPARATOR_1
- @echo "$(SEPARATOR_1)"
- endif
+ ifdef SEPARATOR_1
+ @echo "$(SEPARATOR_1)"
+ endif
@echo "Making $(MAKECMDGOALS) in $@"
$(Q)$(MAKE) $(QM) -C $@ $(INSTALL_PATHS) $(MAKECMDGOALS)
-.PHONY: dev dev-nodes dev-clean suse_symvers probe ins rm test reload check \
- refclocks kernel_config
-dev dev-nodes dev-clean probe ins rm test reload check \
- refclocks kernel_config:
+.PHONY: probe ins rm test reload
+probe ins rm test reload:
$(Q)$(MAKE) $(QM) -C mbgclock $@
@@ -589,11 +644,11 @@ LDFLAGS += $(foreach dir,$(SO_SUBDIRS),-L$(BASEDIR)/$(dir) )
# The path to the static library we use to
# simplify the build procedure.
-MBGTOOLS_LIB_PATH = $(BASEDIR)/$(MBGTOOLS_LIB_DIR)
-MBGTOOLS_LIB_FILE_PATH = $(MBGTOOLS_LIB_PATH)/$(MBGTOOLS_LIB_FILE)
+MBGTOOLS_STATIC_LIB_PATH = $(BASEDIR)/$(MBGTOOLS_STATIC_LIB_DIR)
+MBGTOOLS_STATIC_LIB_FILE_PATH = $(MBGTOOLS_STATIC_LIB_PATH)/$(MBGTOOLS_STATIC_LIB_FILE)
-ifdef MBGTOOLS_LIB_TARGET
- CURR_TARGET = $(MBGTOOLS_LIB_TARGET)
+ifdef MBGTOOLS_STATIC_LIB_TARGET
+ CURR_TARGET = $(MBGTOOLS_STATIC_LIB_TARGET)
USE_STATIC_LIB = 0
endif
@@ -642,10 +697,10 @@ endif # MBGTOOLS_TARGET
ifneq ($(USE_STATIC_LIB),0)
- LDFLAGS += -L$(MBGTOOLS_LIB_PATH)
- LDLIBS += -l$(MBGTOOLS_LIB_BASENAME)
+ LDFLAGS += -L$(MBGTOOLS_STATIC_LIB_PATH)
+ LDLIBS += -l$(MBGTOOLS_STATIC_LIB_BASENAME)
- $(CURR_TARGET): $(MBGTOOLS_LIB_FILE_PATH)
+ $(CURR_TARGET): $(MBGTOOLS_STATIC_LIB_FILE_PATH)
endif
@@ -654,7 +709,7 @@ CPPFLAGS += $(CPPFLAGS_SYN1588)
LDLIBS += $(LDLIBS_SYN1588)
-$(call debug_msg,$(INFO) MBGTOOLS_LIB_FILE_PATH: $(MBGTOOLS_LIB_FILE_PATH))
+$(call debug_msg,$(INFO) MBGTOOLS_STATIC_LIB_FILE_PATH: $(MBGTOOLS_STATIC_LIB_FILE_PATH))
$(call debug_msg,$(INFO) USE_STATIC_LIB: $(USE_STATIC_LIB))
$(call debug_msg,$(INFO) CURR_TARGET: $(CURR_TARGET))
@@ -724,8 +779,8 @@ else
endif
-$(MBGTOOLS_LIB_FILE_PATH):
- $(MAKE) -C $(MBGTOOLS_LIB_PATH) $(MBGTOOLS_LIB_FILE)
+$(MBGTOOLS_STATIC_LIB_FILE_PATH):
+ $(MAKE) -C $(MBGTOOLS_STATIC_LIB_PATH) $(MBGTOOLS_STATIC_LIB_FILE)
# Options for the archiver to build a static library.
ARFLAGS := rcs
@@ -741,37 +796,37 @@ $(call debug_msg,$(INFO) MAKECMDGOALS: $(MAKECMDGOALS))
$(CURR_TARGET): $(OBJS)
-ifdef MBGTOOLS_LIB_TARGET
+ifdef MBGTOOLS_STATIC_LIB_TARGET
$(vecho) " $(AR) $@"
$(Q)$(AR) $(ARFLAGS) $@ $(OBJS)
else
$(vecho) " Linking $@"
$(Q)$(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS)
ifdef SO_TARGET_LIBNAME
- ln -sf $(CURR_TARGET) $(SO_TARGET_LIBNAME)
+ ln -sf $(CURR_TARGET) $(SO_TARGET_LIBNAME)
endif
-endif # MBGTOOLS_LIB_TARGET
+endif # MBGTOOLS_STATIC_LIB_TARGET
.PHONY: install
install:
ifneq ($(INST_DIR),)
ifneq ($(UID),0)
- $(call make_as_root, $@)
+ $(call make_as_root, $@)
else
ifdef INCLUDE_FILES # Install header files.
- for incfile in $(INCLUDE_FILES); do \
- install -m 644 -D $(BASEDIR)/mbglib/common/$$incfile $(INST_DIR)/$$incfile; \
- done;
- for basename in $(SO_BASENAMES); do \
- (cd $(DESTDIR)$(libdir); ln -sf libmbg$$basename.so.$(SO_MAJOR_VERSION) libmbg$$basename.so;) \
- done;
+ for incfile in $(INCLUDE_FILES); do \
+ install -m 644 -D $(BASEDIR)/mbglib/common/$$incfile $(INST_DIR)/$$incfile; \
+ done;
+ for basename in $(SO_BASENAMES); do \
+ (mkdir -p $(DESTDIR)$(libdir); cd $(DESTDIR)$(libdir); ln -sf libmbg$$basename.so.$(SO_MAJOR_VERSION) libmbg$$basename.so;) \
+ done;
else # Usual installation.
- install -s -m 755 -D $(CURR_TARGET) $(INST_DIR)/$(CURR_TARGET)
+ install -s -m 755 -D $(CURR_TARGET) $(INST_DIR)/$(CURR_TARGET)
- ifndef CALLED_FROM_SPEC
+ ifndef STAGED_BUILD
ifdef INST_TO_LIB
- $(LDCONFIG) $(INST_DIR)
+ $(LDCONFIG) $(INST_DIR)
endif
endif
endif
@@ -783,20 +838,20 @@ endif
uninstall:
ifneq ($(INST_DIR),)
ifneq ($(UID),0)
- $(call make_as_root, $@)
+ $(call make_as_root, $@)
else
ifdef INCLUDE_FILES # Remove header files.
- rm -rf $(INST_DIR)
- ifndef CALLED_FROM_SPEC # Remove symbolic links.
- for basename in $(SO_BASENAMES); do \
- rm -f $(libdir)/libmbg$$basename.so; \
- done;
+ rm -rf $(INST_DIR)
+ ifndef STAGED_BUILD # Remove symbolic links.
+ for basename in $(SO_BASENAMES); do \
+ rm -f $(libdir)/libmbg$$basename.so; \
+ done;
endif
else
rm -f $(INST_DIR)/$(CURR_TARGET)
- ifndef CALLED_FROM_SPEC
+ ifndef STAGED_BUILD
ifdef INST_TO_LIB
- $(LDCONFIG) $(INST_DIR)
+ $(LDCONFIG) $(INST_DIR)
endif
endif
endif
@@ -1013,24 +1068,26 @@ else
@echo $(KERNEL_BUILD_MSG) \"$(MAKECMDGOALS)\"
$(Q)$(MAKE) $(QMK) -C $(BUILD_DIR) $(MBGCLOCK_DIR_ARG) V=$(V) $(MAKECMDGOALS)
@echo $(KERNEL_BUILD_FINISHED_MSG) \"$(MAKECMDGOALS)\"
- ifndef CALLED_FROM_SPEC
- @echo
- @echo Explicitly running \"$(DEPMOD) $(DEPMOD_ARGS)\"
- $(DEPMOD) $(DEPMOD_ARGS)
+ ifndef STAGED_BUILD
+ @echo
+ @echo Explicitly running \"$(DEPMOD) $(DEPMOD_ARGS)\"
+ $(DEPMOD) $(DEPMOD_ARGS)
+ @echo
endif
endif
.PHONY: install
-install: install_module dev
+install: install_module
+
.PHONY: uninstall
uninstall:
-ifndef CALLED_FROM_SPEC
+ifndef STAGED_BUILD
ifneq ($(UID),0)
- $(Q)$(call make_as_root, $@)
+ $(Q)$(call make_as_root, $@)
else
- $(Q)rm -f /lib/modules/`uname -r`/extra/$(MBGTOOLS_TARGET)
+ $(Q)rm -f /lib/modules/`uname -r`/extra/$(MBGTOOLS_TARGET)
endif
endif
@@ -1057,12 +1114,12 @@ clean:
@echo $(KERNEL_BUILD_MSG) \"$@\"
$(Q)$(MAKE) $(QM) -C $(BUILD_DIR) $(MBGCLOCK_DIR_ARG) BASEDIR=$(BASEDIR) V=$(V) clean
@echo $(KERNEL_BUILD_FINISHED_MSG) \"clean\"
-ifneq ($(CLEAN_FILES),)
- $(Q)rm -f $(CLEAN_FILES)
-endif
-ifneq ($(CLEAN_DIRS),)
- $(Q)rm -rf $(CLEAN_DIRS)
-endif
+ ifneq ($(CLEAN_FILES),)
+ $(Q)rm -f $(CLEAN_FILES)
+ endif
+ ifneq ($(CLEAN_DIRS),)
+ $(Q)rm -rf $(CLEAN_DIRS)
+ endif
else # !$(KERNELRELEASE)
@@ -1097,79 +1154,104 @@ GETENFORCE = getenforce
GETENFORCE_BIN = $(call chk_which_exec, $(GETENFORCE))
ifneq ($(GETENFORCE_BIN),)
- INSTALL_OPTS += -Z
+ # Install option to set the SELinux security context to default.
+ INST_OPT_SELINUX = -Z
+endif
+
+ifndef STAGED_BUILD
+ # Install option to set root ownership.
+ INST_OPT_CHOWN_ROOT = -o root
endif
CONF_FILE_SYSTEMD = $(MBGTOOLS_TARGET).service
SRC_DIR_SYSTEMD = $(BASEDIR)/rc-scripts/systemd/
-DST_DIR_SYSTEMD = /etc/systemd/system/
-DST_DIR_SYSTEMD_EXISTS = $(call chk_exist_dir, $(DST_DIR_SYSTEMD))
-
+DST_DIR_SYSTEMD ?= $(DESTDIR)/etc/systemd/system/
+ifndef STAGED_BUILD
+ DST_DIR_SYSTEMD_EXISTS = $(call chk_exist_dir, $(DST_DIR_SYSTEMD))
+else
+ DST_DIR_SYSTEMD_EXISTS = $(DST_DIR_SYSTEMD)
+endif
INITCTL = initctl
INITCTL_BIN = $(call chk_which_exec, $(INITCTL))
CONF_FILE_UPSTART = $(MBGTOOLS_TARGET).conf
SRC_DIR_UPSTART = $(BASEDIR)/rc-scripts/upstart/
-DST_DIR_UPSTART = /etc/init/
-DST_DIR_UPSTART_EXISTS = $(call chk_exist_dir, $(DST_DIR_UPSTART))
-
+DST_DIR_UPSTART ?= $(DESTDIR)/etc/init/
+ifndef STAGED_BUILD
+ DST_DIR_UPSTART_EXISTS = $(call chk_exist_dir, $(DST_DIR_UPSTART))
+else
+ # Nothing to do here since by default we don't
+ # support upstart in staged builds.
+ # If required, DST_DIR_UPSTART_EXISTS can be
+ # specified on the command line.
+endif
$(MBGTOOLS_TARGET)_install:
ifneq ($(UID),0)
- $(call make_as_root, $@)
+ $(call make_as_root, $@)
else
ifneq ($(DST_DIR_SYSTEMD_EXISTS),)
- @echo "Installing $(CONF_FILE_SYSTEMD) to systemd configuration directory $(DST_DIR_SYSTEMD)"
- install -o root -m 644 $(INSTALL_OPTS) -t $(DST_DIR_SYSTEMD) $(SRC_DIR_SYSTEMD)$(CONF_FILE_SYSTEMD)
- sed -i -e 's?@prefix@?$(prefix)?g' $(DST_DIR_SYSTEMD)$(CONF_FILE_SYSTEMD)
+ @echo "Installing $(CONF_FILE_SYSTEMD) to systemd configuration directory $(DST_DIR_SYSTEMD)"
+ ifdef STAGED_BUILD
+ mkdir -p $(DST_DIR_SYSTEMD)
+ endif
+ install $(INST_OPT_CHOWN_ROOT) $(INST_OPT_SELINUX) -m 644 -t $(DST_DIR_SYSTEMD) $(SRC_DIR_SYSTEMD)$(CONF_FILE_SYSTEMD)
+ sed -i -e 's?@prefix@?$(prefix)?g' $(DST_DIR_SYSTEMD)$(CONF_FILE_SYSTEMD)
ifneq ($(SYSTEMCTL_BIN),)
- @echo "Registering $(MBGTOOLS_TARGET) with systemd"
- $(SYSTEMCTL_BIN) daemon-reload
- $(SYSTEMCTL_BIN) enable $(CONF_FILE_SYSTEMD)
- -$(SYSTEMCTL_BIN) stop $(CONF_FILE_SYSTEMD)
- -$(SYSTEMCTL_BIN) start $(CONF_FILE_SYSTEMD)
- $(SYSTEMCTL_BIN) -l status $(CONF_FILE_SYSTEMD)
+ ifndef STAGED_BUILD
+ @echo "Registering $(MBGTOOLS_TARGET) with systemd"
+ $(SYSTEMCTL_BIN) daemon-reload
+ $(SYSTEMCTL_BIN) enable $(CONF_FILE_SYSTEMD)
+ -$(SYSTEMCTL_BIN) stop $(CONF_FILE_SYSTEMD)
+ -$(SYSTEMCTL_BIN) start $(CONF_FILE_SYSTEMD)
+ $(SYSTEMCTL_BIN) -l status $(CONF_FILE_SYSTEMD)
+ endif # STAGED_BUILD
else
- @echo "Command $(SYSTEMCTL) not found, unable to register $(MBGTOOLS_TARGET) with systemd"
+ @echo "Command $(SYSTEMCTL) not found, unable to register $(MBGTOOLS_TARGET) with systemd"
endif
else
- @echo "systemd configuration directory $(DST_DIR_SYSTEMD) not found, skipping registering $(MBGTOOLS_TARGET) for systemd"
+ @echo "systemd configuration directory $(DST_DIR_SYSTEMD) not found, skipping registering $(MBGTOOLS_TARGET) for systemd"
endif
ifneq ($(DST_DIR_UPSTART_EXISTS),)
- @echo "Installing $(CONF_FILE_UPSTART) to upstart configuration directory $(DST_DIR_UPSTART)"
- install -o root -m 644 -t $(DST_DIR_UPSTART) $(SRC_DIR_UPSTART)$(CONF_FILE_UPSTART)
+ @echo "Installing $(CONF_FILE_UPSTART) to upstart configuration directory $(DST_DIR_UPSTART)"
+ ifdef STAGED_BUILD
+ mkdir -p $(DST_DIR_UPSTART)
+ endif
+ install $(INST_OPT_CHOWN_ROOT) -m 644 -t $(DST_DIR_UPSTART) $(SRC_DIR_UPSTART)$(CONF_FILE_UPSTART)
ifneq ($(INITCTL_BIN),)
- @echo "Registering $(MBGTOOLS_TARGET) with upstart init system"
- $(INITCTL_BIN) reload-configuration
- $(INITCTL_BIN) status $(MBGTOOLS_TARGET) | grep "running" || $(INITCTL_BIN) start $(MBGTOOLS_TARGET)
+ @echo "Registering $(MBGTOOLS_TARGET) with upstart init system"
+ $(INITCTL_BIN) reload-configuration
+ $(INITCTL_BIN) status $(MBGTOOLS_TARGET) | grep "running" || $(INITCTL_BIN) start $(MBGTOOLS_TARGET)
else
- @echo "Command $(INITCTL) not found, unable to register $(MBGTOOLS_TARGET) with upstart"
+ @echo "Command $(INITCTL) not found, unable to register $(MBGTOOLS_TARGET) with upstart"
endif
else
- @echo "upstart configuration directory $(DST_DIR_UPSTART) not found, skipping registering $(MBGTOOLS_TARGET) for upstart"
+ ifndef STAGED_BUILD
+ @echo "upstart configuration directory $(DST_DIR_UPSTART) not found, skipping registering $(MBGTOOLS_TARGET) for upstart"
+ endif
endif
endif
$(MBGTOOLS_TARGET)_uninstall:
ifneq ($(UID),0)
- $(call make_as_root, $@)
+ $(call make_as_root, $@)
else
ifneq ($(SYSTEMCTL_BIN),)
- @echo "Unregistering $(MBGTOOLS_TARGET) from systemd"
- -$(SYSTEMCTL_BIN) stop $(CONF_FILE_SYSTEMD)
- -$(SYSTEMCTL_BIN) disable $(CONF_FILE_SYSTEMD)
- -$(SYSTEMCTL_BIN) daemon-reload
+ @echo "Unregistering $(MBGTOOLS_TARGET) from systemd"
+ -$(SYSTEMCTL_BIN) stop $(CONF_FILE_SYSTEMD)
+ -$(SYSTEMCTL_BIN) disable $(CONF_FILE_SYSTEMD)
+ -$(SYSTEMCTL_BIN) daemon-reload
endif
- rm -f $(DST_DIR_SYSTEMD)$(CONF_FILE_SYSTEMD)
+ rm -f $(DST_DIR_SYSTEMD)$(CONF_FILE_SYSTEMD)
ifneq ($(INITCTL_BIN),)
- @echo "Unregistering $(MBGTOOLS_TARGET) from upstart init system"
- -$(INITCTL_BIN) stop $(MBGTOOLS_TARGET)
+ @echo "Unregistering $(MBGTOOLS_TARGET) from upstart init system"
+ -$(INITCTL_BIN) stop $(MBGTOOLS_TARGET)
endif
- rm -f $(DST_DIR_UPSTART)$(CONF_FILE_UPSTART)
+ rm -f $(DST_DIR_UPSTART)$(CONF_FILE_UPSTART)
ifneq ($(INITCTL_BIN),)
- $(INITCTL_BIN) reload-configuration
+ $(INITCTL_BIN) reload-configuration
endif
endif
@@ -1205,11 +1287,10 @@ endif
pre_build_info:
$(call show_syn1588_info,Building,$(build_info),$(syn1588_info))
-
.PHONY: post_build_info
post_build_info:
ifdef SEPARATOR_2
- @echo "$(SEPARATOR_2)"
+ @echo "$(SEPARATOR_2)"
endif
$(call show_syn1588_info,Built,$(build_info),$(syn1588_info))
ifeq ($(SUPP_SYN1588),0)
diff --git a/libmbg/Makefile b/libmbg/Makefile
index b5e0a85..8a0e572 100644
--- a/libmbg/Makefile
+++ b/libmbg/Makefile
@@ -1,13 +1,15 @@
#########################################################################
#
-# $Id: Makefile 1.10 2022/08/02 09:12:36 martin.burnicki REL_M $
+# $Id: Makefile 1.11 2023/12/04 14:49:51 martin.burnicki REL_M $
#
# Description:
# Makefile for libmbg.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.11 2023/12/04 14:49:51 martin.burnicki
+# Better support for staged builds, and cleanup.
# Revision 1.10 2022/08/02 09:12:36 martin.burnicki
# Re-ordered list of object files.
# Revision 1.9 2022/06/30 08:42:32 martin.burnicki
@@ -33,7 +35,7 @@
#
#########################################################################
-MBGTOOLS_LIB_TARGET=$(MBGTOOLS_LIB_FILE)
+MBGTOOLS_STATIC_LIB_TARGET=$(MBGTOOLS_STATIC_LIB_FILE)
OBJS += cfg_hlp.o
OBJS += cmp_time_util.o
diff --git a/mbgclock/Makefile b/mbgclock/Makefile
index 07c5184..5513d79 100644
--- a/mbgclock/Makefile
+++ b/mbgclock/Makefile
@@ -1,13 +1,15 @@
#########################################################################
#
-# $Id: Makefile 1.26 2021/03/24 10:04:57 martin REL_M $
+# $Id: Makefile 1.27 2023/12/04 14:49:54 martin.burnicki REL_M $
#
# Description:
# Makefile for mbgclock driver for Meinberg clock devices on Linux.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.27 2023/12/04 14:49:54 martin.burnicki
+# Better support for staged builds, and cleanup.
# Revision 1.26 2021/03/24 10:04:57 martin
# Made the 'make install' messages more readable.
# Revision 1.25 2021/03/21 17:36:19 martin
@@ -229,50 +231,6 @@ endif
include $(BASEDIR)/Makefile
-
-ifndef MINORS
- MINORS = 0 1 2 3
-endif
-
-# Name template for old device nodes that shall be removed when cleaning up
-MBG_DEVS_TO_CLEAN = mbgclock mbgclk mbgntp
-
-# For 2.6.x and newer kernels the devices are implemented as character devices
-# using their own dynamic major number, and minor numbers starting at 0.
-# The device nodes are automatically created by udev, where the rules are
-# located in a rules.d directory, to which our rules file has to be copied.
-# Udev versions before 055 used a different syntax than later versions, so
-# we provide 2 different files with either syntax and try to figure out
-# during installation which file to use.
-
-# Try to find udev version using the udevadm tool:
-UDEVADM ?= $(call chk_which_exec, "udevadm" )
-ifneq ($(UDEVADM),)
- UDEV_VER ?= $(shell $(UDEVADM) --version | awk '{print $$1;}' )
-endif
-
-# If the version could not be determined there may be an udev
-# version installed which does not yet provide the udevadm tool.
-# In this case try to get the udev version from udevinfo:
-UDEV_VER ?= $(shell udevinfo -V | awk '{print $$3}' | sed -e 's/[^0-9]//g' )
-
-UDEV_VER_055 = 055
-UDEV_RULES_D = $(DESTDIR)$(sysconfdir)/udev/rules.d
-UDEV_RULES_MBGCLOCK = 55-mbgclock.rules
-UDEV_RULES_MBGCLOCK_BEFORE_055 = $(UDEV_RULES_MBGCLOCK).before-udev-$(UDEV_VER_055)
-
-UDEV_RULES_TO_INSTALL := $(shell \
- if [ $(UDEV_VER) -lt $(UDEV_VER_055) ]; then \
- echo "$(UDEV_RULES_MBGCLOCK_BEFORE_055)"; \
- else \
- echo "$(UDEV_RULES_MBGCLOCK)"; \
- fi; )
-
-ifndef CALLED_FROM_SPEC
- INTERACTIVE_COPYING = -i
-endif
-
-
.PHONY: ins
ins: all
ifneq ($(UID),0)
@@ -316,68 +274,3 @@ reload: rm probe
.PHONY: cleanreload
cleanreload: clean all install rm probe
-
-.PHONY: dev-clean
-dev-clean:
-ifneq ($(UID),0)
- $(call make_as_root, $@)
-else
- @for dev in $(MBG_DEVS_TO_CLEAN); do rm -f /dev/$$dev*; done
- @echo "Existing device nodes have been removed."
- @echo ""
-endif
-
-
-.PHONY: dev-nodes
-dev-nodes:
-ifneq ($(UID),0)
- $(call make_as_root, $@)
-else
- ifneq ($(MAJOR),)
- for minor in $(MINORS); do mknod -m 0644 /dev/$(MODULE)$$minor c $(MAJOR) $$minor; done
- ls -l /dev/$(MODULE)*
- else
- @echo "Unable to create device nodes:"
- @echo "udev rules dir not found, and device major number not specified"
- endif
-endif
-
-
-.PHONY: dev
-dev:
-ifneq ($(UID),0)
- $(call make_as_root, $@)
-else
- ifneq ($(CHRDEV),0)
- ifdef CALLED_FROM_SPEC
- mkdir -p $(UDEV_RULES_D)
- endif
- @echo
- @if test -d $(UDEV_RULES_D); then \
- if test -f $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); then \
- if diff -Nq $(UDEV_RULES_TO_INSTALL) $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); then \
- echo "Udev rules file $(UDEV_RULES_MBGCLOCK) in $(UDEV_RULES_D)/ is unchanged."; \
- else \
- cp -v $(INTERACTIVE_COPYING) $(UDEV_RULES_TO_INSTALL) $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); \
- chmod 644 $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); \
- echo \"\"; \
- fi \
- else \
- echo "Copying new udev rules file $(UDEV_RULES_TO_INSTALL) to $(UDEV_RULES_D)/."; \
- cp $(INTERACTIVE_COPYING) $(UDEV_RULES_TO_INSTALL) $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); \
- chmod 644 $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); \
- fi \
- else \
- echo "WARNING:"; \
- echo " No udev rules directory found!"; \
- echo ""; \
- echo " If you want the device nodes to be automatically created by udev,"; \
- echo " you manually have to add appropriate udev rules."; \
- echo ""; \
- echo " See the README file from the driver package for details."; \
- echo ""; \
- fi
- else
- make dev-nodes
- endif
-endif
diff --git a/mbgclock/55-mbgclock.rules b/udev/55-mbgclock.rules
index ee7bcd9..ee7bcd9 100644
--- a/mbgclock/55-mbgclock.rules
+++ b/udev/55-mbgclock.rules
diff --git a/mbgclock/55-mbgclock.rules.before-udev-055 b/udev/55-mbgclock.rules.before-udev-055
index b69387d..b69387d 100644
--- a/mbgclock/55-mbgclock.rules.before-udev-055
+++ b/udev/55-mbgclock.rules.before-udev-055
diff --git a/udev/Makefile b/udev/Makefile
new file mode 100644
index 0000000..e950675
--- /dev/null
+++ b/udev/Makefile
@@ -0,0 +1,115 @@
+
+#########################################################################
+#
+# Makefile for the udev rules shipped with mbgtools-lx.
+#
+#########################################################################
+
+BASEDIR := ..
+include $(BASEDIR)/Makefile
+
+
+# For 2.6.x and newer kernels, the devices are implemented as character devices
+# using their own dynamic major number, and minor numbers starting at 0.
+# The device nodes are automatically created by udev, where the rules are
+# located in a rules.d directory, to which our rules file has to be copied.
+# Udev versions before 055 used a different syntax than later versions, so
+# we provide 2 different files with either syntax and try to figure out
+# during installation which file to use.
+# Very old systems may not provide a rules.d directory. The udev rules of
+# such systems need to be updated manually.
+
+# Try to find udev version using the udevadm tool:
+UDEVADM ?= $(call chk_which_exec, "udevadm" )
+ifneq ($(UDEVADM),)
+ UDEV_VER ?= $(shell $(UDEVADM) --version | awk '{print $$1;}' )
+endif
+
+# If the version could not be determined there may be an udev
+# version installed which does not yet provide the udevadm tool.
+# In this case try to get the udev version from udevinfo:
+UDEVINFO ?= $(call chk_which_exec, "udevinfo" )
+UDEV_VER ?= $(shell $(UDEVINFO) -V | awk '{print $$3}' | sed -e 's/[^0-9]//g' )
+
+
+UDEV_VER_055 = 055
+UDEV_RULES_D = $(DESTDIR)$(sysconfdir)/udev/rules.d
+UDEV_RULES_MBGCLOCK = 55-mbgclock.rules
+UDEV_RULES_MBGCLOCK_BEFORE_055 = $(UDEV_RULES_MBGCLOCK).before-udev-$(UDEV_VER_055)
+
+
+ifndef STAGED_BUILD
+
+UDEV_RULES_TO_INSTALL := $(shell \
+ if [ $(UDEV_VER) -lt $(UDEV_VER_055) ]; then \
+ echo "$(UDEV_RULES_MBGCLOCK_BEFORE_055)"; \
+ else \
+ echo "$(UDEV_RULES_MBGCLOCK)"; \
+ fi; )
+else
+ UDEV_RULES_TO_INSTALL = $(UDEV_RULES_MBGCLOCK)
+endif
+
+ifndef STAGED_BUILD
+ # Copy udev rules interactively.
+ CP_OPTS_UDEV = -i
+endif
+
+
+
+.PHONY: install_udev
+install_udev:
+ifneq ($(UID),0)
+ $(call make_as_root, $@)
+else
+ ifdef STAGED_BUILD
+ mkdir -p $(UDEV_RULES_D)
+ endif
+ @if test -d $(UDEV_RULES_D); then \
+ if test -f $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); then \
+ if diff -Nq $(UDEV_RULES_TO_INSTALL) $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); then \
+ echo "Udev rules file $(UDEV_RULES_MBGCLOCK) in $(UDEV_RULES_D)/ is unchanged."; \
+ else \
+ cp -v $(CP_OPTS_UDEV) $(UDEV_RULES_TO_INSTALL) $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); \
+ chmod 644 $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); \
+ echo \"\"; \
+ fi \
+ else \
+ echo "Copying new udev rules file $(UDEV_RULES_TO_INSTALL) to $(UDEV_RULES_D)/."; \
+ cp $(CP_OPTS_UDEV) $(UDEV_RULES_TO_INSTALL) $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); \
+ chmod 644 $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK); \
+ fi \
+ else \
+ echo "WARNING:"; \
+ echo " No udev rules directory found!"; \
+ echo ""; \
+ echo " If you want the device nodes to be automatically created by udev,"; \
+ echo " you manually have to add appropriate udev rules."; \
+ echo ""; \
+ echo " See the README file from the driver package for details."; \
+ echo ""; \
+ fi
+endif
+
+
+.PHONY: uninstall_udev
+uninstall_udev:
+ifneq ($(UID),0)
+ $(call make_as_root, $@)
+else
+ ifdef STAGED_BUILD
+ rm -rf $(UDEV_RULES_D)
+ else
+ rm -f $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK)
+ rm -f $(UDEV_RULES_D)/$(UDEV_RULES_MBGCLOCK_BEFORE_055)
+ endif
+endif
+
+
+.PHONY: install
+install: install_udev
+
+
+.PHONY: uninstall
+uninstall: uninstall_udev
+