######################################################################### # # $Id: Makefile 1.1.1.8 2017/08/11 10:32:21 martin TEST $ # # Description: # Makefile for mbgtools which recurses into the subdirectories. # # ----------------------------------------------------------------------- # $Log: Makefile $ # Revision 1.1.1.8 2017/08/11 10:32:21 martin # Cleaned up CPPFLAGS. # Revision 1.1.1.7 2017/08/10 15:40:25 martin # Cleanup. # Revision 1.1.1.6 2017/08/10 15:15:02 martin # Merged common kernel module stuff. # Revision 1.1.1.5 2017/08/02 12:13:19 martin # Re-added mbgclock to SUBDIRS. # Revision 1.1.1.4 2017/07/26 14:31:06 martin # Removed trailing spaces. # Revision 1.1.1.3 2011/11/24 13:59:58 martin # Revision 1.1.1.2 2011/07/08 12:10:09 martin # Revision 1.1.1.1 2011/03/29 13:54:39 martin # Revision 1.1.1.6.1.1 2011/03/28 09:36:56 martin # Kardel: exclude subdir mbgclock under NetBSD # Revision 1.1.1.6 2011/03/25 11:05:55 martin # Optional parameter USE_TIMESPEC. # Revision 1.1.1.5 2011/03/21 16:24:12 martin # Workaround for recursive make under NetBSD. # Revision 1.1.1.4 2011/02/04 10:09:45 martin # Revision 1.1.1.3 2011/02/02 12:33:29 martin # Revision 1.1.1.2 2011/01/28 09:29:47 martin # Revision 1.1.1.1 2011/01/27 16:16:40 martin # Revision 1.1 2011/01/27 15:41:01 martin # Initial revision # ######################################################################### .ifndef prefix prefix := /usr/local .endif .ifndef bindir bindir := $(prefix)/bin .endif .ifndef sbindir sbindir := $(prefix)/sbin .endif .ifndef sysconfdir sysconfdir := /etc .endif .ifndef includedir includedir := $(prefix)/include .endif .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) .ifndef SO_BASENAMES SO_BASENAMES += devio SO_BASENAMES += util SO_BASENAMES += serio SO_BASENAMES += extio .endif .ifndef SO_SUBDIRS # SO_SUBDIRS += $(foreach dir,$(SO_BASENAMES), libmbg_so/mbg$(dir) ) ## $(warning $(INFO) **************** SO_SUBDIRS set to $(SO_SUBDIRS)) .endif ##$(warning $(INFO) SO_SUBDIRS set to $(SO_SUBDIRS)) .ifndef BASEDIR .DEFAULT_GOAL := all MAKECMDGOALS ?= $(.DEFAULT_GOAL) # 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)) # The macro function below prints an info string whether a target # is supported by the kernel Makefile .ifndef SUBDIRS chk_subdir = $(shell test -f $(strip $(1))/Makefile && echo "$(1)" ) .ifndef DONT_BUILD_LIBS SUBDIRS += $(SO_SUBDIRS) ## $(foreach dir,$(SO_SUBDIRS),$(eval SUBDIRS += $(call chk_subdir, $(dir)))) SUBDIRS += $(call chk_subdir, "libmbg_so/devel" ) .endif .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 .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" ) .endif .endif .ifndef DONT_BUILD_DRIVER SUBDIRS += $(call chk_subdir, "mbgclock" ) ##SUBDIRS += $(call chk_subdir, "test/mbgclock-test" ) .endif ## $(warning $(INFO) SUBDIRS = $(SUBDIRS)) ## $(warning $(INFO) MAKECMDGOALS = $(MAKECMDGOALS)) .endif 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/mbgtestcalrec # SUBDIRS += test/mbgtestio # SUBDIRS += test/mbgtestmmio # SUBDIRS += test/mbgtestxhrt # SUBDIRS += test/mbgchksystime SUBDIRS += mbgclock .PHONY: all clean distclean install uninstall all clean distclean install uninstall: @for dir in $(SUBDIRS); do \ if test -f $$dir/Makefile; then \ /bin/sh -c "cd $$dir; $(MAKE) $@"; \ 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: @cd mbgclock && make $@ .PHONY: cleanreload cleanreload: clean all install reload .else # ================================================================ # This section is evaluated only if this makefile is included from # a subproject's makefile. .ifndef MBGLIB MBGLIB := $(BASEDIR)/mbglib .endif ## MBGLIB_DIRS += common linux MBGLIB_COMMON = ${MBGLIB}/common MBGLIB_BSD = ${MBGLIB}/bsd INCLUDES += -I. INCLUDES += -I$(BASEDIR) ## INCLUDES += $(foreach dir,$(MBGLIB_DIRS),-I$(MBGLIB)/$(dir)) INCLUDES += -I$(MBGLIB_COMMON) INCLUDES += -I$(MBGLIB_BSD) # Macros useful to run individual commands as root: .ifndef CALLED_FROM_SPEC .ifndef SUDO SUDO := $(shell which sudo) .endif .ifndef SU SU := $(shell which su) .endif 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)) .ifdef DEBUG CPPFLAGS += -DDEBUG=$(DEBUG) CPPFLAGS += -g .endif .ifndef KMOD #=========================================================== # not building a kernel module CPPFLAGS += -Wall ## CPPFLAGS += -W .ifdef USE_TIMESPEC CPPFLAGS += -DUSE_TIMESPEC=$(USE_TIMESPEC) .endif CPPFLAGS += $(INCLUDES) LDFLAGS += $(foreach dir,$(SO_SUBDIRS),-L $(BASEDIR)/$(dir) ) SO_MAJOR_VERSION = 1 SO_MINOR_VERSION = 0 .ifdef SO_TARGET_BASENAME .ifndef SO_POINT_RELEASE SO_POINT_RELEASE = 0 .endif SO_TARGET_NAME = libmbg$(SO_TARGET_BASENAME) SO_TARGET_LIBNAME = $(SO_TARGET_NAME).so SO_TARGET_SONAME = $(SO_TARGET_LIBNAME).$(SO_MAJOR_VERSION) TARGET = $(SO_TARGET_SONAME).$(SO_MINOR_VERSION).$(SO_POINT_RELEASE) OBJS += mbg$(SO_TARGET_BASENAME).o CLEAN_FILES += $(SO_TARGET_LIBNAME) CPPFLAGS += -fPIC CPPFLAGS += -c LDFLAGS += -shared LDFLAGS += -lc LDFLAGS += -Wl,-soname,$(SO_TARGET_SONAME) .ifndef LIBDIR LIBDIR := $(shell if [ -d /usr/lib64 ]; then echo /usr/lib64; else echo /usr/lib; fi ) .endif .endif .PHONY: all all: $(TARGET) ## VPATH += $(foreach dir,$(MBGLIB_DIRS),$(MBGLIB)/$(dir)) VPATH = $(MBGLIB_COMMON):$(MBGLIB_BSD) .ifndef MBGDEVIO_SIMPLE MBGDEVIO_SIMPLE = 1 .endif .ifdef MBGDEVIO_SIMPLE CPPFLAGS += -DMBGDEVIO_SIMPLE=$(MBGDEVIO_SIMPLE) .endif .ifdef USE_THREAD_API # Check whether thread affinity is supported by the installed pthread library. # Newer versions of glibc/pthread (at least glibc 2.5) supports this natively. # Older versions of glibc/pthread (e.g. glibc 2.3) may not support this natively # but may provide a NPTL (New Posix Thread Library) library located under separate # include and lib paths. We try to detect NPTL and add those paths to the search # paths only if USE_NTPL has been defined e.g. on the make command line. # Check whether pthread_getaffinity is supported by the standard pthread.h USE_THREAD_AFFINITY := $(shell grep -q pthread_getaffinity /usr/include/pthread.h && echo 1) # If it is not, check nptl/pthread.h .ifndef USE_THREAD_AFFINITY .ifdef USE_NPTL USE_THREAD_AFFINITY := $(shell grep -q pthread_getaffinity /usr/include/nptl/pthread.h && echo 1) .endif .ifndef USE_THREAD_AFFINITY ##++++ If not found either, don't support thread affinity USE_THREAD_AFFINITY=0 .else #if supported via nptl add the associated search paths CPPFLAGS += -I /usr/include/nptl -L /usr/lib/nptl .endif .endif # May want to use the result for our program ## CPPFLAGS += -DUSE_THREAD_AFFINITY=$(USE_THREAD_AFFINITY) CPPFLAGS += -DMBGDEVIO_USE_THREAD_API=1 #LDFLAGS += -lpthread LDFLAGS += -pthread .endif .ifdef INST_TO_BIN INST_DIR = $(DESTDIR)$(bindir) .else .ifdef INST_TO_SBIN INST_DIR = $(DESTDIR)$(sbindir) .else .ifdef INST_TO_LIB INST_DIR = $(DESTDIR)$(libdir) .else .ifdef INST_TO_INCLUDE INST_DIR = $(DESTDIR)$(includedir)/mbglib .endif .endif .endif .endif .ifdef DO_GUI_INSTALLATION EXT_INSTALL += gui_install EXT_UNINSTALL += gui_uninstall .endif ## $(warning $(INFO) CPPFLAGS=$(CPPFLAGS)) ## $(warning $(INFO) EXTRA_CPPFLAGS=$(EXTRA_CPPFLAGS)) ## $(warning $(INFO) MAKECMDGOALS = $(MAKECMDGOALS)) $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LDFLAGS) .ifdef SO_TARGET_LIBNAME ln -sf $(TARGET) $(SO_TARGET_LIBNAME) .endif .PHONY: install install: $(EXT_INSTALL) .ifdef XXX #.ifneq ($(UID),0) $(call make_as_root, $@) .else .ifdef INCLUDE_FILES #include files mkdir -p $(INST_DIR) for incfile in $(INCLUDE_FILES); do \ install -m 644 $(BASEDIR)/mbglib/common/$$incfile $(INST_DIR)/; \ done; for basename in $(SO_BASENAMES); do \ pushd $(DESTDIR)$(libdir); \ ln -sf libmbg$$basename.so.$(SO_MAJOR_VERSION) libmbg$$basename.so; \ popd; \ done; .else #usual installation .ifdef CALLED_FROM_SPEC mkdir -p $(INST_DIR) .endif install -s $(TARGET) $(INST_DIR) .ifndef CALLED_FROM_SPEC .ifdef INST_TO_LIB /sbin/ldconfig .endif .endif .endif .endif .PHONY: uninstall uninstall: $(EXT_UNINSTALL) .ifdef INCLUDE_FILES #remove include files and rm -rf $(INST_DIR) .ifndef CALLED_FROM_SPEC #remove symbolic links for basename in $(SO_BASENAMES); do \ rm -f $(libdir)/libmbg$$basename.so; \ done; .endif .else .ifdef XXX #.ifneq ($(UID),0) $(call make_as_root, $@) .else rm -f $(INST_DIR)/$(TARGET) .ifndef CALLED_FROM_SPEC .ifdef INST_TO_LIB /sbin/ldconfig .endif .endif .endif .endif .PHONY: gui_install gui_install: .ifdef XXX #.ifneq ($(UID),0) $(call make_as_root, $@) .else mkdir -p $(DESTDIR)$(prefix)/share/$(TARGET) cp $(TARGET).png $(DESTDIR)$(prefix)/share/$(TARGET)/$(TARGET).png mkdir -p $(DESTDIR)$(prefix)/share/applications cp $(TARGET).desktop $(DESTDIR)$(prefix)/share/applications/$(TARGET).desktop .endif .PHONY: gui_uninstall gui_uninstall: .ifdef XXX #.ifneq ($(UID),0) $(call make_as_root, $@) .else rm -rf $(DESTDIR)$(prefix)/share/$(TARGET) rm -f $(DESTDIR)$(prefix)/share/applications/$(TARGET).desktop .endif CLEAN_FILES += *.o CLEAN_FILES += *~ CLEAN_FILES += core CLEAN_FILES += $(TARGET) .PHONY: clean clean: .ifdef CLEAN_FILES rm -f $(CLEAN_FILES) .endif .ifdef CLEAN_DIRS rm -rf $(CLEAN_DIRS) .endif .else # ===== Building a kernel module ============================================= USE_FORT?= yes # network client/server # WARNS?= 5 .include CPPFLAGS += ${INCLUDES} ## .if defined(DEBUG) ## CPPFLAGS += -DDEBUG=${DEBUG} ## .endif .if defined(MBG_DEBUG) CPPFLAGS += -DMBG_DEBUG=${MBG_DEBUG} .endif .PATH: ${MBGLIB_COMMON} ${MBGLIB_BSD} MKMAN=no .if !defined (MKMODULAR) || ( defined(MKMODULAR) && (${MKMODULAR}!="no") ) .include .else .include .endif .endif # building kernel module #================================================================================== # common targets: .PHONY: distclean distclean: clean .endif