]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - omk/rules/linux/Makefile.rules
Makefile.rules updated to actual OMK version.
[lincan.git] / omk / rules / linux / Makefile.rules
index 25507fad4b31854f15fe8140d20e0f4e154c43eb..a887fa258116778354e79e8263540e5223c46452 100644 (file)
@@ -1,10 +1,10 @@
 #  Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*- #OMK:base.omk
 #
-#  (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 by Michal Sojka - Czech Technical University, FEE, DCE
 #
 #  Homepage: http://rtime.felk.cvut.cz/omk/
-#  Version:  0.1-71-g6698de2
+#  Version:  0.2-27-g254fd61
 #
 # The OMK build system is distributed under the GNU General Public
 # License.  See file COPYING for details.
@@ -35,7 +35,9 @@
 # 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
 # QTDIR                   .. where QT resides
 OMK_RULES_TYPE=linux                                                             #OMK:Makefile.rules.linux@
                                                                                  #OMK:base.omk@Makefile.rules.linux
-# 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
-
 # If we are not called by OMK leaf Makefile...
 ifndef MAKERULES_DIR
 MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
@@ -79,7 +75,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")
@@ -91,7 +96,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
@@ -113,34 +118,32 @@ endif
 #=========================
 # 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 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.
@@ -152,7 +155,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)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
 #$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
 
 #$(warning SOURCES_DIR = "$(SOURCES_DIR)")
@@ -207,6 +210,9 @@ 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'` ; \
        if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
@@ -241,18 +247,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) \
                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
@@ -336,11 +345,17 @@ 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 -C -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
 
@@ -350,21 +365,19 @@ 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
                                                                                  #OMK:linux.omk@Makefile.rules.linux
 # Hack to check RT-Linux rules
@@ -461,6 +474,7 @@ LIB_CPPFLAGS += $(CPPFLAGS)
 LIB_CFLAGS   += $(CFLAGS)
 
 ifeq ($(TARGET_OS),win32)
+  EXE_SUFFIX = .exe
   SOLIB_EXT = dll
 else
   SOLIB_EXT = so
@@ -481,7 +495,8 @@ OMK_WORK_DIR  = $(USER_OBJS_DIR)
 ifneq ($(OMK_SERIALIZE_INCLUDED),y)
 include-pass: check-dir
 library-pass: include-pass
-binary-pass: library-pass link-pseudo-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
@@ -565,6 +580,7 @@ $(2): $(1) $$(GEN_HEADERS)
        fi
 endef
 
+NM ?= nm
 
 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
 define CMETRIC_o_h_template
@@ -573,21 +589,28 @@ $(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) $$< \
+       $(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; }\
                | 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) $$< \
+               | 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; }\
                | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
-               | sort >>$$@
+               | 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; }\
+               | sed -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) $$($(2)_IDLFLAGS) $(1)
 endef
@@ -617,7 +640,7 @@ 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,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$@
+         $$($(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
        @echo >>$(USER_OBJS_DIR)/$(1).exe.d
@@ -674,6 +697,7 @@ SOLIB_SOURCES += $$($(1)_SOURCES)
 $(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
@@ -709,6 +733,9 @@ $(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 # USER_RULE_TEMPLATES
 
@@ -724,7 +751,7 @@ $(1)_shared_libs = $$(patsubst %,$(USER_LIB_DIR)/lib%.$(SOLIB_EXT),$$(filter $$(
 #$$(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) -o $$@ $$($(1)_objslo) $$(LOADLIBES) $$($(1)_libs:%=-l%)
+       $(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
@@ -741,7 +768,7 @@ endif # link-shared-libs
 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)
@@ -765,7 +792,7 @@ 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)
@@ -775,7 +802,7 @@ 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_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
 KERN_EXE_SUFFIX := $(LINUX_MODULE_EXT)
 KERN_LDFLAGS = $(LINUX_LDFLAGS)
 ifdef LINUX_ARCH
@@ -1000,7 +1027,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 $$@
@@ -1110,6 +1137,12 @@ $(foreach src,$(filter %.S,$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,
 
 $(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))
@@ -1148,7 +1181,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
@@ -1163,7 +1196,7 @@ endif
 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"
@@ -1240,7 +1273,7 @@ define qt_project_template
 # FIXME: Handle multiple .pro files correctly
 $(LOCAL_BUILD_DIR)/$(dir $(1))Makefile: $(SOURCES_DIR)/$(1)
        $(Q)mkdir -p $$(dir $$(@)) && cd $$(dir $$(@)) &&               \
-       $(QTDIR:%=%/bin/)qmake                                          \
+       $(if $(QMAKE),$(QMAKE),$(QTDIR:%=%/bin/)qmake)                  \
             TOP_DIR=$(OUTPUT_DIR)                                      \
             RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir $(1))                 \
             $(QTDIR:%=QTDIR=%) CC=$(CC) CXX=$(CXX)                     \
@@ -1351,5 +1384,6 @@ endif
 
 cscope: $(SOURCES_LIST)
        @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
-       $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i-
+       $(Q)sed -e '/^#/d' $(SOURCES_LIST) > cscope.files
+       $(Q)cscope -b -icscope.files
 #FIXME: see doc to -i in cscope(1)