OSDN Git Service

Include all lib*/Makefile.in in top_srcdir/Makefile.in, allows adding foreign objects...
[uclinux-h8/uClibc.git] / Makerules
1 #
2 # Licensed under LGPL v2.1, see the file COPYING.LIB in this tarball for details.
3 #
4
5 .SUFFIXES: .c .S .o .os .oS .so .a .s .i
6
7 # order is important, the stripping uses STRIP_FLAGS for lib-so, but not for lib-a
8 ifeq ($(HAVE_SHARED),y)
9 .LIBPATTERNS: "lib%.so"
10 libs: lib-so-y lib-a-y
11 objs: shared_objs ar_objs
12 else
13 .LIBPATTERNS: "lib%.a"
14 libs: lib-a-y
15 objs: ar_objs
16 endif
17
18 shared_objs-y =  $(lduClibc-so-y) $(libc-so-y) $(libc-nonshared-y) $(libdl-so-y)
19 shared_objs-y += $(libcrypt-so-y) $(libintl-so-y) $(libm-so-y) $(libnsl-so-y) $(libpthread-so-y)
20 shared_objs-y += $(libresolv-so-y) $(librt-so-y) $(libutil-so-y)
21 ar_objs-y =  $(libc-a-y) $(libcrypt-a-y) $(libintl-a-y) $(libm-a-y) $(libnsl-a-y)
22 ar_objs-y += $(libpthread-a-y) $(libresolv-a-y) $(librt-a-y) $(libutil-a-y)
23
24 shared_objs: $(shared_objs-y)
25 ifeq ($(DOPIC),y)
26 ar_objs: $(ar_objs-y:.o=.os)
27 else
28 ar_objs: $(ar_objs-y)
29 endif
30
31 headers-y: $(headers-y)
32 ld-uClibc-y: $(ld-uClibc-y)
33 interp-y: $(interp)
34 pre-y: interp-y ld-uClibc-y
35 libc-y: pre-y $(libc) crt-y
36 lib-a-y: headers_root crt-y $(lib-a-y)
37 lib-so-y: libc-y $(lib-so-y)
38
39 headers_root:
40         @cd $(top_builddir); $(MAKE) headers
41
42 ifneq ($(findstring s,$(MAKEFLAGS)),)
43 DISP := sil
44 Q := @
45 else
46 ifneq ($(V)$(VERBOSE),)
47 DISP := ver
48 Q := 
49 else
50 DISP := pur
51 Q := @
52 endif
53 endif
54
55 show_objs = $(subst ../,,$@)
56
57 pur_disp_compile.c = echo "  "CC $(show_objs)
58 pur_disp_compile.S = echo "  "AS $(show_objs)
59 pur_disp_compile.m = $(pur_disp_compile.c)
60 pur_disp_compile-m = echo "  "CC-m $(show_objs)
61 pur_disp_strip     = echo "  "STRIP $(STRIP_FLAGS) $@:*
62 pur_disp_ar        = echo "  "AR $(ARFLAGS) $@
63 pur_disp_ld        = echo "  "LD $(1)
64
65 sil_disp_compile.c = true
66 sil_disp_compile.S = true
67 sil_disp_compile.m = true
68 sil_disp_compile-m = true
69 sil_disp_strip     = true
70 sil_disp_ar        = true
71 sil_disp_ld        = true
72
73 ver_disp_compile.c = echo $(cmd_compile.c)
74 ver_disp_compile.S = echo $(cmd_compile.S)
75 ver_disp_compile.m = echo $(cmd_compile.m)
76 ver_disp_compile-m = echo $(cmd_compile-m)
77 ver_disp_strip     = echo $(cmd_strip)
78 ver_disp_ar        = echo $(cmd_ar)
79 ver_disp_ld        = 
80
81 disp_compile.c = $($(DISP)_disp_compile.c)
82 disp_compile.S = $($(DISP)_disp_compile.S)
83 disp_compile.m = $($(DISP)_disp_compile.m)
84 disp_compile-m = $($(DISP)_disp_compile-m)
85 disp_strip     = $($(DISP)_disp_strip)
86 disp_ar        = $($(DISP)_disp_ar)
87 disp_ld        = $($(DISP)_disp_ld)
88
89 cmd_compile.c = $(CC) -c $< -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(subst $(top_srcdir),,$(dir $<))) $(CFLAGS-$(notdir $<)) $(CFLAGS-$(notdir $@))
90 cmd_compile.S = $(cmd_compile.c) $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@))
91 cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
92 cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-multi-y)
93 cmd_strip     = $(STRIPTOOL) $(STRIP_FLAGS) $^
94 cmd_ar        = $(AR) $(ARFLAGS) $@ $^
95
96 compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
97 compile.E = $(cmd_compile.c:-c=-E)
98 compile.S = @$(disp_compile.S) ; $(cmd_compile.S)
99 compile.m = @$(disp_compile.m) ; $(cmd_compile.m)
100 compile-m = @$(disp_compile-m) ; $(cmd_compile-m)
101 do_strip  = @$(disp_strip)     ; $(cmd_strip)
102 do_ar     = @$(disp_ar)        ; $(cmd_ar)
103
104 define link.so
105         $(Q)$(INSTALL) -d $(dir $@)
106         $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
107         @$(disp_ld)
108         $(Q)$(LD) $(LDFLAGS-$(notdir $@)) -soname=$(notdir $@).$(2) \
109                 -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
110                 --whole-archive $(firstword $^) --no-whole-archive \
111                 $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
112         $(Q)$(LN) -sf $(1) $@.$(2)
113         $(Q)$(LN) -sf $(1) $@
114 endef
115
116 CFLAGS-.os+=$(PICFLAG)
117 CFLAGS-.oS+=$(PICFLAG) -DSHARED
118
119 %.o:  %.c ; $(compile.c)
120 %.os: %.c ; $(compile.c)
121 %.oS: %.c ; $(compile.c)
122 %.o:  %.S ; $(compile.S)
123 %.os: %.S ; $(compile.S)
124 %.o:  %.s ; $(compile.S)
125 %.os: %.s ; $(compile.S)
126 %.E:  %.c ; $(compile.E)
127 %.E:  %.S ; $(compile.E)
128
129 #ifeq ($(HAVE_ELF),y)
130 CRT=crt1
131 #else
132 #CRT=crt0
133 #endif
134
135 ifeq ($(HAVE_SHARED),y)
136 CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
137 else
138 CRTS=$(top_builddir)lib/$(CRT).o
139 endif
140
141 $(top_builddir)lib/$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
142         $(Q)$(INSTALL) -d $(dir $@)
143         $(compile.S) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
144         @$(disp_strip) $(show_objs)
145         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
146
147 $(top_builddir)lib/S$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
148         $(Q)$(INSTALL) -d $(dir $@)
149         $(compile.S) $(PIEFLAG) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
150         @$(disp_strip) $(show_objs)
151         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
152
153 CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
154
155 ifeq ($(UCLIBC_CTOR_DTOR),y)
156 $(top_builddir)lib/crti.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crti.S
157         $(Q)$(INSTALL) -d $(dir $@)
158         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
159
160 $(top_builddir)lib/crtn.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crtn.S
161         $(Q)$(INSTALL) -d $(dir $@)
162         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
163 else
164 $(CTOR_TARGETS):
165         $(Q)$(INSTALL) -d $(top_builddir)lib
166         $(do_ar)
167 endif
168
169 crt-y: $(crt-y)
170 $(crt-y): $(CRTS) $(CTOR_TARGETS)
171
172 $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
173         $(Q)$(INSTALL) -d $(dir $@)
174         $(do_ar)
175
176 .PHONY: dummy create
177 clean: objclean-y headers_clean-y
178
179 objclean-y: $(objclean-y)
180 headers_clean-y: $(headers_clean-y)