]> rtime.felk.cvut.cz Git - omk.git/blobdiff - snippets/base
Added variable test_PROGRAMS.
[omk.git] / snippets / base
index 4a96af4122f3d10849d3393fbd2f97becbe716b8..c5e0612c87c98828dbadae480f1c1304261948c6 100644 (file)
@@ -17,7 +17,7 @@ ifndef SOURCES_DIR
 SOURCES_DIR := $(shell ( pwd -L ) )
 endif
 
-.PHONY: all default check-make-ver
+.PHONY: all default check-make-ver omkize
 
 ifdef W
   ifeq ("$(origin W)", "command line")
@@ -66,15 +66,20 @@ export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
 ifndef RELATIVE_DIR
 RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
 endif
+#$(warning  === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
 override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
 override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
-#$(warning  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_/$$__')
-#$(warning  BACK2TOP_DIR $(BACK2TOP_DIR))
+#$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
 
-#$(warning SOURCES_DIR = $(SOURCES_DIR))
-#$(warning MAKERULES_DIR = $(MAKERULES_DIR))
-#$(warning RELATIVE_DIR = $(RELATIVE_DIR))
+#$(warning SOURCES_DIR = "$(SOURCES_DIR)")
+#$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
+#$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
+
+# We have to use RELATIVE_PREFIX because of mingw
+override RELATIVE_PREFIX := $(RELATIVE_DIR)/
+override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
 
 #vpath %.c $(SOURCES_DIR)
 #vpath %.cc $(SOURCES_DIR)
@@ -104,15 +109,16 @@ else
   QUIET_CMD_ECHO = echo
 endif
 
+MAKEFILE_OMK=Makefile.omk
 # All subdirectories (even linked ones) containing Makefile.omk
 # Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
-ALL_OMK_SUBDIRS = $(patsubst %/Makefile.omk,%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/Makefile.omk)))
+ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
 
 # ===================================================================
 # We have set up all important variables, so we can check and include
 # real OCERA style Makefile.omk now
 ifndef OMK_INCLUDED
-include $(SOURCES_DIR)/Makefile.omk
+include $(SOURCES_DIR)/$(MAKEFILE_OMK)
 OMK_INCLUDED := 1
 endif
 
@@ -145,12 +151,12 @@ define omk_pass_template
 $(1):
        +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
                $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
-               RELATIVE_DIR=$(RELATIVE_DIR)/$(dir) -C $(2)/$(dir) \
+               RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(2)/$(dir) \
                -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) true
 ifneq ($(4),)
        @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \
        $(call mkdir_def,$(2)); \
-       $(MAKE) $(NO_PRINT_DIRECTORY) -C $(2) \
+       $(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
                -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local)
 endif
 endef
@@ -172,6 +178,18 @@ $(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always)
 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" ; )
+       @$(foreach x, $(default_CONFIG), echo '$(x)' | \
+               sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
+
 
+omkize:
+       $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
+          echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
+       fi
+       $(Q)for i in `find -L . -name Makefile.omk` ; do \
+          i=`dirname $${i}`; \
+          if [ x"$$i" != x"." ]; then \
+             rm -f $${i}/Makefile; \
+             cp Makefile $${i}/Makefile; \
+          fi \
+       done