]> rtime.felk.cvut.cz Git - omk/sssa.git/commitdiff
Added support for pass hooks in Makefile.omk
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 18 Apr 2008 17:21:00 +0000 (17:21 +0000)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 18 Apr 2008 17:21:00 +0000 (17:21 +0000)
Setting of <pass-name>_HOOKS causes specified targets to be executed
during compilation of a pass. See documentation for details.

darcs-hash:20080418172146-f2ef6-8e02d43f066f74bb017188f4ba1af01c42cf1704.gz

doc/omk-manual.texinfo
snippets/base
tests/hooks/Makefile [new file with mode: 0644]
tests/hooks/Makefile.omk [new file with mode: 0644]
tests/hooks/config.omk-default [new file with mode: 0644]
tests/hooks/runtest [new file with mode: 0755]
tests/whole_tree/subdir/Makefile.omk

index 4afdd86f108a8c37b0891ba23297e5310701b7c8..c97770063ca4ca7558e163ce357cd0d8fed6091c 100644 (file)
@@ -195,7 +195,8 @@ it. This search is performed only once at the beginning of compilation.
 
 @c TODO: Pavel's note about qmake.
 
-The compilation process itself is comprised of several passes. Every
+@anchor{passes}
+The compilation process itself is comprised of several @emph{passes}. Every
 pass traverses the whole directory structure@footnote{In future, we are
 planning some optimization that allows OMK to traverse the directories
 only once and thus decrease compilation time.} and does a particular
@@ -740,6 +741,14 @@ to the desired configuration.
 In this section we list several OMK features, which are more complicated
 or rarely used so they were omitted in previous sections.
 
+@menu
+* Unsorted Advanced Features::  
+* Adding Hooks to Passes::      
+@end menu
+
+@node  Unsorted Advanced Features, Adding Hooks to Passes, Advanced OMK Features, Advanced OMK Features
+@subsection Unsorted Advanced Features
+
 @itemize
 @item
   The @file{_compiled} directory can be shared between multiple projects
@@ -824,6 +833,36 @@ compilation. Values are like @samp{linux}, @samp{rtems}, @samp{sysless},
 @file{Makefile.omk} to tweak compilation for specific targets.
 @end defvar
 
+@node Adding Hooks to Passes,  , Unsorted Advanced Features, Advanced OMK Features
+@subsection Adding Hooks to Passes
+
+Sometimes it is necessary to run some special commands as a part of
+compilation. Typical example might be a tool which generates source
+files on the fly. OMK supports calling additional commands during
+compilation by so called @emph{pass hooks}. A pass hook is an ordinary
+make target which is invoked as part of compilation during a particular
+pass (see @ref{passes}). Pass hooks can be defined by assigning their
+names to @code{xxx_HOOKS} variable.
+
+@defvar{xxx_HOOKS}
+Specifies one or more hooks (make targets) which are invoked during pass
+@var{xxx}. The working directory of commands or this target is under the
+@file{_build} tree.
+
+In the example bellow header file @file{generated_header.h} is created
+during @samp{include-pass} by @file{convert_data} program. The program
+takes @file{data_file.txt} in the source directory as the input and
+creates the header file in the in the correct directory under the
+@file{_build} tree.
+
+@example
+include-pass_HOOKS = generated_header.h
+
+generated_header.h: $(SOURCES_DIR)/data_file.txt
+            convert_data < $^ > $@@
+@end example
+@end defvar
+
 @node Properties of Specific Makefile.rules, Running OMK under Windows OS, Advanced OMK Features, OMK User's Manual
 @section Properties of Specific Makefile.rules
 
index e70438e2e8d65a5d99e78592abff60104c1f997a..b20f19d217178525225ea6da3fe971205c2d7520 100644 (file)
@@ -208,13 +208,14 @@ $(pass):
 $(pass)-submakes:
        @true                   # Do not emit "nothing to be done" messages
 
-ifneq ($(4),)
+ifneq ($(4)$($(pass)_HOOKS),)
 $(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) \
                -f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
+$(pass)-local: $($(pass)_HOOKS)
 endif
 endef
 
diff --git a/tests/hooks/Makefile b/tests/hooks/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/tests/hooks/Makefile.omk b/tests/hooks/Makefile.omk
new file mode 100644 (file)
index 0000000..6d6aca2
--- /dev/null
@@ -0,0 +1,8 @@
+include-pass_HOOKS=include-pass-hook
+library-pass_HOOKS=library-pass-hook
+binary-pass_HOOKS=binary-pass-hook
+
+$(info in Makefile.omk: $(binary-pass_HOOKS))
+
+%-hook:
+       @echo "$@ executed"
diff --git a/tests/hooks/config.omk-default b/tests/hooks/config.omk-default
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/hooks/runtest b/tests/hooks/runtest
new file mode 100755 (executable)
index 0000000..07f6498
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+source ../functions.sh
+
+make|tee make.log
+
+grep -q "include-pass-hook executed" make.log||error "include-pass-hook didn't execute"
+grep -q "library-pass-hook executed" make.log||error "library-pass-hook didn't execute"
+grep -q  "binary-pass-hook executed" make.log||error  "binary-pass-hook didn't execute"
index 43f8508eedfe329a5527b3a5259006a316fc92d0..fcc33cbc4eccff4795d940b54224b3af59651e54 100644 (file)
@@ -1,4 +1,4 @@
-include-passinclude-pass-test
+include-pass_HOOKS=include-pass-test
 
 include-pass-test:
        echo $@ >> $(MAKERULES_DIR)/subdir.mark