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