]> rtime.felk.cvut.cz Git - orte.git/commitdiff
Update OMK makefiles and rules
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 4 Oct 2013 08:56:42 +0000 (10:56 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 4 Oct 2013 08:56:42 +0000 (10:56 +0200)
23 files changed:
Makefile
Makefile.rules
orte/Makefile
orte/contrib/Makefile
orte/contrib/decoder/Makefile
orte/examples/Makefile
orte/examples/hello/Makefile
orte/examples/mpo/Makefile
orte/examples/mpo/ddso/Makefile
orte/examples/multicast/Makefile
orte/examples/ping/Makefile
orte/examples/reliable/Makefile
orte/examples/rtems-shell/Makefile
orte/examples/schneider/Makefile
orte/examples/spy/Makefile
orte/idl-compiler/Makefile
orte/idl-compiler/Makefile.rules
orte/include/Makefile
orte/java/Makefile
orte/libjorte/Makefile
orte/liborte/Makefile
orte/liborte/rtl/Makefile
orte/manager/Makefile

index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index 1458619e30c2cc83e9c058a0a1f9b3092cf6465a..b0db575da72e86dcc9f5f01904acba99d4a2b68e 100644 (file)
@@ -4,7 +4,7 @@
 #  (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011 by Michal Sojka - Czech Technical University, FEE, DCE
 #
 #  Homepage: http://rtime.felk.cvut.cz/omk/
-#  Version:  0.2-97-g532aeb1
+#  Version:  0.2-109-g87787c0
 #
 # The OMK build system is distributed under the GNU General Public
 # License.  See file COPYING for details.
@@ -568,9 +568,9 @@ endif
 
 ifdef USER_RULE_TEMPLATES
 
-USER_SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.S .o/.o
+USER_SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.cpp .o/.S .o/.o
 
-USER_SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.S .lo/.lo
+USER_SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.cpp .lo/.S .lo/.lo
 
 #%.lo: %.c
 #      $(CC) -o $@ $(LCFLAGS) -c $<
@@ -579,7 +579,7 @@ c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
 
 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
-       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(CXXFLAGS) -DOMK_FOR_USER
 
 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
@@ -689,7 +689,7 @@ USER_SOURCES += $$($(1)_SOURCES)
 
 $(2)/$(1)$(3): $$($(1)_OBJS)
        @$(QUIET_CMD_ECHO) "  LINK    $$@"
-       $(Q) $$(if $$(filter %.cc,$$($(1)_SOURCES:%.cxx=%.cc)),$$(CXX),$$(CC)) \
+       $(Q) $$(if $$(filter %.cc,$$($(1)_SOURCES))$$(filter %.cxx,$$($(1)_SOURCES))$$(filter %.cpp,$$($(1)_SOURCES)),$$(CXX),$$(CC)) \
          $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(LDFLAGS) $$($(1)_LDFLAGS) -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$@
        @echo "$(2)/$(1)$(3): \\" >$(USER_OBJS_DIR)/$(1).exe.d
        @$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(USER_OBJS_DIR)/$(1).exe.map|tr '&' '\134'  >>$(USER_OBJS_DIR)/$(1).exe.d
@@ -994,6 +994,7 @@ define MODULE_kern_template
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cpp=%.o))
 $(1)_OBJS := $$(sort $$($(1)_OBJS))
 
 KERN_OBJS  += $$($(1)_OBJS)
@@ -1046,6 +1047,7 @@ define LIBRARY_kern_template
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cpp=%.o))
 $(1)_OBJS := $$(sort $$($(1)_OBJS))
 
 KERN_OBJS  += $$($(1)_OBJS)
@@ -1177,6 +1179,8 @@ $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template
 
 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
 
+$(foreach src,$(filter %.cpp,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cpp=%.o),)))
+
 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
 
 $(foreach src,$(filter %.c,$(USER_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),)))
@@ -1196,6 +1200,8 @@ $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_templat
 
 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
 
