Update.
[glibc.git] / elf / Makefile
blob45b296ca40c4a75581bb4ddc14b0f4a0d4864db5
1 # Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB. If not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
19 # Makefile for elf subdirectory of GNU C Library.
21 subdir := elf
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-addr enbl-secure dl-profstub
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 version profile)
32 # But they are absent from the shared libc, because that code is in ld.so.
33 elide-routines.os = $(dl-routines) dl-support enbl-secure
35 # ld.so uses those routines, plus some special stuff for being the program
36 # interpreter and operating independent of libc.
37 rtld-routines := rtld $(dl-routines) dl-sysdep dl-environ dl-minimal
38 distribute = $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \
39 dl-hash.h soinit.c sofini.c ldd.sh.in ldd.bash.in eval.c \
40 genrtldtbl.awk atomicity.h dl-procinfo.h ldsodefs.h \
41 dl-librecon.h interp.c
43 extra-libs = libdl
44 extra-libs-others = $(extra-libs)
45 libdl-routines := dlopen dlclose dlsym dlvsym dlerror dladdr
47 before-compile = $(objpfx)trusted-dirs.h
50 all: # Make this the default target; it will be defined in Rules.
52 include ../Makeconfig
54 ifeq ($(versioning),yes)
55 ld-map = $(common-objpfx)libc.map
56 endif
58 ifeq (yes,$(build-shared))
59 extra-objs = $(rtld-routines:=.os) soinit.os sofini.os eval.os interp.os
60 generated = librtld.os dl-allobjs.os ld.so trusted-dirs.h trusted-dirs.st
61 install-others = $(inst_slibdir)/$(rtld-installed-name)
62 install-bin = ldd
63 generated += ldd
64 endif
66 others = sprof
67 install-bin += sprof
69 ifeq (yes,$(has-ldconfig))
70 others-static += ldconfig
71 others += ldconfig
72 install-rootsbin = ldconfig
73 endif
75 include ../Rules
78 ifeq (yes,$(build-shared))
79 # Make sure these things are built in the `make lib' pass so they can be used
80 # to run programs during the `make others' pass.
81 lib-noranlib: $(objpfx)$(rtld-installed-name) \
82 $(addprefix $(objpfx),$(extra-objs))
83 endif
85 # Command to link into a larger single relocatable object.
86 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
88 $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os)
89 $(reloc-link) $^
91 # Link together the dynamic linker into a single relocatable object.
92 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
93 $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
95 # Do we need a linker script?
96 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
98 ifneq (,$(rtld-ldscript-in))
99 rtld-ldscript = $(objpfx)rtld-ldscript
100 generated += rtld-ldscript
102 LDFLAGS-rtld = -T $(rtld-ldscript)
103 before-compile += $(rtld-ldscript)
105 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
106 include $(rtld-parms)
108 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
109 sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
110 -e 's#@@rtld-arch@@#$(rtld-arch)#' \
111 -e 's#@@rtld-entry@@#$(rtld-entry)#' \
112 -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
113 endif
115 $(objpfx)ld.so: $(objpfx)librtld.os $(addprefix $(objpfx),$(rtld-ldscript)) \
116 $(ld-map)
117 $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \
118 -Wl,-rpath=$(default-rpath) $(LDFLAGS-rtld) \
119 $(filter-out $(rtld-ldscript) $(map-file),$^) \
120 $(load-map-file) -Wl,-soname=$(rtld-installed-name)
122 # The dl code in the static libc needs a default library path.
123 CFLAGS-dl-support.c = -D'DEFAULT_RPATH="$(default-rpath)"'
125 # interp.c exists just to get this string into the libraries.
126 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
128 ifneq (ld.so,$(rtld-installed-name))
129 # Make sure ld.so.1 exists in the build directory so we can link
130 # against it.
131 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
132 rm -f $@
133 ln -s $(<F) $@
134 generated += $(rtld-installed-name)
135 endif
137 # Build a file mentioning all trustworthy directories to look for shared
138 # libraries when using LD_LIBRARY_PATH in a setuid program. The user can
139 # add directories to the list by defining $(user-defined-trusted-dirs)
140 # before starting make.
141 $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @:
142 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
143 $(make-target-directory)
144 dirs="$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))"; \
145 for dir in $$dirs; do \
146 echo " \"$$dir/\","; \
147 done > ${@:st=T}
148 $(move-if-change) ${@:st=T} ${@:st=h}
149 touch $@
150 CPPFLAGS-dl-load.c = -I$(objpfx).
151 CFLAGS-dl-load.c += -Wno-uninitialized
153 # Specify the dependencies of libdl.so; its commands come from the generic
154 # rule to build a shared library.
155 $(objpfx)libdl.so: $(objpfx)libdl_pic.a $(common-objpfx)libc.so $(objpfx)ld.so
157 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
158 $(do-install-program)
160 $(inst_slibdir)/$(rtld-installed-name): \
161 $(inst_slibdir)/$(rtld-version-installed-name)
162 $(make-shlib-link)
164 # Special target called by parent to install just the dynamic linker.
165 .PHONY: ldso_install
166 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
169 sh-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
170 -e 's%@VERSION@%$(version)%g'
171 bash-ldd-rewrite = $(sh-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
172 -e 's%@TEXTDOMAINDIR@%$(localedir)%g'
174 ifneq ($(have-bash2),yes)
175 ldd-shell = sh
176 else
177 ldd-shell = bash
178 endif
180 ifeq ($(ldd-rewrite-script),no)
181 define gen-ldd
182 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
183 endef
184 else
185 define gen-ldd
186 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
187 endef
188 endif
190 $(objpfx)ldd: ldd.$(ldd-shell).in $(common-objpfx)soversions.mk \
191 $(common-objpfx)config.make
192 $(gen-ldd)
193 chmod 555 $@.new
194 mv -f $@.new $@
197 ifeq ($(build-shared),yes)
198 $(objpfx)sprof: $(objpfx)libdl.so$(libdl.so-version)
199 else
200 $(objpfx)sprof: $(objpfx)libdl.a
201 endif
203 # muwahaha
205 LDFLAGS-dl.so = -Wl,-dynamic-linker,$(slibdir)/$(rtld-installed-name)
206 $(objpfx)libdl.so: $(objpfx)eval.os