summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2020-10-15 16:42:47 +0200
committerMartin Burnicki <martin.burnicki@meinberg.de>2020-10-15 16:42:47 +0200
commit86ca6d42567427f6d8de84b606501738c4a2f48f (patch)
tree1326b6d06cae54394a68211a7c3c1dd5134b304f
parent8275c6a151e60408cad980679f39eba14e6bc1fa (diff)
downloadmbgtools-fbsd-devel.tar.gz
mbgtools-fbsd-devel.zip
Update top level Makefiledevel
Build using a static lib to reduce build time. Use CPPFLAGS instead of CFLAGS, and LDLIBS where appropriate. Update and sort target dir list. Cleanup and more common structure.
-rwxr-xr-xMakefile644
1 files changed, 423 insertions, 221 deletions
diff --git a/Makefile b/Makefile
index 51899de..aed3358 100755
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,19 @@
#########################################################################
#
-# $Id: Makefile 1.2.1.2 2018/11/19 12:50:06 martin TRASH $
+# $Id: Makefile 1.2.1.3.2.2 2020/10/15 14:28:07 martin TRASH $
#
# Description:
# Makefile for mbgtools which recurses into the subdirectories.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.2.1.3.2.2 2020/10/15 14:28:07 martin
+# Update an sort target dir list.
+# Revision 1.2.1.3.2.1 2020/10/01 13:11:03 martin
+# *** empty log message ***
+# Revision 1.2.1.3 2020/09/10 10:49:17 martin
+# Use CPPFLAGS instead of CFLAGS, and LDLIBS where appropriate.
# Revision 1.2.1.2 2018/11/19 12:50:06 martin
# Renamed symbol TARGET to MBGTOOLS_TARGET to avoid name clashes.
# Revision 1.2.1.1 2018/04/12 15:35:59 martin
@@ -22,7 +28,21 @@
#
#########################################################################
-V ?= 0 # set to 1 to build verbosely
+.ifdef DEBUG_MAKE
+## debug_msg = .info make[$(MAKELEVEL)] $(1)
+## debug_msg = $(shell echo $(1))
+## debug_msg = $(shell echo make[$(MAKELEVEL)] $*)
+## debug_msg =
+.endif
+
+
+## SEPARATOR_1 := "++"
+SEPARATOR_2 := "========================================================================"
+
+INFO = top common:
+
+# Set V to 1 to build verbosely.
+V ?= 0
# The lines below make the build output non-verbose by default.
# Call make with parameter "V=1" to get verbose output.
@@ -36,275 +56,443 @@ V ?= 0 # set to 1 to build verbosely
vecho = @echo
.endif
+chk_which_exec = $(shell which $(1) 2>/dev/null || whereis -b $(1) | awk ' { print $$2 }' )
+chk_exist_dir = $(shell if test -d $(1); then echo "$(1)"; fi )
-.ifndef prefix
- prefix := /usr/local
-.endif
-.ifndef bindir
- bindir := $(prefix)/bin
-.endif
+# Macros useful to run individual commands as root:
+.ifdef CALLED_FROM_SPEC
+ # fake running as root
+ UID = 0
+.else
+ UID = $(shell id -u)
+ SUDO ?= $(call chk_which_exec,"sudo")
+ SU ?= $(call chk_which_exec,"su")
+.endif # CALLED_FROM_SPEC
-.ifndef sbindir
- sbindir := $(prefix)/sbin
-.endif
+## $(call debug_msg,$(INFO) UID: $(UID))
+## $(call debug_msg,$(INFO) SUDO: $(SUDO))
+## $(call debug_msg,$(INFO) SU: $(SU))
-.ifndef sysconfdir
- sysconfdir := /etc
+.if !empty(SUDO)
+ run_as_root = $(Q)$(shell echo "$(SUDO) $(1)" )
+.elif !empty(SU)
+ run_as_root = $(Q)$(shell echo "$(SU) -c \"$(1)\"" )
.endif
-.ifndef includedir
- includedir := $(prefix)/include
-.endif
+make_as_root = $(call run_as_root, $(MAKE) $(QM) $(INSTALL_PATHS) $(1))
-.ifndef libdir
- CUR_ARCH = $(shell uname -m)
- find_libdirname := $(shell \
- if [ $(CUR_ARCH) = "ia64" -o $(CUR_ARCH) = "x86_64" ]; then \
- if test -d $(prefix)/lib64; \
- then echo "lib64"; \
- else echo "lib"; \
- fi \
- else \
- if test -d $(prefix)/lib32; \
- then echo "lib32"; \
- else echo "lib"; \
- fi \
- fi \
- )
- libdir := $(prefix)/$(call find_libdirname)
-##$(warning $(INFO) libdir set to $(libdir))
-.endif
-INSTALL_PATHS = DESTDIR=$(DESTDIR) prefix=$(prefix) bindir=$(bindir) sbindir=$(sbindir) includedir=$(includedir) libdir=$(libdir) sysconfdir=$(sysconfdir)
+CUR_ARCH ?= $(shell uname -m)
+
+# Determine the path where shared object libraries are to be
+# installed. Expects $(prefix) as parameter.
+find_libdir = $(shell \
+ if [ $(CUR_ARCH) = "ia64" -o $(CUR_ARCH) = "x86_64" ]; then \
+ if test -d $(1)/lib64; \
+ then echo "$(1)/lib64"; \
+ else echo "$(1)/lib"; \
+ fi \
+ else \
+ if test -d $(1)/lib32; \
+ then echo "$(1)/lib32"; \
+ else echo "$(1)/lib"; \
+ fi \
+ fi \
+)
+
+
+prefix ?= /usr/local
+bindir ?= $(prefix)/bin
+sbindir ?= $(prefix)/sbin
+
+sysconfdir ?= /etc
+includedir ?= $(prefix)/include
+libdir ?= $(call find_libdir,$(prefix))
+
+## $(call debug_msg,$(INFO) prefix: $(prefix))
+## $(call debug_msg,$(INFO) libdir: $(libdir) CUR_ARCH: $(CUR_ARCH))
+
+
+INSTALL_PATHS = DESTDIR=$(DESTDIR)
+INSTALL_PATHS += prefix=$(prefix)
+INSTALL_PATHS += bindir=$(bindir)
+INSTALL_PATHS += sbindir=$(sbindir)
+INSTALL_PATHS += includedir=$(includedir)
+INSTALL_PATHS += libdir=$(libdir)
+INSTALL_PATHS += sysconfdir=$(sysconfdir)
+
.ifndef SO_BASENAMES
SO_BASENAMES += devio
SO_BASENAMES += util
- SO_BASENAMES += serio
- SO_BASENAMES += extio
-.endif
+## SO_BASENAMES += serio
+## SO_BASENAMES += extio
+.endif # SO_BASENAMES
-.ifndef SO_SUBDIRS
-# SO_SUBDIRS += $(foreach dir,$(SO_BASENAMES), libmbg_so/mbg$(dir) )
-## $(warning $(INFO) **************** SO_SUBDIRS set to $(SO_SUBDIRS))
+# SO_SUBDIRS ?= $(foreach dir,$(SO_BASENAMES), libmbg_so/mbg$(dir) )
+## $(call debug_msg,$(INFO) SO_SUBDIRS: $(SO_SUBDIRS))
+.ifdef DEBUG_MAKE
+.info [${.MAKE.LEVEL}] $(INFO) SO_SUBDIRS: $(SO_SUBDIRS)
.endif
-##$(warning $(INFO) SO_SUBDIRS set to $(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
+
+
-.ifndef BASEDIR
+.ifndef BASEDIR # ======================================================
-.DEFAULT_GOAL := all
-MAKECMDGOALS ?= $(.DEFAULT_GOAL)
+# This section is evaluated if BASEDIR is not yet defined,
+# i.e. if this makefile is read by the top-level make.
+
+INFO = top 1st:
+## $(call debug_msg,$(INFO) reading top level part)
+.ifdef DEBUG_MAKE
+.info [${.MAKE.LEVEL}] $(INFO) reading top level part
+.endif
+
+.TARGETS ?= all
# This section is used only if this makefile is called by the top-level
# make. It specifies some common targets and some subdirs in which a
# recursive make will be executed, which may include this make file again
# and evaluate the second part.
-INFO=top 1st:
-## $(warning $(INFO) reading top level part)
-## export COMMON_MAKEFILE := $(CURDIR)/Makefile
-## $(warning $(INFO) COMMON_MAKEFILE set to $(COMMON_MAKEFILE))
+# A routine that can be called to check if a Makefile exists
+# in a specific subdirectory. It returns the subdirectory name
+# if it does, or an empty string if it does not.
+chk_subdir = $(shell test -f $(strip $(1))/Makefile && echo "$(1)" )
+
-# The macro function below prints an info string whether a target
-# is supported by the kernel Makefile
+# List of subdirectories that are only built/cleaned,
+# but not installed/uninstalled.
+SUBDIRS_BUILD_ONLY ?= $(MBGTOOLS_LIB_DIR)
-.ifndef SUBDIRS
-chk_subdir = $(shell test -f $(strip $(1))/Makefile || test -f $(strip $(1))/BSDmakefile && echo "$(1)" )
+# List of subdirectories that don't need to be built/cleaned,
+# but installed/uninstalled.
+SUBDIRS_INST_ONLY ?= $(call chk_subdir, "libmbg_so/devel" )
+
+
+# List of subdirectories that are built/cleaned
+# as well as installed/uninstalled.
+.ifndef SUBDIRS_COMMON
.ifndef DONT_BUILD_LIBS
- SUBDIRS += $(SO_SUBDIRS)
+ SUBDIRS_COMMON += $(SO_SUBDIRS)
## $(foreach dir,$(SO_SUBDIRS),$(eval SUBDIRS += $(call chk_subdir, $(dir))))
- SUBDIRS += $(call chk_subdir, "libmbg_so/devel" )
-.endif
+## SUBDIRS += $(call chk_subdir, "libmbg_so/devel" )
+.endif # DONT_BUILD_LIBS
.ifndef DONT_BUILD_TOOLS
- SUBDIRS += $(call chk_subdir, "mbgstatus" )
- SUBDIRS += $(call chk_subdir, "mbgsetsystime" )
- SUBDIRS += $(call chk_subdir, "mbgctrl" )
- SUBDIRS += $(call chk_subdir, "mbgirigcfg" )
- SUBDIRS += $(call chk_subdir, "mbgshowsignal" )
- SUBDIRS += $(call chk_subdir, "mbggpscap" )
- SUBDIRS += $(call chk_subdir, "mbghrtime" )
- SUBDIRS += $(call chk_subdir, "mbgfasttstamp" )
- SUBDIRS += $(call chk_subdir, "mbgsvcd" )
- SUBDIRS += $(call chk_subdir, "mbgxhrtime" )
- SUBDIRS += $(call chk_subdir, "test/mbgtestcalrec" )
- SUBDIRS += $(call chk_subdir, "test/mbgtestio" )
- SUBDIRS += $(call chk_subdir, "test/mbgtestmmio" )
- SUBDIRS += $(call chk_subdir, "test/mbgtestxhrt" )
- SUBDIRS += $(call chk_subdir, "test/mbgchksystime" )
- SUBDIRS += $(call chk_subdir, "test/mbgtestsettime" )
-.endif
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgstatus")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgsetsystime")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgctrl")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgirigcfg")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgshowsignal")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbggpscap")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbghrtime")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgfasttstamp")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgsvcd")
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgxhrtime")
+ SUBDIRS_COMMON += $(call chk_subdir, "test/mbgtestcalrec")
+ SUBDIRS_COMMON += $(call chk_subdir, "test/mbgtestio")
+ SUBDIRS_COMMON += $(call chk_subdir, "test/mbgtestmmio")
+ SUBDIRS_COMMON += $(call chk_subdir, "test/mbgtestxhrt")
+ SUBDIRS_COMMON += $(call chk_subdir, "test/mbgchksystime")
+ SUBDIRS_COMMON += $(call chk_subdir, "test/mbgtestsettime")
+.endif # DONT_BUILD_TOOLS
+
.ifndef DONT_BUILD_GUI
-.ifndef DONT_BUILD_MBGMON
- SUBDIRS += $(call chk_subdir, "wxwidgets/mbgmon" )
-.endif
-.ifndef DONT_BUILD_MBGSTATSVIEWER
- SUBDIRS += $(call chk_subdir, "wxwidgets/mbgstatsviewer" )
+.ifdef BUILD_MBGMON
+ SUBDIRS_COMMON += $(call chk_subdir, "wxwidgets/mbgmon")
.endif
+.ifdef BUILD_MBGSTATSVIEWER
+ SUBDIRS_COMMON += $(call chk_subdir, "wxwidgets/mbgstatsviewer")
.endif
+.endif # DONT_BUILD_GUI
+
.ifndef DONT_BUILD_DRIVER
- SUBDIRS += $(call chk_subdir, "mbgclock" )
- ##SUBDIRS += $(call chk_subdir, "test/mbgclock-test" )
-.endif
+ SUBDIRS_COMMON += $(call chk_subdir, "mbgclock")
+ ## SUBDIRS_COMMON += $(call chk_subdir, "test/mbgclock-test" )
+.endif # DONT_BUILD_DRIVER
+
+.endif # SUBDIRS_COMMON
+
+
+## FIXME TODO Temporary creation of list
+
+SUBDIRS_COMMON += mbgcmptime
+SUBDIRS_COMMON += mbgctrl
+SUBDIRS_COMMON += mbgfasttstamp
+SUBDIRS_COMMON += mbggpscap
+SUBDIRS_COMMON += mbghrtime
+SUBDIRS_COMMON += mbgirigcfg
+SUBDIRS_COMMON += mbgsetsystime
+SUBDIRS_COMMON += mbgshowsignal
+SUBDIRS_COMMON += mbgstatus
+SUBDIRS_COMMON += mbgsvcd
+SUBDIRS_COMMON += mbgtcrcal
+## SUBDIRS_COMMON += mbgxhrtime ## not yet tested
+
+SUBDIRS_COMMON += test/mbgchksystime
+## SUBDIRS_COMMON += test/mbgclock-test
+SUBDIRS_COMMON += test/mbgreadtime
+##SUBDIRS_COMMON += test/mbgtestcalrec
+SUBDIRS_COMMON += test/mbgtestio
+SUBDIRS_COMMON += test/mbgtestsettime
+SUBDIRS_COMMON += test/mbg_ucap
+
+SUBDIRS_COMMON += mbgclock
+
+## FIXME TODO End of temporary creation of list
+
+
+# Targets for which we recurse into specific subdirs
+TARGETS_BUILD := all clean distclean
+TARGETS_INST := install uninstall
+
+
+# Determine the subdirectories to be recursed into
+# depending on the current goal.
+## ifneq ($(filter $(.TARGET),$(TARGETS_BUILD)),)
+## SUBDIR_TARGETS += $(SUBDIRS_BUILD_ONLY) $(SUBDIRS_COMMON)
+## endif
+
+## ifneq ($(filter $(.TARGET),$(TARGETS_INST)),)
+## SUBDIR_TARGETS += $(SUBDIRS_INST_ONLY) $(SUBDIRS_COMMON)
+## endif
+
+
+# For some targets we may also want to execute some additional
+# commands after the main targets have been made.
+## ifeq ($(.TARGET),all)
+## POST_TARGETS = post_build_info
+## endif
-## $(warning $(INFO) SUBDIRS = $(SUBDIRS))
-## $(warning $(INFO) MAKECMDGOALS = $(MAKECMDGOALS))
+## ifeq ($(.TARGET),install)
+## POST_TARGETS = post_install_info
+## endif
+
+# If the current target is uninstall, we may also want to run
+# some commands before uninstallation.
+## ifeq ($(.TARGET),uninstall)
+## PRE_TARGETS = pre_uninstall
+## PRE_UNINSTALL_TARGETS = mbgsvcd_uninstall
+## endif
+
+
+## $(call debug_msg,$(INFO) .TARGETS: $(.TARGETS))
+## $(call debug_msg,$(INFO) SUBDIRS_BUILD_ONLY: $(SUBDIRS_BUILD_ONLY))
+## $(call debug_msg,$(INFO) SUBDIRS_INST_ONLY: $(SUBDIRS_INST_ONLY))
+## $(call debug_msg,$(INFO) SUBDIRS_COMMON: $(SUBDIRS_COMMON))
+.ifdef DEBUG_MAKE
+.info [${.MAKE.LEVEL}] $(INFO) .TARGETS: $(.TARGETS)
+.info [${.MAKE.LEVEL}] $(INFO) SUBDIRS_BUILD_ONLY: $(SUBDIRS_BUILD_ONLY)
+.info [${.MAKE.LEVEL}] $(INFO) SUBDIRS_INST_ONLY: $(SUBDIRS_INST_ONLY)
+.info [${.MAKE.LEVEL}] $(INFO) SUBDIRS_COMMON: $(SUBDIRS_COMMON)
+.info [${.MAKE.LEVEL}] $(INFO) TARGETS_BUILD: $(TARGETS_BUILD)
+.info [${.MAKE.LEVEL}] $(INFO) TARGETS_INST: $(TARGETS_INST)
+.info [${.MAKE.LEVEL}] $(INFO) SUBDIR_TARGETS: $(SUBDIR_TARGETS)
.endif
+## .PHONY: $(TARGETS_BUILD) $(TARGETS_INST)
+## $(TARGETS_BUILD) $(TARGETS_INST): $(PRE_TARGETS) $(SUBDIR_TARGETS) $(POST_TARGETS)
-SUBDIRS += mbgstatus
-SUBDIRS += mbgsvcd
-SUBDIRS += mbgsetsystime
-SUBDIRS += mbgctrl
-SUBDIRS += mbgirigcfg
-SUBDIRS += mbgshowsignal
-SUBDIRS += mbggpscap
-SUBDIRS += mbghrtime
-SUBDIRS += mbgfasttstamp
-## SUBDIRS += mbgxhrtime ## not yet tested
-
-SUBDIRS += test/mbgchksystime
-## SUBDIRS += test/mbgclock-test
-SUBDIRS += test/mbgcmptime
-SUBDIRS += test/mbgreadtime
-SUBDIRS += test/mbgtcrcal
-##SUBDIRS += test/mbgtestcalrec
-SUBDIRS += test/mbgtestio
-SUBDIRS += test/mbgtestsettime
-SUBDIRS += test/mbg_ucap
-
-SUBDIRS += mbgclock
-
-.PHONY: all clean distclean install uninstall
-all clean distclean install uninstall:
- @for dir in $(SUBDIRS); do \
- if test -f $$dir/Makefile || test -f $$dir/BSDmakefile; then \
- echo "Making $@ in $$dir"; \
- /bin/sh -c "cd $$dir; $(MAKE) $@"; \
+
+.PHONY: $(TARGETS_BUILD)
+$(TARGETS_BUILD):
+.ifdef SEPARATOR_1
+ @echo "$(SEPARATOR_1)"
+.endif
+ @for dir in $(SUBDIRS_BUILD_ONLY) $(SUBDIRS_COMMON); do \
+ if test -f $$dir/Makefile; then \
+ echo "Making ${.TARGETS} in $$dir"; \
+ /bin/sh -c "cd $$dir && $(MAKE) ${.TARGETS}"; \
fi \
done
-.PHONY: dev dev-nodes dev-clean suse_symvers probe ins rm test reload check \
- refclocks kernel_config
-dev dev-nodes dev-clean suse_symvers probe ins rm test reload check \
- refclocks kernel_config:
- @echo "Making $(MAKECMDGOALS) in $@"
- @cd mbgclock && make $@
-.PHONY: cleanreload
-cleanreload: clean all install reload
+
+## .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:
+## @echo "Making $(.TARGET) in $@"
+## @$(MAKE) -C mbgclock $@
+
+## .PHONY: cleanreload
+## cleanreload: clean all install reload
.else # ================================================================
-# This section is evaluated only if this makefile is included from
-# a subproject's makefile.
+# This section is evaluated if BASEDIR is already defined,
+# i.e. if this makefile is included from a sub-level make.
+INFO = top 2nd:
+## $(call debug_msg,$(INFO) reading second level definitions)
+
+## $(call debug_msg,$(INFO) MBGTOOLS_TARGET: $(MBGTOOLS_TARGET))
+## $(call debug_msg,$(INFO) BASEDIR: $(BASEDIR))
+## $(call debug_msg,$(INFO) .TARGETS: $(.TARGETS))
.ifndef MBGLIB
MBGLIB := $(BASEDIR)/mbglib
+ ## $(call debug_msg,$(INFO) MBGLIB: $(MBGLIB))
.endif
-MBGLIB_DIRS += common linux
+# We could use this if we could use 'foreach':
+## MBGLIB_DIRS += common
+## MBGLIB_DIRS += bsd
-# Macros useful to run individual commands as root:
-.ifndef CALLED_FROM_SPEC
-.ifndef SUDO
- SUDO := $(shell which sudo)
-.endif
+# Without 'foreach', we use these:
+MBGLIB_COMMON = ${MBGLIB}/common
+MBGLIB_BSD = ${MBGLIB}/bsd
-.ifndef SU
- SU := $(shell which su)
-.endif
+INCLUDE_PATHS = -I.
+INCLUDE_PATHS += -I$(BASEDIR)
+# foreach doesn't seem to work under *BSD :-(
+# INCLUDE_PATHS += $(foreach dir,$(MBGLIB_DIRS),-I$(MBGLIB)/$(dir))
+INCLUDE_PATHS += -I$(MBGLIB_COMMON)
+INCLUDE_PATHS += -I$(MBGLIB_BSD)
- UID = $(shell id -u)
-.else
- #fake running as root
- UID = 0
-.endif
-run_as_root = $(shell echo "$(SUDO) $(1) || $(SU) -c \"$(1)\"" )
-make_as_root = $(call run_as_root, make $(1))
+.ifndef KMOD #===========================================================
-.ifndef KMOD # ===== not building a kernel module ===============
+# not building a kernel module
+
+.c.o:
+ $(vecho) " $(CC) ${.IMPSRC}"
+ $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -o ${.TARGET} -c ${.IMPSRC}
+
+.cpp.o:
+ $(vecho) " $(CC) ${.IMPSRC}"
+ $(Q)$(CC) $(CPPFLAGS) $(CXXFLAGS) -o ${.TARGET} -c ${.IMPSRC}
-CFLAGS += -Wall
+
+
+CPPFLAGS += -Wall
+## CPPFLAGS += -Wextra
+## CPPFLAGS += -Winline
+## CPPFLAGS += -D_PRELIMINARY_CODE
.ifdef DEBUG
- CFLAGS += -DDEBUG=$(DEBUG)
- CFLAGS += -g
+ CPPFLAGS += -DDEBUG=$(DEBUG)
+ CPPFLAGS += -g2
.else
- CFLAGS += -O2
+ CPPFLAGS += -O2
.endif
.ifdef USE_TIMESPEC
- CFLAGS += -DUSE_TIMESPEC=$(USE_TIMESPEC)
+ CPPFLAGS += -DUSE_TIMESPEC=$(USE_TIMESPEC)
.endif
-CFLAGS += -I.
-CFLAGS += -I$(BASEDIR)
-# foreach doesn't seem to work under FreeBSD :-(
-# CFLAGS += $(foreach dir,$(MBGLIB_DIRS),-I$(MBGLIB)/$(dir))
-CFLAGS += -I$(BASEDIR)/mbglib/common
-CFLAGS += -I$(BASEDIR)/mbglib/bsd
-LDFLAGS += -lutil
-# foreach doesn't seem to work under FreeBSD :-(
-# LDFLAGS += $(foreach dir,$(SO_SUBDIRS),-L $(BASEDIR)/$(dir) )
+## CPPFLAGS += -D_USE_SOCKET_IO=1
+
+## CPPFLAGS += -D_USE_CHK_TSTR=1
+
+CPPFLAGS += $(INCLUDE_PATHS)
+
+# This is required for the shared object libraries, but
+# we use it in general to simplify the build procedure.
+CPPFLAGS += -fPIC
+
+
+# Additional C++-only compiler flags.
+## CXXFLAGS += -Wno-deprecated
+
+
+## LDFLAGS += $(foreach dir,$(SO_SUBDIRS),-L$(BASEDIR)/$(dir) )
+# foreach doesn't seem to work under *BSD :-(
+
+
+# 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)
+
+.ifdef MBGTOOLS_LIB_TARGET
+ CURR_TARGET = $(MBGTOOLS_LIB_TARGET)
+ USE_STATIC_LIB = 0
+.endif
+LDLIBS += -lutil
+# We also need these version numbers for install
SO_MAJOR_VERSION = 1
SO_MINOR_VERSION = 0
-.ifdef SO_TARGET_BASENAME
+.ifdef MBGTOOLS_SO_TARGET_BASENAME
+
.ifndef SO_POINT_RELEASE
SO_POINT_RELEASE = 0
.endif
- SO_TARGET_NAME = libmbg$(SO_TARGET_BASENAME)
+ SO_TARGET_NAME = libmbg$(MBGTOOLS_SO_TARGET_BASENAME)
SO_TARGET_LIBNAME = $(SO_TARGET_NAME).so
SO_TARGET_SONAME = $(SO_TARGET_LIBNAME).$(SO_MAJOR_VERSION)
- MBGTOOLS_TARGET = $(SO_TARGET_SONAME).$(SO_MINOR_VERSION).$(SO_POINT_RELEASE)
+ CURR_TARGET = $(SO_TARGET_SONAME).$(SO_MINOR_VERSION).$(SO_POINT_RELEASE)
+ USE_STATIC_LIB = 1
- OBJS += mbg$(SO_TARGET_BASENAME).o
+ OBJS += mbg$(MBGTOOLS_SO_TARGET_BASENAME).o
CLEAN_FILES += $(SO_TARGET_LIBNAME)
- CFLAGS += -fPIC
- CFLAGS += -c
+ # Flag -fPIC is required when compiling for shared objects, so
+ # we add this unless it has already been added globally before.
+## FIXME ifeq ($(filter $(CPPFLAGS),-fPIC),)
+## CPPFLAGS += -fPIC
+## endif
+
+ CPPFLAGS += -c
LDFLAGS += -shared
- LDFLAGS += -lc
LDFLAGS += -Wl,-soname,$(SO_TARGET_SONAME)
+ LDLIBS += -lc
+
.ifndef LIBDIR
LIBDIR := $(shell if [ -d /usr/lib64 ]; then echo /usr/lib64; else echo /usr/lib; fi )
.endif
-.endif
-CXXFLAGS = $(CFLAGS)
+.endif # MBGTOOLS_SO_TARGET_BASENAME
+
+.ifdef MBGTOOLS_TARGET
+ CURR_TARGET = $(MBGTOOLS_TARGET)
+ USE_STATIC_LIB = 1
+
+ OBJS = $(CURR_TARGET).o
+.endif # MBGTOOLS_TARGET
+
+
+.if $(USE_STATIC_LIB) != 0
+ LDFLAGS += -L$(MBGTOOLS_LIB_PATH)
+ LDLIBS += -l$(MBGTOOLS_LIB_BASENAME)
+
+ $(CURR_TARGET): mbg_static_lib
+.endif # $(USE_STATIC_LIB) != 0
+
+
+## $(call debug_msg,$(INFO) MBGTOOLS_LIB_FILE_PATH: $(MBGTOOLS_LIB_FILE_PATH))
+## $(call debug_msg,$(INFO) USE_STATIC_LIB: $(USE_STATIC_LIB))
+## $(call debug_msg,$(INFO) CURR_TARGET: $(CURR_TARGET))
.PHONY: all
-all: $(MBGTOOLS_TARGET)
+all: $(CURR_TARGET)
#### VPATH += $(foreach dir,$(MBGLIB_DIRS),$(MBGLIB)/$(dir))
VPATH = $(BASEDIR)/mbglib/common:$(BASEDIR)/mbglib/bsd
-.ifndef MBGDEVIO_SIMPLE
- MBGDEVIO_SIMPLE = 1
-.endif
-
-.ifdef MBGDEVIO_SIMPLE
- CFLAGS += -DMBGDEVIO_SIMPLE=$(MBGDEVIO_SIMPLE)
-.endif
+## USE_THREAD_API = 1
.ifdef USE_THREAD_API
@@ -323,25 +511,25 @@ VPATH = $(BASEDIR)/mbglib/common:$(BASEDIR)/mbglib/bsd
.ifndef USE_THREAD_AFFINITY
.ifdef USE_NPTL
USE_THREAD_AFFINITY := $(shell grep -q pthread_getaffinity /usr/include/nptl/pthread.h && echo 1)
-.endif
+.endif # USE_NPTL
.ifndef USE_THREAD_AFFINITY
##++++ If not found either, don't support thread affinity
USE_THREAD_AFFINITY=0
-.else
+.else # USE_THREAD_AFFINITY
#if supported via nptl add the associated search paths
- CFLAGS += -I /usr/include/nptl -L /usr/lib/nptl
-.endif
-.endif
+ CPPFLAGS += -I/usr/include/nptl -L/usr/lib/nptl
+.endif # USE_THREAD_AFFINITY
+.endif # USE_THREAD_API
# May want to use the result for our program
- ## CFLAGS += -DUSE_THREAD_AFFINITY=$(USE_THREAD_AFFINITY)
+ ## CPPFLAGS += -DUSE_THREAD_AFFINITY=$(USE_THREAD_AFFINITY)
- CFLAGS += -DMBGDEVIO_USE_THREAD_API=1
+ CPPFLAGS += -DMBGDEVIO_USE_THREAD_API=1
+
+ LDLIBS += -pthread
+.endif # USE_THREAD_API
- #LDFLAGS += -lpthread
- LDFLAGS += -pthread
-.endif
.ifdef INST_TO_BIN
INST_DIR = $(DESTDIR)$(bindir)
@@ -353,44 +541,55 @@ VPATH = $(BASEDIR)/mbglib/common:$(BASEDIR)/mbglib/bsd
INST_DIR = $(DESTDIR)$(libdir)
.else
.ifdef INST_TO_INCLUDE
- INST_DIR = $(DESTDIR)$(includedir)/mbglib
-.endif
+ INST_DIR = $(DESTDIR)$(includedir)/mbglib
.endif
.endif
.endif
+.endif # INST_TO_BIN
+
.ifdef DO_GUI_INSTALLATION
EXT_INSTALL += gui_install
EXT_UNINSTALL += gui_uninstall
.endif
+.PHONY: mbg_static_lib
+mbg_static_lib:
+ /bin/sh -c "cd $(MBGTOOLS_LIB_PATH) && $(MAKE) $(MBGTOOLS_LIB_FILE)"
-## $(warning $(INFO) CFLAGS=$(CFLAGS))
-## $(warning $(INFO) EXTRA_CFLAGS=$(EXTRA_CFLAGS))
-## $(warning $(INFO) MAKECMDGOALS = $(MAKECMDGOALS))
+# Options for the archiver to build a static library
+ARFLAGS := rcs
+.if $(V) != 0
+ # In verbose mode we also make the archiver verbose.
+ ARFLAGS := $(ARFLAGS)v
+.endif
-.c.o:
- $(vecho) " $(CC) ${.IMPSRC}"
- $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -o ${.TARGET} -c ${.IMPSRC}
-
+## $(call debug_msg,$(INFO) CPPFLAGS: $(CPPFLAGS))
+# ## $(call debug_msg,$(INFO) EXTRA_CFLAGS: $(EXTRA_CFLAGS))
+## $(call debug_msg,$(INFO) .TARGET: $(.TARGET))
-$(MBGTOOLS_TARGET): $(OBJS)
+$(CURR_TARGET): $(OBJS)
+.ifdef MBGTOOLS_LIB_TARGET
+ $(vecho) " $(AR) $@"
+ $(Q)$(AR) $(ARFLAGS) $@ $(OBJS)
+.else
$(vecho) " Linking $@"
- $(Q)$(CC) -o $@ $(OBJS) $(LDFLAGS)
-.ifdef SO_TARGET_LIBNAME
- ln -sf $(MBGTOOLS_TARGET) $(SO_TARGET_LIBNAME)
-.endif
+ $(Q)$(CC) -o $@ $(LDFLAGS) $(OBJS) $(LDLIBS)
+.ifdef SO_TARGET_LIBNAME
+ ln -sf $(CURR_TARGET) $(SO_TARGET_LIBNAME)
+.endif # SO_TARGET_LIBNAME
+.endif # MBGTOOLS_LIB_TARGET
.PHONY: install
install: $(EXT_INSTALL)
.ifdef XXX #.ifneq ($(UID),0)
$(call make_as_root, $@)
-.else
-.ifdef INCLUDE_FILES #include files
+.else # UID
+.ifdef INCLUDE_FILES # include files
mkdir -p $(INST_DIR)
for incfile in $(INCLUDE_FILES); do \
install -m 644 $(BASEDIR)/mbglib/common/$$incfile $(INST_DIR)/; \
@@ -400,7 +599,7 @@ install: $(EXT_INSTALL)
ln -sf libmbg$$basename.so.$(SO_MAJOR_VERSION) libmbg$$basename.so; \
popd; \
done;
-.else #usual installation
+.else # usual installation
.ifdef CALLED_FROM_SPEC
mkdir -p $(INST_DIR)
.endif
@@ -409,58 +608,61 @@ install: $(EXT_INSTALL)
.ifndef CALLED_FROM_SPEC
.ifdef INST_TO_LIB
/sbin/ldconfig
-.endif
-.endif
-.endif
-.endif
+.endif # INST_TO_LIB
+.endif # CALLED_FROM_SPEC
+.endif # !INCLUDE_FILES
+.endif # UID
.PHONY: uninstall
uninstall: $(EXT_UNINSTALL)
.ifdef INCLUDE_FILES #remove include files and
- rm -rf $(INST_DIR)
+ $(Q)rm -rf $(INST_DIR)
.ifndef CALLED_FROM_SPEC #remove symbolic links
for basename in $(SO_BASENAMES); do \
- rm -f $(libdir)/libmbg$$basename.so; \
+ $(Q)rm -f $(libdir)/libmbg$$basename.so; \
done;
-.endif
-.else
+.endif # CALLED_FROM_SPEC
+.else # !INCLUDE_FILES
.ifdef XXX #.ifneq ($(UID),0)
$(call make_as_root, $@)
-.else
- rm -f $(INST_DIR)/$(MBGTOOLS_TARGET)
+.else # UID
+ $(Q)rm -f $(INST_DIR)/$(MBGTOOLS_TARGET)
.ifndef CALLED_FROM_SPEC
.ifdef INST_TO_LIB
/sbin/ldconfig
-.endif
-.endif
-.endif
-.endif
+.endif # INST_TO_LIB
+.endif # CALLED_FROM_SPEC
+.endif # UID
+.endif # INCLUDE_FILES
+
.PHONY: gui_install
gui_install:
.ifdef XXX #.ifneq ($(UID),0)
$(call make_as_root, $@)
-.else
+.else # UID
mkdir -p $(DESTDIR)$(prefix)/share/$(MBGTOOLS_TARGET)
cp $(MBGTOOLS_TARGET).png $(DESTDIR)$(prefix)/share/$(MBGTOOLS_TARGET)/$(MBGTOOLS_TARGET).png
mkdir -p $(DESTDIR)$(prefix)/share/applications
cp $(MBGTOOLS_TARGET).desktop $(DESTDIR)$(prefix)/share/applications/$(MBGTOOLS_TARGET).desktop
-.endif
+.endif # UID
+
.PHONY: gui_uninstall
gui_uninstall:
.ifdef XXX #.ifneq ($(UID),0)
$(call make_as_root, $@)
-.else
+.else # UID
$(Q)rm -rf $(DESTDIR)$(prefix)/share/$(MBGTOOLS_TARGET)
$(Q)rm -f $(DESTDIR)$(prefix)/share/applications/$(MBGTOOLS_TARGET).desktop
-.endif
+.endif # UID
+
CLEAN_FILES += *.o
CLEAN_FILES += *~
CLEAN_FILES += core
-CLEAN_FILES += $(MBGTOOLS_TARGET)
+CLEAN_FILES += $(CURR_TARGET)
.PHONY: clean
clean:
@@ -477,15 +679,15 @@ clean:
# Conditionals for any kernel driver.
.ifdef MBG_PRI_64_PREFIX_L
- CFLAGS += -DMBG_PRI_64_PREFIX_L
+ CPPFLAGS += -DMBG_PRI_64_PREFIX_L
.else
.ifdef MBG_PRI_64_PREFIX_LL
- CFLAGS += -DMBG_PRI_64_PREFIX_LL
+ CPPFLAGS += -DMBG_PRI_64_PREFIX_LL
.endif
.endif
.ifdef DEBUG_MSG_SLEEP
- CFLAGS += -DDEBUG_MSG_SLEEP=$(DEBUG_MSG_SLEEP)
+ CPPFLAGS += -DDEBUG_MSG_SLEEP=$(DEBUG_MSG_SLEEP)
MUST_DEBUG_DRVR = 1
.endif
@@ -493,10 +695,10 @@ clean:
# Global conditionals.
.ifdef DEBUG
- CFLAGS += -DDEBUG=$(DEBUG)
+ CPPFLAGS += -DDEBUG=$(DEBUG)
.else
.ifdef MUST_DEBUG_DRVR
- CFLAGS += -DDEBUG=5 # Yet must be > MBG_DBG_DETAIL, TODO
+ CPPFLAGS += -DDEBUG=5 # Yet must be > MBG_DBG_DETAIL, TODO
.endif
.endif