+$(foreach src,$(filter %.cpp,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cpp=%.lo),$(SOLIB_PICFLAGS))))
+
 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
 
 $(foreach src,$(filter %.c,$(SOLIB_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
@@ -1226,6 +1232,8 @@ $(foreach src,$(filter %.cc,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_tem
 
 $(foreach src,$(filter %.cxx,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
 
+$(foreach src,$(filter %.cpp,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.cpp=%.o),)))
+
 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
 endif
 
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index 2b864d288424717fe1313733c3de8a6921dae699..b0db575da72e86dcc9f5f01904acba99d4a2b68e 100644 (file)
@@ -1,23 +1,27 @@
-#                   Version for Linux/RTLinux builds.        #OMK@linux
+#  Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*- #OMK:base.omk
 #
-#  Makefile.rules - OCERA make framework common project rules -*- makefile -*- #OMK@base
-#
-#  (C) Copyright 2003 by Pavel Pisa - OCERA team member
-#  (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
+#  (C) Copyright 2003, 2006, 2007, 2008, 2009  by Pavel Pisa - OCERA team member
+#  (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011 by Michal Sojka - Czech Technical University, FEE, DCE
 #
 #  Homepage: http://rtime.felk.cvut.cz/omk/
+#  Version:  0.2-109-g87787c0
 #
 # The OMK build system is distributed under the GNU General Public
 # License.  See file COPYING for details.
 #
-# input variables
+#
+#                   Version for Linux/RTLinux builds.                            #OMK:linux.omk
+#
+#
+# input variables                                                                #OMK:base.omk
 # V                .. if set to 1, full command text is shown else short form is used
 # W                .. whole tree - if set to 1, make is always called from the top-level directory
 # SUBDIRS          .. list of subdirectories intended for make from actual directory
 # default_CONFIG   .. list of default config assignments CONFIG_XXX=y/n ...
-# LN_HEADERS       .. if "y", header files are symbolicaly linked instead of copied. #OMK@include
-#                                                            #OMK@linux
-# input variables
+# wvtest_SCRIPTS    .. list of scripts producing wvtest output                   #OMK:wvtest.omk
+# wvtest_PROGRAMS   .. list of the testing programs producing wvtest output
+# LN_HEADERS       .. if "y", header files are symbolicaly linked instead of copied. #OMK:include.omk
+# input variables                                                                #OMK:linux.omk
 # lib_LIBRARIES    .. list of the user-space libraries
 # shared_LIBRARIES .. list of the user-space shared libraries
 # kernel_LIBRARIES .. list of the kernel-space libraries
 # bin_PROGRAMS     .. list of the require binary programs
 # utils_PROGRAMS   .. list of the development utility programs
 # test_PROGRAMS    .. list of the testing programs
+# bin_SCRIPTS      .. list of scripts to be copied to _compiled/bin
 # kernel_MODULES   .. list of the kernel side modules/applications
 # rtlinux_MODULES  .. list of RT-Linux the kernel side modules/applications
 # xxx_SOURCES      .. list of specific target sources
-# xxx_LIBS         .. list of specific target libraries
+# xxx_LIBS         .. list of specific target libraries (-l prefix is automatically added)
+# xxx_LDFLAGS      .. list of specific target LDFLAGS
+# lib_LOADLIBES    .. list of libraries linked to each executable
 # INCLUDES         .. additional include directories and defines for user-space
 # kernel_INCLUDES  .. additional include directories and defines for kernel-space
 # rtlinux_INCLUDES .. additional include directories and defines for RT-Linux
@@ -45,7 +52,7 @@
 # CXXFLAGS         .. C++ compiler flags
 # CPPFLAGS        .. C preprocessor flags
 # LDFLAGS         .. linker flags for programs linking
-# LOCAL_CONFIG_H   .. name of local config.h file generated from values #OMK@config_h
+# LOCAL_CONFIG_H   .. name of local config.h file generated from values          #OMK:config_h.omk
 #                     of options defined in the current directory
 # config_include_HEADERS .. names of global config files (possibly
 #                     with subdirectories)
 # DOXYGEN          .. if non-empty, generated headers includes Doxygen's @file
 #                    command, so it is possible to document config
 #                    variables.
-# QT_SUBDIRS       .. subdirectories where to build QT applications using qmake #OMK@qt
+# QT_PROJECTS     .. list of QT .pro file to use for compilation                  #OMK:qt.omk
+# QT_SUBDIRS       .. subdirectories where to build QT applications using qmake (depricated)
 # QTDIR                   .. where QT resides
-OMK_RULES_TYPE=linux                                         #OMK@__type
-                                                             #OMK@base
-# We need to ensure definition of sources directory first
-ifndef SOURCES_DIR
-# Only shell built-in pwd understands -L
-SOURCES_DIR := $(shell ( pwd -L ) )
-endif
-
+OMK_RULES_TYPE=linux                                                             #OMK:Makefile.rules.linux@
+                                                                                 #OMK:base.omk@Makefile.rules.linux
 # If we are not called by OMK leaf Makefile...
 ifndef MAKERULES_DIR
 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
 endif
 
+# The $(SED4OMK) command for BSD based systems requires -E option to allow
+# extended regular expressions
+
+SED4OMK ?= sed
+ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
+  SED4OMK := $(SED4OMK) -E
+  ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
+    SED4OMK := gsed
+  endif
+  ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
+    SED4OMK := gsed -E
+  endif
+  ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
+    $(error No SED program suitable for OMK found)
+  endif
+endif
+
 # OUTPUT_DIR is the place where _compiled, _build and possible other
 # files/directories are created. By default is the same as
 # $(MAKERULES_DIR).
@@ -76,7 +95,16 @@ ifndef OUTPUT_DIR
 OUTPUT_DIR := $(MAKERULES_DIR)
 endif
 
-.PHONY: all default check-make-ver omkize
+# We need to ensure definition of sources directory first
+ifndef SOURCES_DIR
+# Only shell built-in pwd understands -L
+SOURCES_DIR := $(shell ( pwd -L ) )
+INVOCATION_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
+INVOCATION_DIR := $(INVOCATION_DIR:/%=%)
+INVOCATION_DIR := $(INVOCATION_DIR:\\%=%)
+endif
+
+.PHONY: all default check-make-ver print-hints omkize
 
 ifdef W
   ifeq ("$(origin W)", "command line")
@@ -88,7 +116,7 @@ ifndef OMK_WHOLE_TREE
 endif
 
 ifneq ($(OMK_WHOLE_TREE),1)
-all: check-make-ver default
+all: check-make-ver print-hints default
        @echo "Compilation finished"
 else
 # Run make in the top-level directory
@@ -96,48 +124,41 @@ all:
        @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
 endif
 
-ifdef OMK_TESTSROOT
-# Usage: $(call canttest,<error message>)
-define canttest
-       ( echo "$(1)" > $(OUTPUT_DIR)/_canttest; echo "$(1)"; exit 1 )
-endef
-else
-define canttest
-       echo "$(1)"
-endef
-endif
+# omk-get-var target allows external scripts/programs to determine the
+# values of OMK variables such as RELATIVE_DIR etc.
+.PHONY: omk-get-var
+omk-get-var:
+       @$(foreach var,$(VAR),echo $(var)=$($(var));)
 
 #=========================
 # Include the config file
 
-# FIXME: I think CONFIG_FILE_OK variable is useless. We have three
-# config files and it is not clearly defined to which file is this
-# variable related.
-ifneq ($(CONFIG_FILE_OK),y)
 ifndef CONFIG_FILE
 CONFIG_FILE      := $(OUTPUT_DIR)/config.omk
 endif
-ifneq ($(wildcard $(CONFIG_FILE)-default),)
--include $(CONFIG_FILE)-default
-else
-ifneq ($(MAKECMDGOALS),default-config)
-$(warning Please, run "make default-config" first)
+
+$(CONFIG_FILE)-default:
+       $(MAKE) default-config 
+
+ifeq ($(MAKECMDGOALS),default-config)
+export DEFAULT_CONFIG_PASS=1
 endif
+
+ifneq ($(DEFAULT_CONFIG_PASS),1)
+include $(CONFIG_FILE)-default
 endif
 
 -include $(OUTPUT_DIR)/config.target
 
 ifneq ($(wildcard $(CONFIG_FILE)),)
 -include $(CONFIG_FILE)
-CONFIG_FILE_OK = y
 endif
-endif #$(CONFIG_FILE_OK)
 
 
 CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
 
 
-export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
+export SED4OMK SOURCES_DIR MAKERULES_DIR RELATIVE_DIR INVOCATION_DIR
 export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
 # OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
 # must to be serialized only in the toplevel make.
@@ -149,7 +170,7 @@ endif
 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
 #$(warning  RELATIVE_DIR = "$(RELATIVE_DIR)")
-override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
+#override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | $(SED4OMK) -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
 #$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
 
 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
@@ -204,10 +225,13 @@ endif
 OMK_INCLUDED := 1
 endif
 
+print-hints:
+       @echo 'Use "make V=1" to see the verbose compile lines.'
+
 check-make-ver:
-       @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
+       @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | $(SED4OMK) -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
        if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
-               echo "Your make program version is too old and does not support OMK system." ; \
+               echo "Your make program version ($(MAKE_VERSION)) is too old and does not support OMK system." ; \
                echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
        fi
 
@@ -238,18 +262,21 @@ endif
 
 pass = $(strip $(1))
 
+unexport SUBDIRS
+
 # Call a pass in a subdirectory
 # Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
 define omk_pass_subdir_template
 .PHONY: $(pass)-$(3)-subdir
 $(pass)-submakes: $(pass)-$(3)-subdir
+$(pass)-$(3)-subdir: MAKEOVERRIDES:=$(filter-out SUBDIRS=%,$(MAKEOVERRIDES))
 $(pass)-$(3)-subdir:
        @$(call mkdir_def,$(2)/$(3))
-       +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
+       +@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
                RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
                -f $(SUBDIR_MAKEFILE) $(pass)-submakes
 # In subdirectories we can call submakes directly since passes are
-# already searialized on the toplevel make.
+# already serialized on the toplevel make.
 endef
 
 ifdef OMK_TESTSROOT
@@ -277,7 +304,7 @@ $(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),
 $(pass):
 # Submakes have to be called this way and not as dependecies for pass
 # serialization to work
-       +@$(MAKE) SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
+       +@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
                RELATIVE_DIR=$(RELATIVE_DIR) \
                -f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
 $(pass)-submakes:
@@ -288,7 +315,7 @@ $(pass)-submakes: $(pass)-this-dir
 $(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
        +@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
        @$(call mkdir_def,$(2))
-       +@$(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
+       +@$(MAKE) --no-builtin-rules $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
                -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
 $(pass)-local: $($(pass)_HOOKS)
 endif
@@ -312,7 +339,7 @@ default-config-pass-local:
 #      @echo Default config for $(RELATIVE_DIR)
        @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
        @$(foreach x, $(default_CONFIG), echo '$(x)' | \
-               sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
+               $(SED4OMK) -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
 
 
 omkize:
@@ -321,23 +348,71 @@ omkize:
        fi
        $(Q)for i in `find -L . -name Makefile.omk` ; do \
           d=`dirname $${i}`; \
-          if ! test -f "$${d}/Makefile.rules" && ( ! test -f "$${d}/Makefile" || ! cmp --silent Makefile "$${d}/Makefile" ); then \
+          if ! test -f "$${d}/Makefile.rules" && ( test -f "$${d}/Makefile" && ! cmp --silent Makefile "$${d}/Makefile" ); then \
              rm -f "$${d}/Makefile"; \
              cp -v Makefile "$${d}/Makefile"; \
           fi \
        done
-ifeq ($(OMK_VERBOSE),1)                                      #OMK@include
+                                                                                 #OMK:wvtest.omk@Makefile.rules.linux
+ifndef WVTEST_LIBRARY
+WVTEST_LIBRARY = wvtest
+endif
+
+# Documentation: wvtest_PROGRAMS is amost equivalent to test_PROGRAMS.
+# The two differences are that the program is automatically linked
+# with $(WVTEST_LIBRARY) and it is run during "make wvtest".
+test_PROGRAMS += $(wvtest_PROGRAMS)
+
+# Documentation: If your project uses wvtest, it is recomended to put
+# the "test: wvtest" rule to config.target.
+wvtest:
+       $(Q)$(MAKERULES_DIR)/wvtestrun $(MAKE) wvtest-pass
+
+.PHONY: wvtest
+
+$(eval $(call omk_pass_template,wvtest-pass,$$(LOCAL_BUILD_DIR),,$(wvtest_SCRIPTS)$(wvtest_PROGRAMS)))
+
+# Usage: $(call wvtest_template,<shell command>)
+define wvtest_template
+wvtest-pass-local: wvtest-run-$(1)
+.PHONY: wvtest-run-$(1)
+wvtest-run-$(1):
+       $(Q)echo "Testing \"Run $(1)\" in Makefile.rules:"
+       $(Q)mkdir -p $(1).wvtest
+       $(Q)cd $(1).wvtest && \
+         PATH=$$(USER_BIN_DIR):$$$$PATH LD_LIBRARY_PATH=$$(USER_LIB_DIR):$$$$LD_LIBRARY_PATH \
+         $(1)
+$(notdir $(1))_LIBS += $$(WVTEST_LIBRARY)
+endef
+
+# Documentation: Write the test so, that it can be run from arbitrary
+# directory, i.e. in case of a script ensure that the wvtest library
+# is sourced like this:
+#
+# . $(dirname $0)/wvtest.sh
+
+$(foreach script,$(wvtest_SCRIPTS),$(eval $(call wvtest_template,$(SOURCES_DIR)/$(script))))
+# Hack!!!
+USER_TESTS_DIR := $(OUTPUT_DIR)/_compiled/bin-tests
+$(foreach prog,$(wvtest_PROGRAMS),$(eval $(call wvtest_template,$(USER_TESTS_DIR)/$(prog))))
+ifeq ($(OMK_VERBOSE),1)                                                          #OMK:include.omk@Makefile.rules.linux
 CPHEADER_FLAGS += -v
 LNHEADER_FLAGS += -v
 endif
 
 ifneq ($(LN_HEADERS),y)
 define cp_cmd
-( echo "  CP      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) )
+if ! cmp --quiet $(1) $(2); then \
+    echo "  CP      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
+    install -D $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \
+fi
 endef
 else
 define cp_cmd
-( echo "  LN      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; [ -f $(1) ] && ln -sf $(LNHEADER_FLAGS) $(1) $(2) )
+if ! cmp --quiet $(1) $(2); then \
+    echo "  LN      $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
+    if [ -f $(1) ]; then d=$(2); mkdir -p $${d%/*} && ln -sf $(LNHEADER_FLAGS) $(1) $(2) || exit 1; else exit 1; fi; \
+fi
 endef
 endif
 
@@ -347,27 +422,21 @@ endif
 # Syntax: $(call include-pass-template,<include dir>,<keyword>)
 define include-pass-template
 include-pass-local: include-pass-local-$(2)
-include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'))
-       @$$(foreach f, $$($(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(notdir $$(f)) \
-          || $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; )
-       @$$(foreach f, $$($(2)_GEN_HEADERS), cmp --quiet $$(f) $(1)/$$(notdir $$(f)) \
-          || $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))) || exit 1 ; ) # FIXME: Use correct build dir, then document it
-       @$$(foreach f, $$(nobase_$(2)_HEADERS), cmp --quiet $$(SOURCES_DIR)/$$(f) $(1)/$$(f) \
-          || ( mkdir -p $(1)/$$(dir $$(f)) && $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)) ) || exit 1 ; )
+include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell f='$$(f)'; echo $$$${f%->*}))
+       @$$(foreach f, $$($(2)_HEADERS),$$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
+# FIXME: Use correct build dir, then document it (in the line bellow)
+       @$$(foreach f, $$($(2)_GEN_HEADERS),$$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
+       @$$(foreach f, $$(nobase_$(2)_HEADERS), $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)); )
        @$$(foreach f, $$(renamed_$(2)_HEADERS), \
-          srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
-          cmp --quiet $$(SOURCES_DIR)/$$$${srcfname} $(1)/$$$${destfname} \
-          || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
+          f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
+          $$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
        @$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
-          srcfname=`echo '$$(f)' | sed -e 's/^\(.*\)->.*$$$$/\1/'` ; destfname=`echo '$$(f)' | sed -e 's/^.*->\(.*\)$$$$/\1/'` ; \
-          cmp --quiet $$$${srcfname} $(1)/$$$${destfname} \
-          || ( mkdir -p `dirname $(1)/$$$${destfname}` && $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}) ) || exit 1 ; )
+          f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
+          $$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
+# Suppress "Nothing to be done for `include-pass-local'" message if no headers are defined in Makefile.omk
+       @$$(if $$($(2)_HEADERS)$$($(2)_GEN_HEADERS)$$(nobase_$(2)_HEADERS)$$(renamed_$(2)_HEADERS)$$(renamed_$(2)_GEN_HEADERS),,true)
 endef
-
-# Local Variables:
-# mode:makefile
-# End:
-                                                             #OMK@linux
+                                                                                 #OMK:linux.omk@Makefile.rules.linux
 # Hack to check RT-Linux rules
 #LINUX_DIR := /home/cvs/ocera/ocera-build/kernel/linux
 #RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
@@ -442,6 +511,7 @@ ifeq ($(TARGET_OS),)
 endif
 
 export TARGET_OS
+export BUILD_OS
 
 LOCAL_BUILD_DIR  = $(USER_OBJS_DIR)
 
@@ -450,6 +520,7 @@ LOCAL_BUILD_DIR  = $(USER_OBJS_DIR)
 CFLAGS ?= -O2 -Wall
 CXXFLAGS ?= -O2 -Wall
 
+
 CPPFLAGS  += -I $(USER_INCLUDE_DIR)
 
 LOADLIBES += -L$(USER_LIB_DIR) 
@@ -460,22 +531,20 @@ LIB_CPPFLAGS += $(CPPFLAGS)
 LIB_CFLAGS   += $(CFLAGS)
 
 ifeq ($(TARGET_OS),win32)
+  EXE_SUFFIX = .exe
   SOLIB_EXT = dll
 else
   SOLIB_EXT = so
   SOLIB_PICFLAGS += -fpic
 endif
 
-ifeq ($(TARGET_OS),win32)
-OMIT_KERNEL_PASSES=1
-endif
-
 #vpath %.c $(SOURCES_DIR)
 #vpath %.cc $(SOURCES_DIR)
 #vpath %.cxx $(SOURCES_DIR)
 
 USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
 KERN_OBJS_DIR = $(KERN_BUILD_DIR)/$(RELATIVE_DIR)
+OMK_WORK_DIR  = $(USER_OBJS_DIR)
 
 .PHONY: dep subdirs clean clean-custom cleandepend check-dir
 
@@ -483,7 +552,8 @@ KERN_OBJS_DIR = $(KERN_BUILD_DIR)/$(RELATIVE_DIR)
 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
 include-pass: check-dir
 library-pass: include-pass
-binary-pass: library-pass
+link-pseudo-pass: library-pass
+binary-pass: link-pseudo-pass
 kernel-lib-pass: include-pass
 kernel-mod-pass: kernel-lib-pass
 kernel-modpost-pass: kernel-mod-pass
@@ -493,21 +563,14 @@ override OMK_SERIALIZE_INCLUDED = y
 MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
 endif
 
-# Checks for OMK tester
-ifdef OMK_TESTSROOT
-default-config-pass-check include-pass-check:
-library-pass-check binary-pass-check:
-       @[ -x "$(shell which $(CC))" ] || $(call canttest,Cannot find compiler: $(CC))
-endif
-
 #=====================================================================
 # User-space rules and templates to compile programs, libraries etc.
 
 ifdef USER_RULE_TEMPLATES
 
-USER_SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.S .o/.o
+USER_SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.cpp .o/.S .o/.o
 
-USER_SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.S .lo/.lo
+USER_SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.cpp .lo/.S .lo/.lo
 
 #%.lo: %.c
 #      $(CC) -o $@ $(LCFLAGS) -c $<
@@ -516,7 +579,7 @@ c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
 
 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
-       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
+       $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(CXXFLAGS) -DOMK_FOR_USER
 
 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
@@ -525,7 +588,7 @@ idl_COMPILE = $(IDL_COMPILER)
 
 # Check GCC version for user build
 ifndef CC_MAJOR_VERSION
-CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
+CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
 endif
 # Prepare suitable define for dependency building
 ifeq ($(CC_MAJOR_VERSION),2)
@@ -567,6 +630,7 @@ $(2): $(1) $$(GEN_HEADERS)
        fi
 endef
 
+NM ?= nm
 
 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
 define CMETRIC_o_h_template
@@ -575,23 +639,30 @@ $(2): $(1)
        $(Q)if [ -n `dirname $$@` ] ; then \
              if [ ! -e `dirname $$@` ] ; then \
                mkdir -p `dirname $$@` ; fi ; fi
-       $(Q)echo >$$@ '/* Automatically generated from $$< */'
-       $(Q)echo >>$$@ '/* Conditionals to control compilation */'
-       $(Q)set -o pipefail ; $(NM) $$< \
-               | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
-               | sort >>$$@
-       $(Q)echo >>$$@ '/* Defines from the values defined to symbols */'
-       $(Q)set -o pipefail ; $(NM) $$< \
-               | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
-               | sort >>$$@
+       $(Q)echo >$$@.tmp '/* Automatically generated from $$< */'
+       $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */'
+# Bellow, the tricks with redirection are for shells without set -o pipefail
+# (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html)
+       $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
+               | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
+               | sort >>$$@.tmp` && exit $$$$status
+       $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */'
+       $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
+               | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
+               | sort >>$$@.tmp` && exit $$$$status
+       $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */'
+       $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\
+               | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
+               | sort >>$$@.tmp` && exit $$$$status
+       $(Q)mv $$@.tmp $$@
 endef
 
 
 
 define COMPILE_idl_template
-$(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1)
+$(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) $$(wildcard $$(firstword $$(idl_COMPILE)))
        @$(QUIET_CMD_ECHO) "  IDL     $$@"
-       $(Q) $$(idl_COMPILE) $(1)
+       $(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1)
 endef
 
 
@@ -618,13 +689,20 @@ USER_SOURCES += $$($(1)_SOURCES)
 
 $(2)/$(1)$(3): $$($(1)_OBJS)
        @$(QUIET_CMD_ECHO) "  LINK    $$@"
-       $(Q) $$(if $$(filter %.cc,$$($(1)_SOURCES:%.cxx=%.cc)),$$(CXX),$$(CC)) \
-         $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(LDFLAGS) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$@
+       $(Q) $$(if $$(filter %.cc,$$($(1)_SOURCES))$$(filter %.cxx,$$($(1)_SOURCES))$$(filter %.cpp,$$($(1)_SOURCES)),$$(CXX),$$(CC)) \
+         $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(LDFLAGS) $$($(1)_LDFLAGS) -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$@
        @echo "$(2)/$(1)$(3): \\" >$(USER_OBJS_DIR)/$(1).exe.d
-       @sed -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(USER_OBJS_DIR)/$(1).exe.map|tr '&' '\134'  >>$(USER_OBJS_DIR)/$(1).exe.d
+       @$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(USER_OBJS_DIR)/$(1).exe.map|tr '&' '\134'  >>$(USER_OBJS_DIR)/$(1).exe.d
        @echo >>$(USER_OBJS_DIR)/$(1).exe.d
 endef
 
+# Usage: $(call SCRIPT_template,<target-directory>,<script-name>)
+define SCRIPT_template
+$(2)/$(1): $$(SOURCES_DIR)/$(1)
+       @$(QUIET_CMD_ECHO) "  CP      $$@"
+       $(Q)cp $$^ $$@
+endef
+
 
 # Syntax: $(call LIBRARY_template,<library-name>)
 define LIBRARY_template
@@ -651,6 +729,7 @@ $(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
        $(Q) $(AR) rcs $$@ $$^
 endef
 
+.PHONY: FORCE
 
 # Syntax: $(call SOLIB_template,<library-name>)
 define SOLIB_template
@@ -672,17 +751,21 @@ $(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%))
 SOLIB_OBJS  += $$($(1)_OBJSLO)
 SOLIB_SOURCES += $$($(1)_SOURCES)
 
-$(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT): $$($(1)_OBJSLO)
-       @$(QUIET_CMD_ECHO) "  LINK    $$@"
-       $(Q) $(CC) --shared -Xlinker -soname=lib$(1).$(SOLIB_EXT) -o $$@ $$^ $$(LOADLIBES) $$($(1)_LIBS:%=-l%)
+$(OMK_WORK_DIR)/lib$(1).$(SOLIB_EXT).omkvar: $$($(1)_OBJSLO) FORCE
+       $(Q)echo '$(1)_objslo += $$$$(addprefix $(USER_OBJS_DIR)/,$$($(1)_OBJSLO))' > $$@.tmp; \
+           echo '$(1)_libs += $$($(1)_LIBS) $$(lib_LOADLIBES)' >> $$@.tmp; \
+           echo '$(1)_ldflags += $$($(1)_LDFLAGS) $$(lib_LDFLAGS)' >> $$@.tmp; \
+           echo 'shared_libs := $$$$(sort $(1) $$$$(shared_libs))' >> $$@.tmp; \
+           if cmp -s $$@.tmp $$@; then rm $$@.tmp; else mv $$@.tmp $$@; fi
 endef
 
-
-
 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
-                   $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(USER_LIB_DIR)/lib%.$(SOLIB_EXT))
+                   $(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(OMK_WORK_DIR)/lib%.$(SOLIB_EXT).omkvar)
 
-binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%$(EXE_SUFFIX)) $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%$(EXE_SUFFIX)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%$(EXE_SUFFIX))
+binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%$(EXE_SUFFIX)) \
+                  $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%$(EXE_SUFFIX)) \
+                  $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%$(EXE_SUFFIX)) \
+                  $(bin_SCRIPTS:%=$(USER_BIN_DIR)/%)
 
 # Special rules for CMETRIC generated headers
 
@@ -705,13 +788,42 @@ $(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TE
 
 $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(EXE_SUFFIX))))
 
+$(foreach script,$(bin_SCRIPTS),$(eval $(call SCRIPT_template,$(script),$(USER_BIN_DIR))))
+
+
 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
 
 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
 
 -include $(USER_OBJS_DIR)/*.d
+#FIXME: This doesn't include dependencies of source files from
+#subdirectories (i.s. *_SOURCES=dir/file.c. I'm currently not sure,
+#how to handle this.
 
-endif
+endif # USER_RULE_TEMPLATES
+
+.PHONY: link-pseudo-pass
+link-pseudo-pass:
+       $(Q)$(MAKE) $(NO_PRINT_DIRECTORY) -C $(USER_BUILD_DIR) -f $(SOURCESDIR_MAKEFILE) link-shared-libs
+
+ifeq ($(MAKECMDGOALS),link-shared-libs)
+
+# Syntax: $(call solib_link_template,<library-name>)
+define solib_link_template
+$(1)_shared_libs = $$(patsubst %,$(USER_LIB_DIR)/lib%.$(SOLIB_EXT),$$(filter $$(shared_libs),$$($(1)_libs)))
+#$$(warning $(1)_shared_libs = $$($(1)_shared_libs))
+$(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT): $$($(1)_shared_libs) $$($(1)_objslo)
+       @$(QUIET_CMD_ECHO) "  LINK    $$@"
+       $(Q)$(CC) --shared -Xlinker -soname=lib$(1).$(SOLIB_EXT) -Wl,-Map,$(USER_OBJS_DIR)/lib$(1).$(SOLIB_EXT).map -o $$@ $$($(1)_objslo) $$(LOADLIBES) $$($(1)_libs:%=-l%) $$(lib_ldflags) $$($(1)_ldflags)
+endef
+
+-include $(shell true; find $(USER_BUILD_DIR) -name 'lib*.omkvar') # `true' is a hack for MinGW
+#$(warning $(shared_libs))
+$(foreach lib,$(shared_libs),$(eval $(call solib_link_template,$(lib))))
+
+.PHONY: link-shared-libs
+link-shared-libs: $(shared_libs:%=$(USER_LIB_DIR)/lib%.$(SOLIB_EXT))
+endif # link-shared-libs
 
 #=====================================================================
 # Kernel-space rules and templates to compile modules, libraries etc.
@@ -719,14 +831,14 @@ endif
 ifdef KERN_RULE_TEMPLATES
 
 $(KERN_LIB_DIR)/kernel.mk: $(LINUX_DIR)/.config $(MAKERULES_DIR)/kernelcfg2mk
-       @$(QUIET_CMD_ECHO) "  KCFG2MK $$@"
+       @$(QUIET_CMD_ECHO) "  KCFG2MK $@"
        $(Q) $(MAKERULES_DIR)/kernelcfg2mk $(LINUX_DIR) $(KERN_LIB_DIR)
 
 ifeq ($(CONFIG_RTLINUX),y)
 include $(RTL_DIR)/rtl.mk
 
 KERN_CC = $(CC)
-kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(CC) -print-search-dirs | sed -n -e 's/^install: \(.*\)$$/\1/p' )
+kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(CC) -print-search-dirs | $(SED4OMK) -n -e 's/^install: \(.*\)$$/\1/p' )
 INCLUDES := -I $(KERN_INCLUDE_DIR) $(INCLUDE) $(rtlinux_INCLUDES) $(kernel_INCLUDES)
 #-DEXPORT_NO_SYMBOLS
 c_o_kern_COMPILE = $(KERN_CC) -idirafter $(kern_GCCLIB_DIR)/include $(INCLUDES)  $(CFLAGS) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
@@ -743,19 +855,19 @@ include $(KERN_LIB_DIR)/kernel.mk
 ifeq ($(LINUX_SRC),)
 LINUX_SRC = $(LINUX_DIR)
 endif
-kernel_INCLUDES += -I $(LINUX_DIR) -idirafter $(LINUX_SRC)/include/linux
+kernel_INCLUDES += -I $(KERN_INCLUDE_DIR) -I $(LINUX_DIR) -idirafter $(LINUX_SRC)/include/linux
 
 ifdef LINUX_CC
 KERN_CC = $(LINUX_CC)
-kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(LINUX_CC) -print-search-dirs | sed -n -e 's/^install: \(.*\)$$/\1/p' )
+kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(LINUX_CC) -print-search-dirs | $(SED4OMK) -n -e 's/^install: \(.*\)$$/\1/p' )
 else
 KERN_CC = echo KERN_CC not defined - compilation skipped
 endif
 c_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_CFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
 cc_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_CFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB
-S_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_AFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB
+S_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_AFLAGS) $(LINUX_AFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
 KERN_EXE_SUFFIX := $(LINUX_MODULE_EXT)
-KERN_LDFLAGS = $(LINUX_LDFLAGS)
+KERN_LDFLAGS = $(LINUX_LDFLAGS) $(LINUX_LDFLAGS_MODULE)
 ifdef LINUX_ARCH
 KERN_ARCH = $(LINUX_ARCH)
 else
@@ -786,7 +898,7 @@ KERN_LOADLIBES += $(kernel_LOADLIBES:%=-l%)
 
 # Check GCC version for kernel part of build
 ifndef kern_CC_MAJOR_VERSION
-kern_CC_MAJOR_VERSION := $(shell $(KERN_CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
+kern_CC_MAJOR_VERSION := $(shell $(KERN_CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
 endif
 # Prepare suitable define for dependency building
 ifeq ($(kern_CC_MAJOR_VERSION),2)
@@ -808,6 +920,34 @@ KERN_MODULES_LINK_DIR = $(KERN_MODULES_DIR)
 KERN_LINK_SUFFIX = $(KERN_EXE_SUFFIX)
 endif
 
+ifeq ($(LINUX_CONFIG_MODVERSIONS),y)
+MODPOST_OPTS += -m
+MODPOST_OPTS += -i $(LINUX_DIR)/Module.symvers
+ifneq ($(LINUX_BUILDHOST),) # this is not correct point, it should look for 2.6.17 kernel
+MODPOST_OPTS += -I $(KERN_LIB_DIR)/Module.symvers
+endif
+MODPOST_OPTS += -o $(KERN_LIB_DIR)/Module.symvers
+endif
+
+ifeq ($(LINUX_CONFIG_DEBUG_SECTION_MISMATCH),y)
+MODPOST_OPTS += -S
+endif
+
+ifeq ($(LINUX_CONFIG_MARKERS),y)
+MODPOST_OPTS += -K $(LINUX_DIR)/Module.markers
+MODPOST_OPTS += -M $(KERN_LIB_DIR)/Module.markers
+endif
+
+ifeq ($(LINUX_KBUILD_MODPOST_WARN),y)
+MODPOST_OPTS += -w
+endif
+
+ifneq ($(LINUX_BUILDHOST),)
+ifneq ($(LINUX_BUILDHOST),$(LINUX_ARCH))
+MODPOST_OPTS += -c
+endif
+endif
+
 define COMPILE_c_o_kern_template
 
 $(2): $(1)
@@ -854,6 +994,7 @@ define MODULE_kern_template
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cpp=%.o))
 $(1)_OBJS := $$(sort $$($(1)_OBJS))
 
 KERN_OBJS  += $$($(1)_OBJS)
@@ -891,11 +1032,11 @@ $(2)/$(1)$(KERN_LINK_SUFFIX): $$($(1)_OBJS)
        @$(QUIET_CMD_ECHO) "  LD [K]  $$@"
        $(Q) $$(KERN_LD) $$(KERN_LDFLAGS) -r $$($(1)_OBJS) -L$$(kern_GCCLIB_DIR) $$($(1)_LIBS:%=-l%) $$(KERN_LOADLIBES) -Map $(KERN_OBJS_DIR)/$(1).mod.map -o $$@
        @echo "$(2)/$(1)$(KERN_LINK_SUFFIX): \\" >$(KERN_OBJS_DIR)/$(1).mod.d
-       @sed -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(KERN_OBJS_DIR)/$(1).mod.map  >>$(KERN_OBJS_DIR)/$(1).mod.d
+       @$(SED4OMK) -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(KERN_OBJS_DIR)/$(1).mod.map  >>$(KERN_OBJS_DIR)/$(1).mod.d
        @echo >>$(KERN_OBJS_DIR)/$(1).mod.d
        @if [ "$(KERN_EXE_SUFFIX)" = ".ko" ] ; then \
          echo $(1) >>$(KERN_MODPOST_DIR)/module-changes ; \
-         echo $(1) >>$(KERN_MODPOST_DIR)/$(1).mod.stamp ; \
+         echo $(1) >$(KERN_MODPOST_DIR)/$(1).mod.stamp ; \
        fi
 
 endef
@@ -906,6 +1047,7 @@ define LIBRARY_kern_template
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
 $(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cpp=%.o))
 $(1)_OBJS := $$(sort $$($(1)_OBJS))
 
 KERN_OBJS  += $$($(1)_OBJS)
@@ -950,7 +1092,7 @@ MODULES_LIST := $(MODULES_LIST:%.mod.stamp=%)
 define MODPOST_kern_template
 $(2) : $(1)$(KERN_LINK_SUFFIX) $(1).mod.c
        @$(QUIET_CMD_ECHO) "  LD [M]  $$@"
-       $(Q) $$(cc_o_kern_COMPILE) -D"KBUILD_BASENAME=$(KERN_MQ)$(1)$(KERN_MQ)" \
+       $(Q) $$(c_o_kern_COMPILE) -D"KBUILD_BASENAME=$(KERN_MQ)$(1)$(KERN_MQ)" \
                -D"KBUILD_MODNAME=$(KERN_MQ)$(1)$(KERN_MQ)" \
                -o $(1).mod.o -c $(1).mod.c
        $(Q) $$(KERN_LD) $$(KERN_LDFLAGS) $(1)$(KERN_LINK_SUFFIX) $(1).mod.o -r -o $$@
@@ -960,7 +1102,7 @@ kernel-modpost-versions: $(wildcard $(LINUX_DIR)/Module.symvers)
        @$(QUIET_CMD_ECHO) "  MODPOST    $(KERN_MODPOST_DIR)"
        @echo  >$(KERN_MODPOST_DIR)/modpost-running
        @rm -f $(KERN_MODPOST_DIR)/module-changes
-       $(Q) $(KERN_MODPOST) $(MODULES_LIST:%=%$(KERN_LINK_SUFFIX)) $(^:%=-i %)
+       $(Q) $(KERN_MODPOST) $(MODPOST_OPTS) $(MODULES_LIST:%=%$(KERN_LINK_SUFFIX))
 
 $(MODULES_LIST:%=%.mod.c) : kernel-modpost-versions
 
@@ -993,13 +1135,13 @@ kernel-modpost-pass:
        fi
 
 $(eval $(call omk_pass_template, library-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)))
-$(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)))
+$(eval $(call omk_pass_template, binary-pass, $(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,$(bin_PROGRAMS)$(utils_PROGRAMS)$(test_PROGRAMS)$(bin_SCRIPTS)))
 
 $(eval $(call omk_pass_template,clean,$(USER_OBJS_DIR),,always))
 $(eval $(call omk_pass_template,install,$(USER_OBJS_DIR),,always))
 $(eval $(call omk_pass_template,include-pass,$(USER_OBJS_DIR),USER_RULE_TEMPLATES=y,always))
 
-check-dir:
+check-dir::
        @$(call mkdir_def,$(USER_BUILD_DIR))
        @$(call mkdir_def,$(KERN_BUILD_DIR))
        @$(call mkdir_def,$(USER_INCLUDE_DIR))
@@ -1037,6 +1179,8 @@ $(foreach src,$(filter %.cc,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template
 
 $(foreach src,$(filter %.cxx,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
 
+$(foreach src,$(filter %.cpp,$(USER_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cpp=%.o),)))
+
 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
 
 $(foreach src,$(filter %.c,$(USER_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.o),)))
@@ -1056,10 +1200,18 @@ $(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_templat
 
 $(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
 
+$(foreach src,$(filter %.cpp,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cpp=%.lo),$(SOLIB_PICFLAGS))))
+
 $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.lo),$(SOLIB_PICFLAGS))))
 
 $(foreach src,$(filter %.c,$(SOLIB_GEN_SOURCES)),$(eval $(call COMPILE_c_o_template,$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
 
+# Create _build directories for sources in subdirectories i.e. *_SOURCES=dir/file.c
+_dirs_to_create=$(filter-out ./,$(sort $(dir $(USER_SOURCES) $(SOLIB_SOURCES))))
+ifneq ($(_dirs_to_create),)
+$(shell mkdir -p $(addprefix $(LOCAL_BUILD_DIR)/,$(_dirs_to_create)))
+endif
+
 # IDL compilation
 
 USER_IDLS := $(sort $(USER_IDLS))
@@ -1080,6 +1232,8 @@ $(foreach src,$(filter %.cc,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_tem
 
 $(foreach src,$(filter %.cxx,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.o),)))
 
+$(foreach src,$(filter %.cpp,$(KERN_SOURCES)),$(eval $(call COMPILE_cc_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.cpp=%.o),)))
+
 $(foreach src,$(filter %.S,$(USER_SOURCES)),$(eval $(call COMPILE_S_o_kern_template,$(SOURCES_DIR)/$(src),$(src:%.S=%.o),)))
 endif
 
@@ -1098,7 +1252,7 @@ clean-local: clean-custom
 
 include-pass-submakes: extra-rules-subdirs
 
-# We must go to EXTRA_RULES_SUBDIRS beofre going to any other
+# We must go to EXTRA_RULES_SUBDIRS before going to any other
 # directory, since the executables compiled in EXTRA_RULES_SUBDIRS
 # might be needed there.
 include-pass-this-dir $(foreach subdir,$(SUBDIRS),include-pass-$(subdir)-subdir): extra-rules-subdirs
@@ -1108,16 +1262,12 @@ ifndef OMIT_KERNEL_PASSES
 # Also make kernel passes if not disabled
 default: kernel-lib-pass kernel-pass
 endif
-
-# Local Variables:
-# mode:makefile
-# End:
-                                                             #OMK@config_h
+                                                                                 #OMK:config_h.omk@Makefile.rules.linux
 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
 define BUILD_CONFIG_H_template
 
 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
-       @$(QUIET_CMD_ECHO) "  CONFGEN $$(@:%.stamp=%)"
+       @$(QUIET_CMD_ECHO) "  CONFGEN $(notdir $(2))"
        @if [ ! -d `dirname $(2).tmp` ] ; then \
                mkdir -p `dirname $(2).tmp` ; fi
        @echo "/* Automatically generated from */" > "$(2).tmp"
@@ -1125,10 +1275,10 @@ $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
        $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
        @echo "#ifndef $(4)" >> "$(2).tmp"
        @echo "#define $(4)" >> "$(2).tmp"
-       @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
+       @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | $(SED4OMK) -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
                echo '$(x).$($(x))' ; ) echo ; ) | \
-               sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
-               sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
+               $(SED4OMK) -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
+               $(SED4OMK) -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
                  >> "$(2).tmp"
        @echo "#endif /*$(4)*/" >> "$(2).tmp"
        @touch "$$@"
@@ -1183,63 +1333,53 @@ clean-local-config-h:
        @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
            if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
        )
+                                                                                 #OMK:qt.omk@Makefile.rules.linux
+ifneq ($(QT_SUBDIRS)$(QT_PROJECTS),)
+
+# Usage: $(call qt_project_template,<.pro_file relative to SOURCES_DIR>)
+define qt_project_template
+
+.PHONY: qt-subpass-$(1) clean-qt-$(dir $(1))
+
+# FIXME: Handle multiple .pro files correctly
+$(LOCAL_BUILD_DIR)/$(dir $(1))Makefile: $(SOURCES_DIR)/$(1)
+       $(Q)mkdir -p $$(dir $$(@)) && cd $$(dir $$(@)) &&               \
+       $(if $(QMAKE),$(QMAKE),$(QTDIR:%=%/bin/)qmake)                  \
+            TOP_DIR=$(OUTPUT_DIR)                                      \
+            RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir $(1))                 \
+            $(QTDIR:%=QTDIR=%) CC=$(CC) CXX=$(CXX)                     \
+            LIBS+="-L$(USER_LIB_DIR)" DESTDIR=$(USER_BIN_DIR)          \
+            INCLUDEPATH+="$(USER_INCLUDE_DIR)"                         \
+            DEPENDPATH+="$(USER_INCLUDE_DIR)"                          \
+            QMAKE_LFLAGS="-Wl,-rpath-link,$(USER_LIB_DIR) $$(QMAKE_LFLAGS)" \
+            $(SOURCES_DIR)/$(1)
+
+# This horrible substitution is here to properly escape
+# -Wl,-rpath,$ORIGIN flags. It includes escaping for make, shell,
+# qmake and again make and shell run on qmake generated makefile.
+QMAKE_LFLAGS = $$(subst $$$$,\\\\\\$$$$\$$$$,$$(LDFLAGS))
 
+# Hook to binary pass
+binary-pass-submakes: qt-subpass-$(1)
+qt-subpass-$(1): $(LOCAL_BUILD_DIR)/$(dir $(1))Makefile
+       $(Q)$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir $(1)) \
+               RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir $(1)) -C $(LOCAL_BUILD_DIR)/$(dir $(1)) || exit 1 ;
 
