Debian Codegraph @

android/app/jni/extern/macports-legacy-support/Makefile

raw
1 # GNU Makefile for MacportsLegacySupport
2 # Copyright (c) 2018 Chris Jones <[email protected]>
3 # Copyright (c) 2019 Michael Dickens <[email protected]>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17 DESTDIR ?=
18 PREFIX ?= /usr/local
19 INCSUBDIR = LegacySupport
20 PKGINCDIR = $(PREFIX)/include/$(INCSUBDIR)
21 LIBDIR = $(PREFIX)/lib
22 AREXT = .a
23 SOEXT = .dylib
24 LIBNAME = MacportsLegacySupport
25 SYSLIBNAME = MacportsLegacySystem.B
26 DLIBFILE = lib$(LIBNAME)$(SOEXT)
27 SLIBFILE = lib$(LIBNAME)$(AREXT)
28 SYSLIBFILE = lib$(SYSLIBNAME)$(SOEXT)
29 DLIBPATH = $(LIBDIR)/$(DLIBFILE)
30 SLIBPATH = $(LIBDIR)/$(SLIBFILE)
31 SYSLIBPATH = $(LIBDIR)/$(SYSLIBFILE)
32 BUILDDLIBDIR = lib
33 BUILDSLIBDIR = lib
34 BUILDDLIBPATH = $(BUILDDLIBDIR)/$(DLIBFILE)
35 BUILDSLIBPATH = $(BUILDSLIBDIR)/$(SLIBFILE)
36 BUILDSYSLIBPATH = $(BUILDDLIBDIR)/$(SYSLIBFILE)
37 SOCURVERSION ?= 1.0
38 SOCOMPATVERSION ?= 1.0
39 BUILDDLIBFLAGS = -dynamiclib -headerpad_max_install_names \
40 -install_name @executable_path/../$(BUILDDLIBPATH) \
41 -current_version $(SOCURVERSION) \
42 -compatibility_version $(SOCOMPATVERSION)
43 BUILDSYSLIBFLAGS = -dynamiclib -headerpad_max_install_names \
44 -install_name @executable_path/../$(BUILDSYSLIBPATH) \
45 -current_version $(SOCURVERSION) \
46 -compatibility_version $(SOCOMPATVERSION)
47 SYSREEXPORTFLAG = -Wl,-reexport_library /usr/lib/libSystem.B.dylib
48 BUILDSLIBFLAGS = -qs
49 POSTINSTALL = install_name_tool
50
51 MAX_DARWIN_REEXPORT ?= 19
52
53 FORCE_ARCH ?=
54 ARCHFLAGS ?=
55 LIPO ?= lipo
56 CC ?= cc $(ARCHFLAGS)
57 CFLAGS ?= -Os -Wall -Wno-deprecated-declarations
58 DLIBCFLAGS ?= -fPIC
59 SLIBCFLAGS ?=
60 CXX ?= c++ $(ARCHFLAGS)
61 CXXFLAGS ?= -Os -Wall
62 LD ?= ld
63 LDFLAGS ?=
64 AR ?= ar
65
66 UNAME ?= uname
67 SED ?= /usr/bin/sed
68 GREP ?= /usr/bin/grep
69 CP ?= /bin/cp
70
71 MKINSTALLDIRS = install -d -m 755
72 INSTALL_PROGRAM = install -c -m 755
73 INSTALL_DATA = install -c -m 644
74 RM = rm -f
75 RMDIR = sh -c 'for d; do test ! -d "$$d" || rmdir -p "$$d"; done' rmdir
76
77 PLATFORM ?= $(shell $(UNAME) -r | $(SED) -ne 's/\([0-9][0-9]*\)\..*/\1/p')
78
79 SRCDIR = src
80 SRCINCDIR = include
81 # Use VAR := $(shell CMD) instead of VAR != CMD to support old make versions
82 FIND_LIBHEADERS := find $(SRCINCDIR) -type f \( -name '*.h' -o \
83 \( -name 'c*' ! -name '*.*' \) \)
84 LIBHEADERS := $(shell $(FIND_LIBHEADERS))
85 ALLHEADERS := $(LIBHEADERS) $(wildcard $(SRCDIR)/*.h)
86
87 MULTISRCS := $(SRCDIR)/fdopendir.c
88 ADDSRCS := $(SRCDIR)/add_symbols.c
89 LIBSRCS := $(filter-out $(MULTISRCS) $(ADDSRCS),$(wildcard $(SRCDIR)/*.c))
90
91 DLIBOBJEXT = .dl.o
92 SLIBOBJEXT = .o
93 DLIBOBJS := $(patsubst %.c,%$(DLIBOBJEXT),$(LIBSRCS))
94 MULTIDLIBOBJS := $(patsubst %.c,%$(DLIBOBJEXT),$(MULTISRCS))
95 SLIBOBJS := $(patsubst %.c,%$(SLIBOBJEXT),$(LIBSRCS))
96 MULTISLIBOBJS := $(patsubst %.c,%$(SLIBOBJEXT),$(MULTISRCS))
97 ADDOBJS := $(patsubst %.c,%$(SLIBOBJEXT),$(ADDSRCS))
98
99 TESTDIR = test
100 TESTNAMEPREFIX = $(TESTDIR)/test_
101 TESTRUNPREFIX = run_
102 TESTLDFLAGS = -L$(BUILDDLIBDIR) $(LDFLAGS)
103 TESTLIBS = -l$(LIBNAME)
104 TESTSRCS_C := $(wildcard $(TESTNAMEPREFIX)*.c)
105 TESTSRCS_CPP := $(wildcard $(TESTNAMEPREFIX)*.cpp)
106 TESTOBJS_C := $(patsubst %.c,%.o,$(TESTSRCS_C))
107 TESTOBJS_CPP := $(patsubst %.cpp,%.o,$(TESTSRCS_CPP))
108 TESTPRGS_C := $(patsubst %.c,%,$(TESTSRCS_C))
109 TESTPRGS_CPP := $(patsubst %.cpp,%,$(TESTSRCS_CPP))
110 TESTPRGS = $(TESTPRGS_C) $(TESTPRGS_CPP)
111 TESTRUNS := $(patsubst $(TESTNAMEPREFIX)%,$(TESTRUNPREFIX)%,$(TESTPRGS))
112
113 define splitandfilterandmergemultiarch
114 output='$(1)' && \
115 lipo='$(2)' && \
116 rm='$(3)' && \
117 cp='$(4)' && \
118 ld='$(5)' && \
119 grep='$(6)' && \
120 platform='$(7)' && \
121 force_arch='$(8)' && \
122 objectlist="$${output}".* && \
123 archlist='' && \
124 fatness='' && \
125 for object in $${objectlist}; do \
126 if [ -z "$${force_arch}" ]; then \
127 archlist_new="$$($${lipo} -archs "$${object}")"; \
128 else \
129 archlist_new="$${force_arch}"; \
130 fi && \
131 if [ -n "$${archlist}" ] && [ "$${archlist}" != "$${archlist_new}" ]; then \
132 printf 'Old/previous architecture list "%s" does not match new one "%s", this is unsupported.\n' "$${archlist}" "$${archlist_new}" >&2 && \
133 exit '1'; \
134 else \
135 archlist="$${archlist_new}"; \
136 fi && \
137 ( $${lipo} -info "$${object}" | grep -qs '^Non-fat file:' ); \
138 fatness_new="$${?}" && \
139 if [ -n "$${fatness}" ] && [ "$${fatness}" != "$${fatness_new}" ]; then \
140 printf 'Old/previous fatness value "%d" does not match new one "%d", this is unsupported.\n' "$${fatness}" "$${fatness_new}" >&2 && \
141 exit '2'; \
142 else \
143 fatness="$${fatness_new}"; \
144 fi && \
145 if [ -n "$${force_arch}" ] && [ '0' -ne "$${fatness}" ]; then \
146 printf 'Architecture forced to "%s", but object file "%s" is a multi-architecture (fat) object file, this is unsupported.\n' "$${force_arch}" "$${object}" >&2 && \
147 exit '3'; \
148 fi && \
149 $$(: 'Check for unknown architectures.') && \
150 for arch in $${archlist}; do \
151 case "$${arch}" in \
152 (unknown*) \
153 printf 'Unknown architecture "%s" encountered, this is unsupported.\n' "$${arch}" >&2 && \
154 exit '4'; \
155 ;; \
156 (*) \
157 ;; \
158 esac && \
159 if [ '0' -eq "$${fatness}" ]; then \
160 $${cp} "$${object}" "$${object}.$${arch}" && \
161 $$(: 'A non-fat file cannot have more than one architecture, but breaking out sounds weird.'); \
162 else \
163 $${lipo} "$${object}" -thin "$${arch}" -output "$${object}.$${arch}"; \
164 fi; \
165 done && \
166 $${rm} "$${object}"; \
167 done && \
168 $$(: '... and use ld to merge each variant into a single-architecture object file ...') && \
169 for arch in $${archlist}; do \
170 $$(: 'Filter out variants not applicable to certain architectures.') && \
171 $$(: 'For instance, the x86_64 architecture is fully UNIX2003-compliant and thus does not have $$UNIX2003-compat functons.') && \
172 $$(: 'On the contrary, the i386 architecture has only $$UNIX2003-compat functions for the $$INODE64 feature set.') && \
173 $$(: '10.4 is so old that it does not even have the $$INODE64 feature.') && \
174 case "$${arch}" in \
175 ('x86_64') \
176 $${ld} -r "$${output}.inode32.$${arch}" "$${output}.inode64.$${arch}" -o "$${output}.$${arch}"; \
177 ;; \
178 ('ppc64') \
179 if [ '9' -gt "$${platform}" ]; then \
180 $${ld} -r "$${output}.inode32.$${arch}" -o "$${output}.$${arch}"; \
181 else \
182 $${ld} -r "$${output}.inode32.$${arch}" "$${output}.inode64.$${arch}" -o "$${output}.$${arch}"; \
183 fi; \
184 ;; \
185 ('i386'|'ppc'|'ppc7400') \
186 if [ '9' -gt "$${platform}" ]; then \
187 $${ld} -r "$${output}.inode32.$${arch}" "$${output}.inode32unix2003.$${arch}" -o "$${output}.$${arch}"; \
188 else \
189 $${ld} -r "$${output}.inode32.$${arch}" "$${output}.inode32unix2003.$${arch}" "$${output}.inode64unix2003.$${arch}" -o "$${output}.$${arch}"; \
190 fi; \
191 ;; \
192 (*) \
193 $${ld} -r "$${output}.inode32.$${arch}" "$${output}.inode32unix2003.$${arch}" "$${output}.inode64.$${arch}" "$${output}.inode64unix2003.$${arch}" -o "$${output}.$${arch}"; \
194 ;; \
195 esac; \
196 done && \
197 $$(: '... build list of single-architecture merged object files ...') && \
198 objectarchlist='' && \
199 for arch in $${archlist}; do \
200 objectarchlist="$${objectarchlist} $${output}.$${arch}"; \
201 done && \
202 if [ '0' -eq "$${fatness}" ]; then \
203 $$(: 'Thin files can just be copied directly, assuming that the list will only contain one element.') && \
204 $${cp} $${objectarchlist} "$${output}"; \
205 else \
206 $$(: '... and eventually use lipo to merge them all together!') && \
207 $${lipo} $${objectarchlist} -create -output "$${output}"; \
208 fi
209 endef
210
211 all: dlib slib syslib
212 dlib: $(BUILDDLIBPATH)
213 slib: $(BUILDSLIBPATH)
214 syslib: dlib $(BUILDSYSLIBPATH)
215
216 # Special rules for special implementations.
217 # For instance, functions using struct stat need to be implemented multiple
218 # times with different stat structs - a 32-bit-inode based one and a 64-bit-
219 # inode-based one.
220 $(MULTIDLIBOBJS): %$(DLIBOBJEXT): %.c $(ALLHEADERS)
221 # Generate possibly multi-architecture object files ...
222 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(DLIBCFLAGS) -D__DARWIN_UNIX03=0 -D__DARWIN_64_BIT_INO_T=0 -D__DARWIN_ONLY_64_BIT_INO_T=0 $< -o [email protected]
223 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(DLIBCFLAGS) -D__DARWIN_UNIX03=1 -D__DARWIN_ONLY_UNIX_CONFORMANCE=0 -D__DARWIN_64_BIT_INO_T=0 -D__DARWIN_ONLY_64_BIT_INO_T=0 $< -o [email protected]
224 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(DLIBCFLAGS) -D__DARWIN_UNIX03=1 -D__DARWIN_ONLY_UNIX_CONFORMANCE=1 -D__DARWIN_64_BIT_INO_T=1 -D__DARWIN_ONLY_64_BIT_INO_T=0 $< -o [email protected]
225 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(DLIBCFLAGS) -D__DARWIN_UNIX03=1 -D__DARWIN_ONLY_UNIX_CONFORMANCE=0 -D__DARWIN_64_BIT_INO_T=1 -D__DARWIN_ONLY_64_BIT_INO_T=0 $< -o [email protected]
226 # ... and split them up, because ld can only generate single-architecture files ...
227 $(call splitandfilterandmergemultiarch,$@,$(LIPO),$(RM),$(CP),$(LD),$(GREP),$(PLATFORM),$(FORCE_ARCH))
228
229 $(MULTISLIBOBJS): %$(SLIBOBJEXT): %.c $(ALLHEADERS)
230 # Generate possibly multi-architecture object files ...
231 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(SLIBCFLAGS) -D__DARWIN_UNIX03=0 -D__DARWIN_64_BIT_INO_T=0 -D__DARWIN_ONLY_64_BIT_INO_T=0 $< -o [email protected]
232 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(SLIBCFLAGS) -D__DARWIN_UNIX03=1 -D__DARWIN_ONLY_UNIX_CONFORMANCE=0 -D__DARWIN_64_BIT_INO_T=0 -D__DARWIN_ONLY_64_BIT_INO_T=0 $< -o [email protected]
233 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(SLIBCFLAGS) -D__DARWIN_UNIX03=1 -D__DARWIN_ONLY_UNIX_CONFORMANCE=1 -D__DARWIN_64_BIT_INO_T=1 -D__DARWIN_ONLY_64_BIT_INO_T=0 $< -o [email protected]
234 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(SLIBCFLAGS) -D__DARWIN_UNIX03=1 -D__DARWIN_ONLY_UNIX_CONFORMANCE=0 -D__DARWIN_64_BIT_INO_T=1 -D__DARWIN_ONLY_64_BIT_INO_T=0 $< -o [email protected]
235 # ... and split them up, because ld can only generate single-architecture files ...
236 $(call splitandfilterandmergemultiarch,$@,$(LIPO),$(RM),$(CP),$(LD),$(GREP),$(PLATFORM),$(FORCE_ARCH))
237
238 # Generously marking all header files as potential dependencies
239 $(DLIBOBJS): %$(DLIBOBJEXT): %.c $(ALLHEADERS)
240 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(DLIBCFLAGS) $< -o $@
241
242 $(SLIBOBJS): %$(SLIBOBJEXT): %.c $(ALLHEADERS)
243 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(SLIBCFLAGS) $< -o $@
244
245 $(ADDOBJS): %$(SLIBOBJEXT): %.c $(ALLHEADERS)
246 $(CC) -c -I$(SRCINCDIR) $(CFLAGS) $(SLIBCFLAGS) $< -o $@
247
248 $(TESTOBJS_C): %.o: %.c $(ALLHEADERS)
249 $(CC) -c -std=c99 -I$(SRCINCDIR) $(CFLAGS) $< -o $@
250
251 $(TESTOBJS_CPP): %.o: %.cpp $(ALLHEADERS)
252 $(CXX) -c -I$(SRCINCDIR) $(CXXFLAGS) $< -o $@
253
254 $(BUILDDLIBPATH): $(DLIBOBJS) $(MULTIDLIBOBJS)
255 $(MKINSTALLDIRS) $(BUILDDLIBDIR)
256 $(CC) $(BUILDDLIBFLAGS) $(LDFLAGS) $^ -o $@
257
258 # Wrapped libSystem relies on reexport which does not work on Darwin20+
259 $(BUILDSYSLIBPATH): $(DLIBOBJS) $(MULTIDLIBOBJS) $(ADDOBJS)
260 ifeq ($(shell test $(PLATFORM) -le $(MAX_DARWIN_REEXPORT); echo $$?),0)
261 $(MKINSTALLDIRS) $(BUILDDLIBDIR)
262 $(CC) $(BUILDSYSLIBFLAGS) $(LDFLAGS) $(SYSREEXPORTFLAG) $^ -o $@
263 endif
264
265 $(BUILDSLIBPATH): $(SLIBOBJS) $(MULTISLIBOBJS)
266 $(MKINSTALLDIRS) $(BUILDSLIBDIR)
267 $(RM) $@
268 $(AR) $(BUILDSLIBFLAGS) $@ $^
269
270 $(TESTPRGS_C): %: %.o $(BUILDDLIBPATH)
271 $(CC) $(TESTLDFLAGS) $< $(TESTLIBS) -o $@
272
273 $(TESTPRGS_CPP): %: %.o $(BUILDDLIBPATH)
274 $(CXX) $(TESTLDFLAGS) $< $(TESTLIBS) -o $@
275
276 # Special clause for testing the cmath fix: Just need to verify that
277 # building succeeds or fails, not that the executable runs or what it
278 # produces. Note that for some reason all Clang compilers tested
279 # (Apple and MP) successfully compile and link this code regardless of
280 # the c++ standard chosen, which seems to be a build issue since the
281 # functions being tested were not introduced until c++11. GCC
282 # correctly fails the compile and link using c++03 or older, but
283 # succeeds using c++11 -- as desired.
284 test_cmath: test/test_cmath.cc $(ALLHEADERS)
285 $(info 1: testing compiler '$(CXX)' for non-legacy cmath using c++03; the build should fail, regardless of the compiler or OS)
286 $(info 1: $(CXX) $(CXXFLAGS) -std=c++03 $< -o test/$@_cxx03)
287 @-$(CXX) -I$(SRCINCDIR) $(CXXFLAGS) -std=c++03 $< -o test/$@_cxx03 &> /dev/null && echo "1: c++03 no legacy cmath build success (test failed)!" || echo "1: c++03 no legacy cmath build failure (test succeeded)!"
288 $(info 2: testing compiler '$(CXX)' for non-legacy cmath using c++03; the build should fail, regardless of the compiler or OS)
289 $(info 2: $(CXX) -I$(SRCINCDIR) $(CXXFLAGS) -std=c++03 $< -o test/$@_cxx03)
290 @-$(CXX) -I$(SRCINCDIR) $(CXXFLAGS) -std=c++03 $< -o test/$@_cxx03 &> /dev/null && echo "2: c++03 legacy cmath build success (test failed)!" || echo "2: c++03 legacy cmath build failure (test succeeded)!"
291 $(info 3: testing compiler '$(CXX)' for non-legacy cmath using c++11; if the compiler supports this standard, then the build should succeed regardless of OS)
292 $(info 3: $(CXX) $(CXXFLAGS) -std=c++11 $< -o test/$@_cxx11)
293 @-$(CXX) $(CXXFLAGS) -std=c++11 $< -o test/$@_cxx11 &> /dev/null && echo "3: c++11 no legacy cmath build success (test failed)!" || echo "3: c++11 no legacy cmath build failure (test succeeded)!"
294 $(info 4: testing compiler '$(CXX)' for legacy cmath using c++11; if the compiler supports this standard, then the build should succeed regardless of OS)
295 $(info 4: $(CXX) -I$(SRCINCDIR) $(CXXFLAGS) -std=c++11 $< -o test/$@_cxx11)
296 @-$(CXX) -I$(SRCINCDIR) $(CXXFLAGS) -std=c++11 $< -o test/$@_cxx11 &> /dev/null && echo "4: c++11 legacy cmath build success (test succeeded)!" || echo "4: c++11 legacy cmath build failure (test failed)!"
297
298 # Special clause for testing faccessat in a setuid program.
299 # Must be run by root.
300 # Assumes there is a _uucp user.
301 # Tests setuid _uucp, setuid root, and setgid tty.
302 test_faccessat_setuid: test/test_faccessat
303 @test/do_test_faccessat_setuid "$(BUILDDLIBPATH)"
304
305 test_faccessat_setuid_msg:
306 @echo 'Run "sudo make test_faccessat_setuid" to test faccessat properly (Not on 10.4)'
307
308 $(TESTRUNS): $(TESTRUNPREFIX)%: $(TESTNAMEPREFIX)%
309 $<
310
311 install: install-headers install-lib
312
313 install-headers:
314 $(MKINSTALLDIRS) $(patsubst $(SRCINCDIR)/%,$(DESTDIR)$(PKGINCDIR)/%,\
315 $(sort $(dir $(LIBHEADERS))))
316 for h in $(patsubst $(SRCINCDIR)/%,%,$(LIBHEADERS)); do \
317 $(INSTALL_DATA) $(SRCINCDIR)/"$$h" $(DESTDIR)$(PKGINCDIR)/"$$h"; \
318 done
319
320 install-lib: install-dlib install-slib install-syslib
321
322 install-dlib: $(BUILDDLIBPATH)
323 $(MKINSTALLDIRS) $(DESTDIR)$(LIBDIR)
324 $(INSTALL_PROGRAM) $(BUILDDLIBPATH) $(DESTDIR)$(LIBDIR)
325 $(POSTINSTALL) -id $(DLIBPATH) $(DESTDIR)$(DLIBPATH)
326
327 install-syslib: $(BUILDSYSLIBPATH)
328 ifeq ($(shell test $(PLATFORM) -le $(MAX_DARWIN_REEXPORT); echo $$?),0)
329 $(MKINSTALLDIRS) $(DESTDIR)$(LIBDIR)
330 $(INSTALL_PROGRAM) $(BUILDSYSLIBPATH) $(DESTDIR)$(LIBDIR)
331 $(POSTINSTALL) -id $(SYSLIBPATH) $(DESTDIR)$(SYSLIBPATH)
332 endif
333
334 install-slib: $(BUILDSLIBPATH)
335 $(MKINSTALLDIRS) $(DESTDIR)$(LIBDIR)
336 $(INSTALL_DATA) $(BUILDSLIBPATH) $(DESTDIR)$(LIBDIR)
337
338 test check: $(TESTRUNS) test_cmath test_faccessat_setuid_msg
339
340 clean:
341 $(RM) $(foreach D,$(SRCDIR) $(TESTDIR),$D/*.o $D/*.o.* $D/*.d)
342 $(RM) $(BUILDDLIBPATH) $(BUILDSLIBPATH) $(BUILDSYSLIBPATH) $(TESTPRGS) test/test_cmath_* test/test_faccessat_setuid
343 @$(RMDIR) $(BUILDDLIBDIR) $(BUILDSLIBDIR)
344
345 .PHONY: all dlib slib clean check test $(TESTRUNS) test_cmath
346 .PHONY: install install-headers install-lib install-dlib install-slib