]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/uclibc/make_rules.mk
update
[l4.git] / l4 / pkg / uclibc / lib / uclibc / make_rules.mk
1 # vi:ft=make
2
3 CXXFLAGS_amd64 += -mcmodel=medium
4 CFLAGS_amd64 += -mcmodel=medium
5
6 CPPFLAGS        += -nostdinc -include \
7                   $(CONTRIB_DIR)/include/libc-symbols.h
8 CFLAGS          += -fno-builtin
9 CFLAGS          += -DUCLIBC_INTERNAL
10 # CFLAGS        += -std=iso9899:199901
11 DEFINES         += -DNDEBUG -D_LIBC -D__UCLIBC_CTOR_DTOR__
12 WARNINGS        = -Wall -Wstrict-prototypes
13
14 # for building the C library we access internal headers
15 PRIVATE_INCDIR += $(CONTRIB_DIR)/libc/sysdeps/linux/$(BUILD_ARCH)
16 # here we cheat a little and allow ../ includes from internal headers
17 PRIVATE_INCDIR += $(LIBC_DST_DIR)/libc $(PTHREAD_INCDIR)
18
19 # the inet subsystem needs the RESOLVER define to be set
20 CPPFLAGS_$(LIBC_DST_DIR)/libc/inet += -DRESOLVER="\"resolv.c\""
21
22 # elf subsystem may access ldso internals
23 CPPFLAGS_$(LIBC_DST_DIR)/libc/misc/elf += $(LDSO_INC)
24
25 # pthread support from libpthread uses libpthread internals
26 CPPFLAGS_$(LIBCSRC_DIR_ABS)/../$(PTHOBJ_PFX) += $(addprefix -I,$(PTHREAD_INCDIR))
27
28 # setup search paths for our sources
29 vpath %.c  $(LIBC_DST_DIR)
30 vpath %.cc $(LIBC_DST_DIR)
31 vpath %.S  $(LIBC_DST_DIR)
32 # libpthread support
33 vpath $(PTHOBJ_PFX)/% $(LIBCSRC_DIR_ABS)/..
34
35 PICFLAGS += -DSHARED=1
36
37
38 # NOTE the two newlines in the define are essential!!
39 define NEWLINE
40
41
42 endef
43
44
45 define add_source_file_x
46   UCLIBC_SRC_$(1)+=$(2)
47 endef
48
49 # add a source file to the BID list of sources
50 add_source_file = $(if $(filter %.c,$(1)),  $(eval $(call add_source_file_x,C$(2),$(1))), \
51                   $(if $(filter %.cc,$(1)), $(eval $(call add_source_file_x,CC$(2),$(1))), \
52                   $(if $(filter %.S,$(1)),  $(eval $(call add_source_file_x,S$(2),$(1))), \
53                   $(error unkwon source file: $(1)))))
54
55 # generate the search path value for source files
56 gen_search_path = $(LIBC_DST_DIR)/$(1)/$(UCLIBC_ARCH) \
57                   $(LIBC_DST_DIR)/$(1)/generic        \
58                   $(LIBC_DST_DIR)/$(1)/common         \
59                   $(LIBC_DST_DIR)/$(1)
60
61 # search for a .c, a .S, or a .cc file for the given basename
62 search_source_file = $(or $(firstword $(wildcard $(addsuffix /$(2).*,$(1)))), \
63                           $(patsubst %.c,%$(suffix $(2)).c,$(firstword $(wildcard $(addsuffix /$(basename $(2)).*,$(1))))), \
64                           $(error source file for $(2) not found))
65
66 # arg 1: directory of the subsystem (e.g., libc/string)
67 # arg 2: the basename of the file to look for (e.g. memcpy, for memcpy.c, memcpy.cc, or
68 #        memcpy.S).
69 # arg 3: the additional suffix for the SRC_<X> variable
70 define HANDLE_file
71   $(call add_source_file,$(subst $(LIBC_DST_DIR)/,,$(call search_source_file,$(1),$(2))),$(3))
72 endef
73
74 HANDLE_dir = $(foreach f,$(subst $(NEWLINE), ,$(SRC_$(1)$(2))),$(call HANDLE_file,$(call gen_search_path,$(1)),$(f),$(3)))
75
76 include $(L4DIR)/mk/rules.inc
77
78 #####################
79 # Generate pseudo rules for compiling the a template source file to a specific
80 # object file using a command line define -DL_<target>.  This is for example used
81 # for libm, where all kinds of functions are compiled from float_wrappers.c.
82 #
83 # arg 1: subsystem name (e.g. libm) -- <subsys>
84 # arg 2: module name (e.g. float, or double) -- <module>
85 #
86 # Uses:
87 #  SRC_<subsys><module> as list of target objects to generate
88 #  SRC_<subsys><module>_src as the source file for the objects
89 #
90 define OBJS_FN_templ
91   OBJS_FN_$(1)$(2) = $(addprefix $(1)/,$(patsubst %,%.o,$(subst $(NEWLINE), ,$(SRC_$(1)$(2)))))
92   UCLIBC_SRC_C += $$(OBJS_FN_$(1)$(2):.o=.c)
93   $(call BID_MAKE_RULE_template,$$(OBJS_FN_$(1)$(2)): %.o,$(1)/$$(SRC_$(1)$(2)_src),C,-DL_$$(patsubst %.o,%,$$(notdir $$@)))
94   $(call BID_MAKE_RULE_template,$$(OBJS_FN_$(1)$(2):.o=.s.o): %.s.o,$(1)/$$(SRC_$(1)$(2)_src),C,$$(PICFLAGS) -DL_$$(patsubst %.s.o,%,$$(notdir $$@)))
95 endef
96
97
98 $(eval $(call BID_GENERATE_DEFAULT_MAKE_RULES,%.__DO_UNLOCKED,%.c,C,-D__DO_UNLOCKED))
99
100
101 define PROCESS_src_lists
102   # SRC_<dir> (e.g. SRC_libc/string)
103   $(foreach d,$(1),$(call HANDLE_dir,$(d),,))
104   # SRC_<dir>_<build_arch> (e.g. SRC_libc/string_arm)
105   $(foreach d,$(1),$(call HANDLE_dir,$(d),_$(BUILD_ARCH),))
106   # SRC_<dir>_<target> (e.g. SRC_libc/string_libuc_c.a)
107   $(foreach t,$(TARGET),$(foreach d,$(1),$(call HANDLE_dir,$(d),_$(t),_$(t))))
108   # SRC_<dir>_<submodule> (e.g. SRC_libc/stdio_wchar)
109   $(foreach t,$(2),$(foreach d,$(1),$(call HANDLE_dir,$(d),_$(t),)))
110 endef
111
112 define PROCESS_template_src
113   $(foreach d,$(1),$(foreach m,$(2),$(eval $(call OBJS_FN_templ,$(d),_$(m)))))
114 endef