-# Local Variables:
-# mode:makefile
-# End:
-                                                             #OMK@qt
-ifneq ($(QT_SUBDIRS),)
-
-.PHONY: qt-subpass clean-qt distclean-qt
-
-# Usage: $(call qt_makefile_template,<qt-subdir>)
-define qt_makefile_template
-$(SOURCES_DIR)/$(1)/Makefile: $(wildcard $(SOURCES_DIR)/$(1)/*.pro)
-       cd $(SOURCES_DIR)/$(1); $(QTDIR:%=%/bin/)qmake TOP_DIR=$(OUTPUT_DIR) \
-            RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) $(QTDIR:%=QTDIR=%) CC=$(CC) \
-            CXX=$(CXX) LIBS+="-L$(USER_LIB_DIR)" INCLUDEPATH+="$(USER_INCLUDE_DIR)"
+# Hook to clean pass
+clean-local: clean-qt-$(dir $(1))
+clean-qt-$(dir $(1)): $(LOCAL_BUILD_DIR)/$(dir $(1))Makefile
+       @$(QUIET_CMD_ECHO) "  QT CLEAN $(dir $(1))"
+       $(Q)$(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir $(1)) \
+         RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir $(1)) \
+         -C $(LOCAL_BUILD_DIR)/$(dir $(1)) clean
+       $(Q)rm $(LOCAL_BUILD_DIR)/$(dir $(1))Makefile
 endef
-$(foreach dir,$(QT_SUBDIRS), $(eval $(call qt_makefile_template,$(dir))))
-
-qt-subpass: $(foreach dir,$(QT_SUBDIRS), $(SOURCES_DIR)/$(dir)/Makefile)
-       $(foreach dir,$(QT_SUBDIRS),\
-               $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
-               RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(SOURCES_DIR)/$(dir) \
-               -f $(SOURCES_DIR)/$(dir)/Makefile || exit 1 ;)
 
-# Hook to binary pass
-binary-pass-submakes: qt-subpass
+$(foreach pro,$(QT_PROJECTS), $(eval $(call qt_project_template,$(pro))))
+$(foreach pro,$(foreach dir,$(QT_SUBDIRS), $(wildcard $(dir)/*.pro)), $(eval $(call qt_project_template,$(pro))))
 
-# Hook to clean pass
-clean-local: clean-qt
-clean-qt:
-       +@$(foreach dir, $(QT_SUBDIRS), \
-               $(if $(wildcard $(SOURCES_DIR)/$(dir)/Makefile), \
-               @$(QUIET_CMD_ECHO) "  CLEAN   $(dir)"; \
-               $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
-               RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(SOURCES_DIR)/$(dir) \
-               -f $(SOURCES_DIR)/$(dir)/Makefile clean|| exit 1 ;))
-
-
-# Hook to distclean
-distclean: distclean-qt
-
-# TODO: Add distclean-qt-pass to handle QT_SUBDIRS in the whole
-# tree. This way we only distclean toplevel subdirs.
-distclean-qt:
-       +@$(foreach dir, $(QT_SUBDIRS), \
-               $(if $(wildcard $(SOURCES_DIR)/$(dir)/Makefile), \
-               @$(QUIET_CMD_ECHO) "  DISTCLEAN $(dir)"; \
-               $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) \
-               RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(SOURCES_DIR)/$(dir) \
-               -f $(SOURCES_DIR)/$(dir)/Makefile distclean|| exit 1 ;))
-endif
-
-# Local Variables:
-# mode:makefile
-# End:
-                                                             #OMK@sources-list
+endif
+                                                                                 #OMK:sources-list.omk@Makefile.rules.linux
 # Rules that creates the list of files which are used during
 # compilation. The list reflects conditional compilation depending on
 # config.omk and other variables.
@@ -1252,13 +1392,7 @@ SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
 endif
 
-ifeq ($(MAKECMDGOALS),sources-list)
-NEED_SOURCES_LIST=y
-endif
-ifeq ($(MAKECMDGOALS),TAGS)
-NEED_SOURCES_LIST=y
-endif
-ifeq ($(MAKECMDGOALS),tags)
+ifneq ($(filter sources-list TAGS tags cscope,$(MAKECMDGOALS)),)
 NEED_SOURCES_LIST=y
 endif
 
@@ -1277,7 +1411,7 @@ $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
        @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
        @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
        @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
-               sed -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
+               $(SED4OMK) -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
        @rm "$(SOURCES_LIST_D).tmp"
        @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
 endif
@@ -1290,7 +1424,7 @@ sources-list-pass-local:
          echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
        @$(foreach ch,$(config_include_HEADERS), \
          echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
-       @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|sed -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
+       @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|$(SED4OMK) -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
        @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
          $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
          $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
@@ -1313,7 +1447,7 @@ export TAGS_CMD
 
 ifeq ($(MAKECMDGOALS),do-tags)
 .PHONY: do-tags
-do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
+do-tags: $(shell $(SED4OMK) -e '/^\#/d' $(SOURCES_LIST))
        @$(QUIET_CMD_ECHO) "  TAGS    $(SOURCES_LIST_FN)"
        $(Q)$(TAGS_CMD) $^
 endif
@@ -1322,9 +1456,6 @@ endif
 
 cscope: $(SOURCES_LIST)
        @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
-       $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i-
+       $(Q)$(SED4OMK) -e '/^#/d' $(SOURCES_LIST) > cscope.files
+       $(Q)cscope -b -icscope.files
 #FIXME: see doc to -i in cscope(1)
-
-# Local Variables:
-# mode:makefile
-# End:
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif
index b22a35765d37ba44709f41e4182c62dbed0e43b7..76b56fd4c60faeb7aef88a652e680d8cd0db31b0 100644 (file)
@@ -7,7 +7,7 @@ endif
 ifeq ($(MAKERULES_DIR),)
 all : default
 .DEFAULT::
-       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+       @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n"
 else
 include $(MAKERULES_DIR)/Makefile.rules
 endif