]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/Makefile.rules.test
Formating changes, added Emacs modelines
[omk.git] / snippets / Makefile.rules.test
1
2 # -*- makefile-gmake -*-
3 include base #omkbuild
4
5 USER_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include
6 USER_LIB_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib
7 USER_UTILS_DIR   := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-utils
8 USER_TESTS_DIR   := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-tests
9 USER_BIN_DIR     := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin
10 USER_BUILD_DIR   := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/user
11 #LINK_BUILD_DIR   := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/link
12
13 check-dir::
14         @$(call mkdir_def,$(USER_BUILD_DIR))
15         @$(call mkdir_def,$(USER_INCLUDE_DIR))
16         @$(call mkdir_def,$(USER_LIB_DIR))
17         @$(call mkdir_def,$(USER_BIN_DIR))
18         @$(call mkdir_def,$(USER_UTILS_DIR))
19         @$(call mkdir_def,$(USER_TESTS_DIR))
20
21 # Avoid double slash at the end in the top-level directory
22 USER_OBJS_DIR = $(USER_BUILD_DIR)$(RELATIVE_DIR:%=/%)
23 KERN_OBJS_DIR = $(KERN_BUILD_DIR)$(RELATIVE_DIR:%=/%)
24
25 ############
26 # Programs #
27 ############
28
29 # Check GCC version for user build
30 ifndef CC_MAJOR_VERSION
31 CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
32 # TODO: export CC_MAJOR_VERSION to save the above shell invocation in
33 # submakes. This will work only if CC is not changed in Makefile.omk.
34 endif
35 # Prepare suitable define for dependency building
36 ifeq ($(CC_MAJOR_VERSION),2)
37 CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp"
38 else
39 CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp"
40 endif
41
42 c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
43         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
44
45 cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
46         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
47
48 S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
49         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
50
51 c_o_cmd = \
52         if $(c_o_COMPILE) $(CC_DEPFLAGS) -o $$@ -c $$< ; \
53         then mv -f "$$@.d.tmp" "$$@.d"; \
54         else rm -f "$$@.d.tmp"; exit 1; \
55         fi
56
57 cc_o_cmd = \
58         if $(cc_o_COMPILE) $(CC_DEPFLAGS) -o $$@ -c $$< ; \
59         then mv -f "$$@.d.tmp" "$$@.d"; \
60         else rm -f "$$@.d.tmp"; exit 1; \
61         fi
62
63 S_o_cmd = \
64         if $(S_o_COMPILE) -D__ASSEMBLY__ $(CC_DEPFLAGS) $($(1)_CFLAGS) -o $$@ -c $$< ; \
65         then mv -f "$$@.d.tmp" "$$@.d" ; \
66         else rm -f "$$@.d.tmp" ; exit 1; \
67         fi
68 # TODO: Implement $($(1)_CFLAGS)
69
70 # Default values for IDL_* variable are suitable for ORBit-like IDL compilers
71 IDL_CLIENT_SOURCES ?= $(1:%.idl=%-stubs.c) $(1:%.idl=%-common.c)
72 IDL_SERVER_SOURCES ?= $(1:%.idl=%-skels.c) $(1:%.idl=%-common.c)
73 IDL_TARGETS ?= $(1:%.idl=%-stubs.c) $(1:%.idl=%-skels.c) $(1:%.idl=%-common.c) $(1:%.idl=%.h)
74
75 idl_src_cmd = $(IDL_COMPILER) $(IDL_FLAGS) $($(1)_IDLFLAGS) $(1)
76
77 # TODO: Implement CMETRIC
78
79 _linker = $(if $(call c++sources,$($(1)_SOURCES)),$(CXX),$(CC))
80 _map_file = $(USER_OBJS_DIR)/$(1).exe.map
81 _dep_file = $(USER_OBJS_DIR)/$(1).exe.d
82 program_cmd = set -e; \
83         $(_linker) $($(1)_OBJS) $($(1)_LIBS:%=-l%) $(LOADLIBES) $(LDFLAGS) \
84                 -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(_map_file) -o $$@; \
85         echo "$$@: \\" >$(_dep_file); \
86         sed -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(_map_file)\
87         |tr '&' '\134' >>$(_dep_file); \
88         echo >>$(_dep_file)
89
90 library_cmd = $(AR) rcs $$@ $$^
91
92 solib_cmd = set -e; \
93         $(_linker) $($(1)_OBJS) $($(1)_LIBS:%=-l%) $(LOADLIBES) $(LDFLAGS) \
94                 -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(_map_file) -o $$@; \
95         echo "$$@: \\" >$(_dep_file); \
96         sed -n -e 's|^LOAD \(.*\)$$$$|  \1  \&|p' $(_map_file)\
97         |tr '&' '\134' >>$(_dep_file); \
98         echo >>$(_dep_file)
99
100
101 include cprog #omkbuild