]> rtime.felk.cvut.cz Git - omk.git/blobdiff - snippets/build
Formating changes, added Emacs modelines
[omk.git] / snippets / build
index a8e1c645f31b9a71b6a49f0b6cd6817c425d4750..ed0e9dd4fa6a93eabae4f54bc160b0e7853d7651 100644 (file)
 
-BUILD_DIR_NAME = _build
-COMPILED_DIR_NAME = _compiled
-
-USER_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include
-USER_LIB_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib
-USER_UTILS_DIR   := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-utils
-USER_TESTS_DIR   := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-tests
-USER_BIN_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin
-USER_BUILD_DIR   := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/user
-LINK_BUILD_DIR   := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/link
-
-USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
-KERN_OBJS_DIR = $(KERN_BUILD_DIR)/$(RELATIVE_DIR)
-OMK_WORK_DIR  = $(USER_OBJS_DIR)
-
-strip_out = $(patsubst $(OUTPUT_DIR)/%,%,$(1))
-repl_out  = $(patsubst $(OUTPUT_DIR)/%,$$(OUTPUT_DIR)/%,$(1))
-
-.PHONY: FORCE
-
-#####################
+##################### -*- makefile-gmake -*-
 # Build pseudo-pass #
 #####################
 
-rule_targets   = $($(1)_targets)
-rule_deps      = $($(1)_deps)
-rule_quiet_cmd = $($(1)_quiet_cmd)
-rule_cmd       = $($(1)_cmd)
+ifneq (,$(filter build,$(MAKECMDGOALS)))
+rule_targets = $(value $(1)_targets)
+rule_deps    = $(value $(1)_deps)
+rule_msg     = $(value $(1)_msg)
+rule_cmd     = $(value $(1)_cmd)
 
-# Usage: $(call build_rule,<target>)
+# Usage: $(eval $(call build_rule,<target>))
 define build_rule
-$(rule_target): $(rule_deps)   # TODO: dep on .cmd file
-       @$(QUIET_CMD_ECHO) "  "$(rule_quiet_cmd) "$$(call strip_out,$$(@))"
+$(rule_targets): $(rule_deps) #$(omk_inc_file)
+       @$(QUIET_CMD_ECHO) "  "$(rule_msg)"$$@" #"$$(call strip_out,$$@)"
        $(Q)$(rule_cmd)
 endef
 
-# TODO: Include target.omk only in the subtree
--include $(shell true; find $(USER_BUILD_DIR) -name '*.target.omk') # `true' is a hack for MinGW
--include $(shell true; find $(USER_BUILD_DIR) -name '*.var.omk') # `true' is a hack for MinGW
-
-$(foreach target,$(minor_targets),$(eval $(call build_rule,$(target))))
-
-.PHONY: build-pseudo-pass
-build-pseudo-pass: $(foreach target,$(major_targets),$(target))
-
-################
-# Prepare pass #
-################
-
-$(eval $(call omk_pass_template,prepare-pass,$(USER_OBJS_DIR),,always))
-
-var_omk_file = $(OMK_WORK_DIR)/$(notdir $(1)).var.omk
-var_omk_target = $(1:$(OUTPUT_DIR)/%=%)
-
-target_omk_file = $(OMK_WORK_DIR)/$(notdir $(1)).target.omk
-
-###
-# prepare is used to generate .var.omk files during prepare-pass.
-# All paths in this file should be relative to $(OUTPUT_DIR)
-# Usage: $(call prepare,<target-name>,<targets>,<deps>,<quiet_cmd>,<cmd>)
-define prepare
-prepare-pass-local: $(var_omk_file)
-
-$(var_omk_file): FORCE
-       $(Q)echo 'minor_targets += $(var_omk_target)' > $$@.tmp; \
-           echo '$(var_omk_target)_targets = $$(call strip_out,$(2))' >> $$@.tmp; \
-           echo '$(var_omk_target)_deps += $$(call strip_out,$(3))' >> $$@.tmp; \
-           echo '$(var_omk_target)_quiet_cmd = $(4)' >> $$@.tmp; \
-           echo '$(var_omk_target)_cmd = $$(call repl_out,$(5))' >> $$@.tmp; \
-       if cmp -s $$@.tmp $$@; then rm $$@.tmp; else mv $$@.tmp $$@; fi
-endef
-
-define target
-prepare-pass-local: $(var_omk_file)
-$(target_omk_file): FORCE
-       $(Q)echo 'major_targets += $(var_omk_target)' > $$@
-endef
-
-############
-# Programs #
-############
-
-# Syntax: $(call compile_c_o_template,<source>,<target>,<additional c-flags>)
-define compile_c_o_template
-
-$(2): $(1) $$(GEN_HEADERS)
-       @$(QUIET_CMD_ECHO) "  CC      $$@"
-       $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
-       then mv -f "$$@.d.tmp" "$$@.d" ; \
-       else rm -f "$$@.d.tmp" ; exit 1; \
-       fi
-endef
-
-
-# Usage: $(call program_template,<executable-name>,<bin|utils|test>)
-define program_template
-$(1)_OBJS += $$(patsubst %.c,%.o,$$(filter %.c,$$($(1)_SOURCES)))
-$(1)_OBJS := $$(addprefix $(USER_OBJS_DIR),$$(sort $$($(1)_OBJS:%/=%)))
-
-USER_OBJS  += $$($(1)_OBJS)
-USER_SOURCES += $$($(1)_SOURCES)
-
-
-program_targets = $(USER_BIN_DIR)/$(1)$(EXE_SUFFIX)
-program_deps = $$($(1)_OBJS) $$($(1)_LIBS)
-program_cmd = $$(if $$(filter %.cc,$$($(1)_SOURCES)),$$(CXX),$$(CC)) \
-       $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(LDFLAGS) -Wl,-rpath-link,$(USER_LIB_DIR) \
-       -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$$$@
-
-$(call prepare,\
-       $(2)_PROGRAMS_$(1),\
-       $$(program_targets),\
-       $$(program_deps),\
-       "LINK    ",\
-       $$(program_cmd))
-endef
+# TODO: Include __goals.omk.inc only in the subtree
+-include $(shell true; find $(BUILD_OMK_DIR) -name '*.omk.inc') # `true' is a hack for MinGW
+# FIXME: Disable automatic remake of included files
 
-c_o_cmd := set -e; cd $$(dir $$@); \
-       if $$(c_o_COMPILE) $$(CC_DEPFLAGS) -o $$@ -c $$< ; \
-       then mv -f "$$@.d.tmp" "$$@.d" ; \
-       else rm -f "$$@.d.tmp" ; \
-       fi
+$(foreach rule,$(prepared_rules),$(eval $(call build_rule,$(rule))))
 
+.PHONY: build
 
-$(foreach prog,$(bin_PROGRAMS),$(eval $(call program_template,$(prog),bin)))
-$(foreach src,$(filter %.c,$(USER_SOURCES)),$(eval $(call prepare,\
-       $(USER_OBJS_DIR)/$(src:%.c=%.o),\
-       $(USER_OBJS_DIR)/$(src:%.c=%.o),\
-       $(SOURCES_DIR)/$(src),\
-       "CC      ",\
-       $(c_o_cmd))))
+build: $(omk_goals)
 
-default: prepare-pass
-       
+endif # (,$(filter build,$(MAKECMDGOALS)))