Update.
[platform/upstream/glibc.git] / elf / Makefile
1 # Makefile for elf subdirectory of GNU C Library.
2
3 # Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
10
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Library General Public License for more details.
15
16 # You should have received a copy of the GNU Library General Public
17 # License along with the GNU C Library; see the file COPYING.LIB.  If not,
18 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
20
21 subdir          := elf
22
23 headers         = elf.h bits/elfclass.h bits/dlfcn.h link.h dlfcn.h
24 routines        = $(dl-routines) dl-open dl-close dl-symbol dl-support \
25                   dl-version enbl-secure
26
27 # The core dynamic linking functions are in libc for the static and
28 # profiled libraries.
29 dl-routines     = $(addprefix dl-,load cache lookup object reloc deps \
30                                   runtime error init fini debug misc)
31 # But they are absent from the shared libc, because that code is in ld.so.
32 elide-routines.so = $(dl-routines) dl-support enbl-secure
33
34 # ld.so uses those routines, plus some special stuff for being the program
35 # interpreter and operating independent of libc.
36 rtld-routines   := rtld $(dl-routines) dl-sysdep dl-minimal
37 distribute      = $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \
38                   dl-hash.h soinit.c sofini.c ldd.sh.in ldd.bash.in eval.c \
39                   genrtldtbl.awk
40
41 extra-libs       = libdl
42 extra-libs-others = $(extra-libs)
43 libdl-routines  := dlopen dlclose dlsym dlvsym dlerror dladdr
44 libdl-map       := libdl.map
45
46 before-compile = $(objpfx)trusted-dirs.h $(objpfx)rtldtbl.h
47
48 # We need GNU awk for the genrtldtbl.awk script.
49 GAWK = gawk
50
51 all: # Make this the default target; it will be defined in Rules.
52
53 include ../Makeconfig
54
55 ifeq (yes,$(build-shared))
56 extra-objs      = $(rtld-routines:=.so) soinit.so sofini.so eval.so
57 generated       = librtld.so dl-allobjs.so trusted-dirs.h rtldtbl.h
58 install-others  = $(inst_slibdir)/$(rtld-installed-name)
59 install-bin     = ldd
60 endif
61
62 ifeq (yes,$(has-ldconfig))
63 extra-objs      += ldconfig.o
64 install-rootsbin = ldconfig
65
66 $(objpfx)ldconfig: $(objpfx)ldconfig.o
67         $(CC) -nostdlib -nostartfiles -o $@ $(sysdep-LDFLAGS) -static         \
68               $(addprefix $(csu-objpfx),start.o) $(+preinit)                  \
69               $(filter-out $(addprefix $(csu-objpfx),start.o) $(+preinit)     \
70                 $(link-extra-libs) $(common-objpfx)libc% $(+postinit),$^)     \
71               $(link-extra-libs) $(common-objpfx)libc.a $(gnulib) $(+postinit)
72 endif
73
74 include ../Rules
75
76
77 ifeq (yes,$(build-shared))
78 # Make sure these things are built in the `make lib' pass so they can be used
79 # to run programs during the `make others' pass.
80 lib-noranlib: $(objpfx)$(rtld-installed-name) \
81               $(addprefix $(objpfx),$(extra-objs))
82 endif
83
84 # Command to link into a larger single relocatable object.
85 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
86
87 $(objpfx)dl-allobjs.so: $(rtld-routines:%=$(objpfx)%.so)
88         $(reloc-link) $^
89
90 # Link together the dynamic linker into a single relocatable object.
91 $(objpfx)librtld.so: $(objpfx)dl-allobjs.so $(common-objpfx)libc_pic.a
92         $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
93
94 # Do we need a linker script?
95 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
96 ifneq (,$(rtld-ldscript-in))
97 LDFLAGS-rtld = -T $(objpfx)rtld-ldscript
98
99 before-compile += $(objpfx)rtld-ldscript
100 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
101 include $(rtld-parms)
102 generated += rtld-ldscript
103 $(objpfx)rtld-ldscript: $(rtld-ldscript-in) $(rtld-parms)
104         sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
105             -e 's#@@rtld-arch@@#$(rtld-arch)#' \
106             -e 's#@@rtld-entry@@#$(rtld-entry)#' \
107             -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
108
109 $(objpfx)ld.so: $(objpfx)librtld.so $(objpfx)rtld-ldscript
110         $(rtld-link) -Wl,-soname=$(rtld-installed-name)
111
112 define rtld-link
113 $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \
114           -Wl,-rpath=$(default-rpath) $(LDFLAGS-rtld) \
115           $(filter-out $(objpfx)rtld-ldscript,$^)
116 endef
117 else
118 $(objpfx)ld.so: $(objpfx)librtld.so
119         $(rtld-link) -Wl,-soname=$(rtld-installed-name)
120
121 define rtld-link
122 $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \
123           -Wl,-rpath=$(default-rpath) $^
124 endef
125 endif
126
127 # The dl code in the static libc needs a default library path.
128 CFLAGS-dl-support.c = -D'DEFAULT_RPATH="$(default-rpath)"'
129
130 ifneq (ld.so,$(rtld-installed-name))
131 # Make sure ld.so.1 exists in the build directory so we can link
132 # against it.
133 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
134         rm -f $@
135         ln -s $(<F) $@
136 endif
137
138 # Build a file mentioning all trustworthy directories to look for shared
139 # libraries when using LD_LIBRARY_PATH in a setuid program.  The user can
140 # add directories to the list by defining $(user-defined-trusted-dirs)
141 # before starting make.
142 $(objpfx)trusted-dirs.h: Makefile
143         $(make-target-directory)
144         (for dir in `echo "$(default-rpath) $(user-defined-trusted-dirs)" |   \
145                      sed 's/:/ /g'`; do                                       \
146            echo "  \"$$dir\",";                                               \
147          done;) > $@T
148         mv -f $@T $@
149 $(objpfx)rtldtbl.h: Makefile
150         $(make-target-directory)
151         echo "$(default-rpath)" | $(GAWK) -f genrtldtbl.awk > $@T
152         mv -f $@T $@
153 CPPFLAGS-dl-load.c = -I$(objdir)/$(subdir)
154 CFLAGS-dl-load.c += -Wno-uninitialized
155
156 # Specify the dependencies of libdl.so; its commands come from the generic
157 # rule to build a shared library.
158 $(objpfx)libdl.so: $(objpfx)libdl_pic.a $(common-objpfx)libc.so $(objpfx)ld.so
159
160 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so
161         $(do-install-program)
162
163 $(inst_slibdir)/$(rtld-installed-name): \
164   $(inst_slibdir)/$(rtld-version-installed-name)
165         $(make-shlib-link)
166
167 ifneq ($(have-bash2),yes)
168 $(objpfx)ldd: ldd.sh.in $(common-objpfx)version.mk \
169               $(common-objpfx)soversions.mk $(common-objpfx)config.make
170         sed -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
171             -e 's%@VERSION@%$(version)%g' < $< > $@.new
172         chmod 555 $@.new
173         mv -f $@.new $@
174 else
175 $(objpfx)ldd: ldd.bash.in $(common-objpfx)version.mk \
176               $(common-objpfx)soversions.mk $(common-objpfx)config.make
177         sed -e 's%@BASH@%$(BASH)%g' \
178             -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
179             -e 's%@VERSION@%$(version)%g' \
180             -e 's%@TEXTDOMAINDIR@%$(localedir)%g' < $< > $@.new
181         chmod 555 $@.new
182         mv -f $@.new $@
183 endif
184 \f
185 # muwahaha
186
187 LDFLAGS-dl.so = -Wl,-dynamic-linker,$(slibdir)/$(rtld-installed-name)
188 $(objpfx)libdl.so: $(objpfx)eval.so