X-Git-Url: http://rtime.felk.cvut.cz/gitweb/omk.git/blobdiff_plain/74b43175b3686193f0c9c46d5acaad3747e03ecb..eefb242a129510654b235b5008716888d2993fbc:/snippets/Makefile.rules.test diff --git a/snippets/Makefile.rules.test b/snippets/Makefile.rules.test index 6e92dc9..1f819a0 100644 --- a/snippets/Makefile.rules.test +++ b/snippets/Makefile.rules.test @@ -1,4 +1,139 @@ -include base #omkbuild -include prepare #omkbuild -include test #omkbuild -include build #omkbuild + +# -*- makefile-gmake -*- +include base.omk #omkbuild + +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 + +check-dir:: + @$(call mkdir_def,$(USER_BUILD_DIR)) + @$(call mkdir_def,$(USER_INCLUDE_DIR)) + @$(call mkdir_def,$(USER_LIB_DIR)) + @$(call mkdir_def,$(USER_BIN_DIR)) + @$(call mkdir_def,$(USER_UTILS_DIR)) + @$(call mkdir_def,$(USER_TESTS_DIR)) + +# Avoid double slash at the end in the top-level directory +USER_OBJS_DIR = $(USER_BUILD_DIR)$(RELATIVE_DIR:%=/%) +KERN_OBJS_DIR = $(KERN_BUILD_DIR)$(RELATIVE_DIR:%=/%) + +############ +# Programs # +############ + +ifeq ($(BUILD_OS),) + # Check for target + ifeq ($(OS),Windows_NT) + BUILD_OS := win32 + else + BUILD_OS := $(shell uname | tr '[A-Z]' '[a-z]' ) + #$(warning BUILD_OS=$(BUILD_OS)) + endif +endif + +ifeq ($(TARGET_OS),) + TARGET_OS := $(BUILD_OS) +endif + +export TARGET_OS +export BUILD_OS + +# Assign default values to CFLAGS variable. If the variable is defined +# earlier (i.g. in config.omk), it is not overriden here. +CFLAGS ?= -O2 -Wall +CXXFLAGS ?= -O2 -Wall + + +CPPFLAGS += -I $(USER_INCLUDE_DIR) +LOADLIBES += -L$(USER_LIB_DIR) +LOADLIBES += $(lib_LOADLIBES:%=-l%) + +LIB_CPPFLAGS += $(CPPFLAGS) +LIB_CFLAGS += $(CFLAGS) + +ifeq ($(TARGET_OS),win32) + SOLIB_EXT = dll +else + SOLIB_EXT = so + SOLIB_PICFLAGS += -fpic +endif + +# Check GCC version for user build +ifndef CC_MAJOR_VERSION +CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/') +# TODO: export CC_MAJOR_VERSION to save the above shell invocation in +# submakes. This will work only if CC is not changed in Makefile.omk. +endif +# Prepare suitable define for dependency building +ifeq ($(CC_MAJOR_VERSION),2) +CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp" +else +CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp" +endif + +c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER + +cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER + +S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER + +c_o_cmd = \ + if $(c_o_COMPILE) $(CC_DEPFLAGS) -o $$@ -c $$< ; \ + then mv -f "$$@.d.tmp" "$$@.d"; \ + else rm -f "$$@.d.tmp"; exit 1; \ + fi + +cc_o_cmd = \ + if $(cc_o_COMPILE) $(CC_DEPFLAGS) -o $$@ -c $$< ; \ + then mv -f "$$@.d.tmp" "$$@.d"; \ + else rm -f "$$@.d.tmp"; exit 1; \ + fi + +S_o_cmd = \ + if $(S_o_COMPILE) -D__ASSEMBLY__ $(CC_DEPFLAGS) $($(1)_CFLAGS) -o $$@ -c $$< ; \ + then mv -f "$$@.d.tmp" "$$@.d" ; \ + else rm -f "$$@.d.tmp" ; exit 1; \ + fi +# TODO: Implement $($(1)_CFLAGS) + +# Default values for IDL_* variable are suitable for ORBit-like IDL compilers +IDL_CLIENT_SOURCES ?= $(1:%.idl=%-stubs.c) $(1:%.idl=%-common.c) +IDL_SERVER_SOURCES ?= $(1:%.idl=%-skels.c) $(1:%.idl=%-common.c) +IDL_TARGETS ?= $(1:%.idl=%-stubs.c) $(1:%.idl=%-skels.c) $(1:%.idl=%-common.c) $(1:%.idl=%.h) +IDL_FLAGS ?= --output-dir=$(USER_OBJS_DIR) + +idl_src_cmd = $(IDL_COMPILER) $(IDL_FLAGS) $($(1)_IDLFLAGS) $$< + +# TODO: Implement CMETRIC + +_linker = $(if $(call c++sources,$($(1)_SOURCES) $($(1)_GEN_SOURCES)),$(CXX),$(CC)) +_map_file = $(USER_OBJS_DIR)/$(1).exe.map +_dep_file = $(USER_OBJS_DIR)/$(1).exe.d +program_cmd = set -e; \ + $(_linker) $($(1)_OBJS) $($(1)_LIBS:%=-l%) $(LOADLIBES) $(LDFLAGS) \ + -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(_map_file) -o $$@; \ + echo "$$@: \\" >$(_dep_file); \ + sed -n -e 's|^LOAD \(.*\)$$$$| \1 \&|p' $(_map_file)\ + |tr '&' '\134' >>$(_dep_file); \ + echo >>$(_dep_file) + +library_cmd = $(AR) rcs $$@ $$^ + +solib_cmd = set -e; \ + $(_linker) $($(1)_OBJS) $($(1)_LIBS:%=-l%) $(LOADLIBES) $(LDFLAGS) \ + -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(_map_file) -o $$@; \ + echo "$$@: \\" >$(_dep_file); \ + sed -n -e 's|^LOAD \(.*\)$$$$| \1 \&|p' $(_map_file)\ + |tr '&' '\134' >>$(_dep_file); \ + echo >>$(_dep_file) + + +include cprog.omk #omkbuild