Update.
[glibc.git] / elf / Makefile
blobddd9d222fb469d56db65210a74053868f0bade1b
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.bash.in eval.c \
40 genrtldtbl.awk atomicity.h dl-procinfo.h ldsodefs.h \
41 dl-librecon.h interp.c sln.c dl-origin.h
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 sln
67 install-bin += sprof
68 others-static = sln
69 install-rootsbin = sln
71 ifeq (yes,$(has-ldconfig))
72 others-static += ldconfig
73 others += ldconfig
74 install-rootsbin += ldconfig
75 endif
77 include ../Rules
80 ifeq (yes,$(build-shared))
81 # Make sure these things are built in the `make lib' pass so they can be used
82 # to run programs during the `make others' pass.
83 lib-noranlib: $(objpfx)$(rtld-installed-name) \
84 $(addprefix $(objpfx),$(extra-objs))
85 endif
87 # Command to link into a larger single relocatable object.
88 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
90 $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os)
91 $(reloc-link) $^
93 # Link together the dynamic linker into a single relocatable object.
94 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
95 $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
97 # Do we need a linker script?
98 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
100 ifneq (,$(rtld-ldscript-in))
101 rtld-ldscript = $(objpfx)rtld-ldscript
102 generated += rtld-ldscript
104 LDFLAGS-rtld = -T $(rtld-ldscript)
105 before-compile += $(rtld-ldscript)
107 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
108 include $(rtld-parms)
110 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
111 sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
112 -e 's#@@rtld-arch@@#$(rtld-arch)#' \
113 -e 's#@@rtld-entry@@#$(rtld-entry)#' \
114 -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
115 endif
117 $(objpfx)ld.so: $(objpfx)librtld.os $(addprefix $(objpfx),$(rtld-ldscript)) \
118 $(ld-map)
119 $(LINK.o) -nostdlib -nostartfiles -shared -o $@ $(LDFLAGS-rtld) \
120 $(filter-out $(rtld-ldscript) $(map-file),$^) \
121 $(load-map-file) -Wl,-soname=$(rtld-installed-name)
123 # interp.c exists just to get this string into the libraries.
124 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
126 ifneq (ld.so,$(rtld-installed-name))
127 # Make sure ld.so.1 exists in the build directory so we can link
128 # against it.
129 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
130 rm -f $@
131 ln -s $(<F) $@
132 generated += $(rtld-installed-name)
133 endif
135 # Build a file mentioning all trustworthy directories to look for shared
136 # libraries when using LD_LIBRARY_PATH in a setuid program. The user can
137 # add directories to the list by defining $(user-defined-trusted-dirs)
138 # before starting make.
139 $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @:
140 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
141 $(make-target-directory)
142 dirs="$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))"; \
143 for dir in $$dirs; do \
144 echo " \"$$dir/\","; \
145 done > ${@:st=T}
146 $(move-if-change) ${@:st=T} ${@:st=h}
147 touch $@
148 CPPFLAGS-dl-load.c = -I$(objpfx).
149 CFLAGS-dl-load.c += -Wno-uninitialized
151 # Specify the dependencies of libdl.so; its commands come from the generic
152 # rule to build a shared library.
153 $(objpfx)libdl.so: $(objpfx)libdl_pic.a $(common-objpfx)libc.so $(objpfx)ld.so
155 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
156 $(do-install-program)
158 $(inst_slibdir)/$(rtld-installed-name): \
159 $(inst_slibdir)/$(rtld-version-installed-name)
160 $(make-shlib-link)
162 # Special target called by parent to install just the dynamic linker.
163 .PHONY: ldso_install
164 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
167 common-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
168 -e 's%@VERSION@%$(version)%g'
169 sh-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%/bin/sh%g;s/\$$"/"/g'
170 bash-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
171 -e 's%@TEXTDOMAINDIR@%$(localedir)%g'
173 ifneq ($(have-bash2),yes)
174 ldd-shell = sh
175 else
176 ldd-shell = bash
177 endif
179 ifeq ($(ldd-rewrite-script),no)
180 define gen-ldd
181 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
182 endef
183 else
184 define gen-ldd
185 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
186 endef
187 endif
189 $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
190 $(common-objpfx)config.make
191 $(gen-ldd)
192 chmod 555 $@.new
193 mv -f $@.new $@
196 ifeq ($(build-shared),yes)
197 $(objpfx)sprof: $(objpfx)libdl.so$(libdl.so-version)
198 else
199 $(objpfx)sprof: $(objpfx)libdl.a
200 endif
202 # muwahaha
204 LDFLAGS-dl.so = -Wl,-dynamic-linker,$(slibdir)/$(rtld-installed-name)
205 $(objpfx)libdl.so: $(objpfx)eval.os