Move non-deprecated RPC-related functions from sunrpc to inet
[platform/upstream/glibc.git] / sunrpc / Makefile
1 # Copyright (C) 1994-2020 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8
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 # Lesser General Public License for more details.
13
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <https://www.gnu.org/licenses/>.
17
18 #
19 #       Sub-makefile for sunrpc portion of the library.
20 #
21 subdir  := sunrpc
22
23 include ../Makeconfig
24
25 # The code in this subdirectory is taken from Sun's RPCSRC-4.0
26 # distribution with some additional changes from the TI-RPC package
27 # which is also available from Sun.  The files are heavily changed to
28 # compile cleanly and to fit in the GNU environment.  All the code
29 # from Sun's rpc, etc, and rpcgen subdirectories is in this directory;
30 # the rpc subdirectory contains only the header files.  Other than
31 # that, several files were renamed so as not to exceed 14-character
32 # file name limits:
33 #
34 #       authunix_prot.c -> authuxprot.c
35 #       clnt_generic.c -> clnt_gen.c
36 #       clnt_perror.c -> clnt_perr.c
37 #       clnt_simple.c -> clnt_simp.c
38 #       get_myaddress.c -> get_myaddr.c
39 #       pmap_getmaps.c -> pm_getmaps.c
40 #       pmap_getport.c -> pm_getport.c
41 #       rpc_callmsg.c -> rpc_cmsg.c
42 #       rpc_commondata.c -> rpc_common.c
43 #       rpc_dtablesize.c -> rpc_dtable.c
44 #       svc_auth_unix.c -> svc_authux.c
45 #       xdr_reference.c -> xdr_ref.c
46
47 rpcsvc = bootparam_prot.x nlm_prot.x rstat.x \
48          yppasswd.x klm_prot.x rex.x sm_inter.x mount.x \
49          rusers.x spray.x nfs_prot.x rquota.x key_prot.x
50 headers-sunrpc = $(addprefix rpc/,auth.h auth_unix.h clnt.h pmap_clnt.h \
51                                   pmap_prot.h pmap_rmt.h rpc.h rpc_msg.h \
52                                   svc.h svc_auth.h types.h xdr.h auth_des.h \
53                                   key_prot.h) \
54                        $(rpcsvc:%=rpcsvc/%) rpcsvc/bootparam.h
55 headers = rpc/netdb.h
56 generated += $(rpcsvc:%.x=rpcsvc/%.h) $(rpcsvc:%.x=x%.c) $(rpcsvc:%.x=x%.stmp) \
57              $(rpcsvc:%.x=rpcsvc/%.stmp) rpcgen
58 generated-dirs += rpcsvc
59
60 ifeq ($(link-obsolete-rpc),yes)
61 headers += $(headers-sunrpc)
62 endif
63
64 ifeq ($(build-shared),yes)
65 need-export-routines := auth_des auth_unix clnt_gen clnt_perr clnt_tcp \
66                         clnt_udp get_myaddr key_call netname pm_getport \
67                         rpc_thread svc svc_tcp svc_udp xcrypt xdr_array xdr \
68                         xdr_intXX_t xdr_mem xdr_ref xdr_sizeof xdr_stdio \
69                         svc_run
70
71 routines := auth_none authuxprot clnt_raw clnt_simp \
72             rpc_dtable getrpcport pmap_clnt pm_getmaps pmap_prot pmap_prot2 \
73             pmap_rmt rpc_prot rpc_common rpc_cmsg svc_auth svc_authux svc_raw \
74             svc_simple xdr_float xdr_rec publickey authdes_prot \
75             des_crypt des_impl des_soft key_prot openchild rtime svcauth_des \
76             clnt_unix svc_unix create_xid $(need-export-routines) \
77             rpc_gethostbyname
78 ifneq ($(link-obsolete-rpc),yes)
79 # We only add the RPC for compatibility to libc.so.
80 shared-only-routines = $(routines)
81 endif
82 endif
83
84 ifeq ($(link-obsolete-rpc),yes)
85 install-bin := rpcgen
86 rpcgen-objs = rpc_main.o rpc_hout.o rpc_cout.o rpc_parse.o \
87               rpc_scan.o rpc_util.o rpc_svcout.o rpc_clntout.o \
88               rpc_tblout.o rpc_sample.o
89 extra-objs = $(rpcgen-objs) $(addprefix cross-,$(rpcgen-objs))
90 others += rpcgen
91 endif
92
93 tests = tst-xdrmem tst-xdrmem2 test-rpcent tst-udp-error tst-udp-timeout \
94   tst-udp-nonblocking
95 xtests := tst-getmyaddr
96
97 ifeq ($(have-thread-library),yes)
98 xtests += thrsvc
99 tests += tst-udp-garbage
100 tests-internal += tst-svc_register
101 endif
102
103 ifeq ($(run-built-tests),yes)
104 ifeq ($(link-obsolete-rpc),yes)
105 rpcgen-tests := $(objpfx)bug20790.out
106 tests-special += $(rpcgen-tests)
107 endif
108 endif
109
110 ifeq ($(link-obsolete-rpc),yes)
111 headers += $(rpcsvc:%.x=rpcsvc/%.h)
112 extra-libs := librpcsvc
113 extra-libs-others := librpcsvc # Make it in `others' pass, not `lib' pass.
114 librpcsvc-routines = $(rpcsvc:%.x=x%)
115 librpcsvc-inhibit-o = .os # Build no shared rpcsvc library.
116 omit-deps = $(librpcsvc-routines)
117 endif
118
119 ifeq (yes,$(build-shared))
120 rpc-compat-routines = $(addprefix compat-,$(need-export-routines))
121 rpc-compat-routines.os = $(addprefix $(objpfx), \
122                                      $(addsuffix .os,$(rpc-compat-routines)))
123 extra-objs += $(addsuffix .os,$(rpc-compat-routines))
124 endif
125
126 include ../Rules
127
128 ifeq (yes,$(build-shared))
129 subdir_lib: $(objpfx)librpc_compat_pic.a
130 $(objpfx)librpc_compat_pic.a: $(rpc-compat-routines.os)
131         $(AR) cr$(verbose) $@ $^
132 $(rpc-compat-routines.os): $(objpfx)compat-%.os: %.c $(before-compile)
133         $(compile-command.c) -DEXPORT_RPC_SYMBOLS
134 endif
135
136 CFLAGS-xbootparam_prot.c += -Wno-unused $(PIC-ccflag)
137 CFLAGS-xnlm_prot.c += -Wno-unused $(PIC-ccflag)
138 CFLAGS-xrstat.c += -Wno-unused $(PIC-ccflag)
139 CFLAGS-xyppasswd.c += -Wno-unused $(PIC-ccflag)
140 CFLAGS-xklm_prot.c += -Wno-unused $(PIC-ccflag)
141 CFLAGS-xrex.c += -Wno-unused $(PIC-ccflag)
142 CFLAGS-xsm_inter.c += -Wno-unused $(PIC-ccflag)
143 CFLAGS-xmount.c += -Wno-unused $(PIC-ccflag)
144 CFLAGS-xrusers.c += -Wno-unused $(PIC-ccflag)
145 CFLAGS-xspray.c += -Wno-unused $(PIC-ccflag)
146 CFLAGS-xnfs_prot.c += -Wno-unused $(PIC-ccflag)
147 CFLAGS-xrquota.c += -Wno-unused $(PIC-ccflag)
148 CFLAGS-xkey_prot.c += -Wno-unused $(PIC-ccflag)
149 CFLAGS-auth_unix.c += -fexceptions
150 CFLAGS-key_call.c += -fexceptions
151 CFLAGS-pmap_rmt.c += -fexceptions
152 CFLAGS-clnt_perr.c += -fexceptions
153 CFLAGS-openchild.c += -fexceptions
154
155 $(objpfx)tst-getmyaddr: $(common-objpfx)linkobj/libc.so
156 $(objpfx)tst-xdrmem: $(common-objpfx)linkobj/libc.so
157 $(objpfx)tst-xdrmem2: $(common-objpfx)linkobj/libc.so
158 $(objpfx)tst-udp-error: $(common-objpfx)linkobj/libc.so
159 $(objpfx)tst-svc_register: \
160   $(common-objpfx)linkobj/libc.so $(shared-thread-library)
161
162 $(objpfx)rpcgen: $(addprefix $(objpfx),$(rpcgen-objs))
163
164 cross-rpcgen-objs := $(addprefix $(objpfx)cross-,$(rpcgen-objs))
165
166 # When generic makefile support for build system programs is
167 # available, it should replace this code.  See
168 # <https://sourceware.org/bugzilla/show_bug.cgi?id=14087>.
169 $(cross-rpcgen-objs): $(objpfx)cross-%.o: %.c $(before-compile)
170         $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) $< \
171                 $(OUTPUT_OPTION) $(native-compile-mkdep-flags) -c
172
173 $(objpfx)cross-rpcgen: $(cross-rpcgen-objs)
174         $(BUILD_CC) $^ $(BUILD_LDFLAGS) -o $@
175
176 # This makes sure -DIN_MODULE is passed for all these modules.
177 cpp-srcs-left := $(rpcgen-objs:.o=.c)
178 lib := nonlib
179 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
180
181 # How we run rpcgen to generate sources and headers in the rules below.
182 # Setting CPP tells it how to run the C preprocessor correctly.  Note
183 # that $(built-program-file) requires that the just-built cross-rpcgen
184 # binary be the second dependency listed in each rule using rpcgen-cmd.
185 rpcgen-cmd = CPP='$(CC) -E -x c-header' $(built-program-file) -Y ../scripts
186
187 \f
188 # Generate the rpcsvc headers with rpcgen.
189 # We use a stamp file to avoid unnessary recompilation each time rpcgen is
190 # relinked.
191 $(rpcsvc:%.x=$(objpfx)rpcsvc/%.h): $(objpfx)rpcsvc/%.h: $(objpfx)rpcsvc/%.stmp
192         @:
193 $(objpfx)rpcsvc/%.stmp: rpcsvc/%.x $(objpfx)cross-rpcgen
194         $(make-target-directory)
195         -@rm -f ${@:stmp=T} $@
196         $(rpcgen-cmd) -h $< -o ${@:stmp=T}
197         $(move-if-change) $(@:stmp=T) $(@:stmp=h)
198         touch $@
199
200 # Generate the rpcsvc XDR functions with rpcgen.
201 $(rpcsvc:%.x=$(objpfx)x%.c): $(objpfx)x%.c: $(objpfx)x%.stmp
202         @:
203 $(objpfx)x%.stmp: rpcsvc/%.x $(objpfx)cross-rpcgen
204         -@rm -f ${@:stmp=T} $@
205         $(rpcgen-cmd) -c $< -o ${@:stmp=T}
206         $(move-if-change) $(@:stmp=T) $(@:stmp=c)
207         touch $@
208
209 # The generated source files depend on the corresponding generated headers.
210 # Gratuitous dependency on generated .c file here just gets it mentioned to
211 # avoid being an intermediate file and getting removed.
212 define o-iterator-doit
213 $(rpcsvc:%.x=$(objpfx)x%$o): $(objpfx)x%$o: $(objpfx)x%.c $(objpfx)rpcsvc/%.h
214 endef
215 object-suffixes-left = $(filter-out $(librpcsvc-inhibit-o),$(object-suffixes))
216 include $(o-iterator)
217
218 rpcsvc-dt-files := $(foreach o,$(filter-out $(librpcsvc-inhibit-o),\
219                                             $(object-suffixes)),\
220                              $(rpcsvc:%.x=$(objpfx)x%$o.dt))
221 rpcsvc-depfiles := $(patsubst %.dt,%.d,$(wildcard $(rpcsvc-dt-files))) \
222                    $(wildcard $(rpcsvc-dt-files:.dt=.d))
223 ifdef rpcsvc-depfiles
224 ifneq ($(no_deps),t)
225 -include $(rpcsvc-depfiles)
226 endif
227 endif
228
229 $(objpfx)thrsvc: $(common-objpfx)linkobj/libc.so $(shared-thread-library)
230
231 ifeq ($(run-built-tests),yes)
232 $(rpcgen-tests): $(objpfx)%.out: %.x $(objpfx)rpcgen
233         -rm -f $@
234         $(built-program-cmd) -c $< -o $@; \
235         $(evaluate-test)
236 endif
237
238 $(objpfx)tst-udp-timeout: $(common-objpfx)linkobj/libc.so
239 $(objpfx)tst-udp-nonblocking: $(common-objpfx)linkobj/libc.so
240 $(objpfx)tst-udp-garbage: \
241   $(common-objpfx)linkobj/libc.so $(shared-thread-library)