]> rtime.felk.cvut.cz Git - omk.git/blobdiff - snippets/linux.omk
Merge branch 'master' of pisa@rtime.felk.cvut.cz:/var/git/omk
[omk.git] / snippets / linux.omk
index 048d5ef86b92af94be1c5932b3e987eef099cebd..6ccc746349776c5b3fba61285f8c8600861bf7a7 100644 (file)
@@ -17,7 +17,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
@@ -124,6 +126,7 @@ LIB_CPPFLAGS += $(CPPFLAGS)
 LIB_CFLAGS   += $(CFLAGS)
 
 ifeq ($(TARGET_OS),win32)
+  EXE_SUFFIX = .exe
   SOLIB_EXT = dll
 else
   SOLIB_EXT = so
@@ -144,7 +147,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
@@ -228,6 +232,7 @@ $(2): $(1) $$(GEN_HEADERS)
        fi
 endef
 
+NM ?= nm
 
 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
 define CMETRIC_o_h_template
@@ -236,21 +241,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
@@ -280,7 +292,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
@@ -337,6 +349,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
@@ -387,7 +400,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
@@ -404,7 +417,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)
@@ -428,7 +441,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)
@@ -438,7 +451,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
@@ -663,7 +676,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 $$@
@@ -811,7 +824,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
@@ -821,7 +834,3 @@ ifndef OMIT_KERNEL_PASSES
 # Also make kernel passes if not disabled
 default: kernel-lib-pass kernel-pass
 endif
-
-# Local Variables:
-# mode:makefile
-# End: