Android.mk revision 36d6188f8cd8b948fb797f11d9620d63d0c2215a
1LOCAL_PATH:= $(call my-dir)
2
3include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/syscalls.mk
4
5# Make everything depend on any changes to included makefiles.
6libc_common_additional_dependencies := \
7    $(LOCAL_PATH)/arch-$(TARGET_ARCH)/syscalls.mk \
8    $(LOCAL_PATH)/Android.mk \
9
10# Define the common source files for all the libc instances
11# =========================================================
12libc_common_src_files := \
13	$(syscall_src) \
14	unistd/alarm.c \
15	unistd/exec.c \
16	unistd/fnmatch.c \
17	unistd/syslog.c \
18	unistd/system.c \
19	unistd/time.c \
20	stdio/asprintf.c \
21	stdio/fflush.c \
22	stdio/fgetc.c \
23	stdio/findfp.c \
24	stdio/fprintf.c \
25	stdio/fputc.c \
26	stdio/fread.c \
27	stdio/freopen.c \
28	stdio/fscanf.c \
29	stdio/fseek.c \
30	stdio/ftell.c \
31	stdio/fvwrite.c \
32	stdio/gets.c \
33	stdio/printf.c \
34	stdio/refill.c \
35	stdio/rewind.c \
36	stdio/scanf.c \
37	stdio/snprintf.c\
38	stdio/sprintf.c \
39	stdio/sscanf.c \
40	stdio/stdio.c \
41	stdio/ungetc.c \
42	stdio/vasprintf.c \
43	stdio/vfprintf.c \
44	stdio/vfscanf.c \
45	stdio/vprintf.c \
46	stdio/vsnprintf.c \
47	stdio/vsprintf.c \
48	stdio/vscanf.c \
49	stdio/vsscanf.c \
50	stdio/wbuf.c \
51	stdlib/atexit.c \
52	stdlib/ctype_.c \
53	stdlib/getenv.c \
54	stdlib/putenv.c \
55	stdlib/setenv.c \
56	stdlib/strtod.c \
57	stdlib/strtoimax.c \
58	stdlib/strtol.c \
59	stdlib/strtoll.c \
60	stdlib/strtoul.c \
61	stdlib/strtoull.c \
62	stdlib/strtoumax.c \
63	stdlib/tolower_.c \
64	stdlib/toupper_.c \
65	string/strcasecmp.c \
66	string/strcspn.c \
67	string/strdup.c \
68	string/strpbrk.c \
69	string/strsep.c \
70	string/strspn.c \
71	string/strstr.c \
72	string/strtok.c \
73	wchar/wcswidth.c \
74	wchar/wcsxfrm.c \
75	bionic/arc4random.c \
76	bionic/atoi.c \
77	bionic/atol.c \
78	bionic/atoll.c \
79	bionic/bindresvport.c \
80	bionic/clearenv.c \
81	bionic/daemon.c \
82	bionic/err.c \
83	bionic/ether_aton.c \
84	bionic/ether_ntoa.c \
85	bionic/fdprintf.c \
86	bionic/flockfile.c \
87	bionic/ftime.c \
88	bionic/ftok.c \
89	bionic/fts.c \
90	bionic/getdtablesize.c \
91	bionic/gethostname.c \
92	bionic/getpgrp.c \
93	bionic/getpriority.c \
94	bionic/getpt.c \
95	bionic/if_indextoname.c \
96	bionic/if_nametoindex.c \
97	bionic/initgroups.c \
98	bionic/ioctl.c \
99	bionic/isatty.c \
100	bionic/issetugid.c \
101	bionic/ldexp.c \
102	bionic/md5.c \
103	bionic/memmem.c \
104	bionic/memswap.c \
105	bionic/pathconf.c \
106	bionic/perror.c \
107	bionic/ptsname.c \
108	bionic/ptsname_r.c \
109	bionic/pututline.c \
110	bionic/reboot.c \
111	bionic/recv.c \
112	bionic/sched_cpualloc.c \
113	bionic/sched_cpucount.c \
114	bionic/sched_getcpu.c \
115	bionic/semaphore.c \
116	bionic/send.c \
117	bionic/setpgrp.c \
118	bionic/sigblock.c \
119	bionic/siginterrupt.c \
120	bionic/siglist.c \
121	bionic/signame.c \
122	bionic/sigsetmask.c \
123	bionic/sleep.c \
124	bionic/strndup.c \
125	bionic/strntoimax.c \
126	bionic/strntoumax.c \
127	bionic/strtotimeval.c \
128	bionic/system_properties.c \
129	bionic/system_properties_compat.c \
130	bionic/tcgetpgrp.c \
131	bionic/tcsetpgrp.c \
132	bionic/time64.c \
133	bionic/umount.c \
134	bionic/unlockpt.c \
135	bionic/usleep.c \
136	bionic/utmp.c \
137	bionic/wcscoll.c \
138
139
140libc_dns_src_files += \
141    netbsd/gethnamaddr.c \
142    netbsd/inet/nsap_addr.c \
143    netbsd/nameser/ns_name.c \
144    netbsd/nameser/ns_netint.c \
145    netbsd/nameser/ns_parse.c \
146    netbsd/nameser/ns_print.c \
147    netbsd/nameser/ns_samedomain.c \
148    netbsd/nameser/ns_ttl.c \
149    netbsd/net/base64.c \
150    netbsd/net/getaddrinfo.c \
151    netbsd/net/getnameinfo.c \
152    netbsd/net/getservbyname.c \
153    netbsd/net/getservbyport.c \
154    netbsd/net/getservent.c \
155    netbsd/net/nsdispatch.c \
156    netbsd/resolv/__dn_comp.c \
157    netbsd/resolv/herror.c \
158    netbsd/resolv/res_cache.c \
159    netbsd/resolv/__res_close.c \
160    netbsd/resolv/res_comp.c \
161    netbsd/resolv/res_data.c \
162    netbsd/resolv/res_debug.c \
163    netbsd/resolv/res_init.c \
164    netbsd/resolv/res_mkquery.c \
165    netbsd/resolv/res_query.c \
166    netbsd/resolv/__res_send.c \
167    netbsd/resolv/res_send.c \
168    netbsd/resolv/res_state.c \
169
170
171# These are used by the 32-bit targets, but not the 64-bit ones.
172ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
173libc_common_src_files += \
174    bionic/legacy_32_bit_support.cpp \
175    bionic/ndk_cruft.cpp \
176
177endif
178
179# Fortify implementations of libc functions.
180libc_common_src_files += \
181    bionic/__FD_chk.cpp \
182    bionic/__fgets_chk.cpp \
183    bionic/__memcpy_chk.cpp \
184    bionic/__memmove_chk.cpp \
185    bionic/__memset_chk.cpp \
186    bionic/__read_chk.cpp \
187    bionic/__recvfrom_chk.cpp \
188    bionic/__strcat_chk.cpp \
189    bionic/__strchr_chk.cpp \
190    bionic/__strcpy_chk.cpp \
191    bionic/__strlcat_chk.cpp \
192    bionic/__strlcpy_chk.cpp \
193    bionic/__strlen_chk.cpp \
194    bionic/__strncat_chk.cpp \
195    bionic/__strncpy_chk.cpp \
196    bionic/__strrchr_chk.cpp \
197    bionic/__umask_chk.cpp \
198    bionic/__vsnprintf_chk.cpp \
199    bionic/__vsprintf_chk.cpp \
200
201libc_bionic_src_files := \
202    bionic/abort.cpp \
203    bionic/access.cpp \
204    bionic/assert.cpp \
205    bionic/bionic_time_conversions.cpp \
206    bionic/brk.cpp \
207    bionic/chmod.cpp \
208    bionic/chown.cpp \
209    bionic/clone.cpp \
210    bionic/dirent.cpp \
211    bionic/dup2.cpp \
212    bionic/epoll_create.cpp \
213    bionic/epoll_wait.cpp \
214    bionic/epoll_pwait.cpp \
215    bionic/__errno.cpp \
216    bionic/eventfd_read.cpp \
217    bionic/eventfd_write.cpp \
218    bionic/ffs.cpp \
219    bionic/fork.cpp \
220    bionic/futimens.cpp \
221    bionic/getauxval.cpp \
222    bionic/getcwd.cpp \
223    bionic/inotify_init.cpp \
224    bionic/lchown.cpp \
225    bionic/libc_init_common.cpp \
226    bionic/libc_logging.cpp \
227    bionic/libgen.cpp \
228    bionic/link.cpp \
229    bionic/lstat.cpp \
230    bionic/mkdir.cpp \
231    bionic/mkfifo.cpp \
232    bionic/mknod.cpp \
233    bionic/open.cpp \
234    bionic/pause.cpp \
235    bionic/pipe.cpp \
236    bionic/poll.cpp \
237    bionic/pthread_atfork.cpp \
238    bionic/pthread_attr.cpp \
239    bionic/pthread_cond.cpp \
240    bionic/pthread_create.cpp \
241    bionic/pthread_detach.cpp \
242    bionic/pthread_equal.cpp \
243    bionic/pthread_exit.cpp \
244    bionic/pthread_getcpuclockid.cpp \
245    bionic/pthread_getschedparam.cpp \
246    bionic/pthread_internals.cpp \
247    bionic/pthread_join.cpp \
248    bionic/pthread_key.cpp \
249    bionic/pthread_kill.cpp \
250    bionic/pthread_mutex.cpp \
251    bionic/pthread_once.cpp \
252    bionic/pthread_rwlock.cpp \
253    bionic/pthread_self.cpp \
254    bionic/pthread_setname_np.cpp \
255    bionic/pthread_setschedparam.cpp \
256    bionic/pthread_sigmask.cpp \
257    bionic/ptrace.cpp \
258    bionic/raise.cpp \
259    bionic/readlink.cpp \
260    bionic/rename.cpp \
261    bionic/rmdir.cpp \
262    bionic/sbrk.cpp \
263    bionic/scandir.cpp \
264    bionic/sched_getaffinity.cpp \
265    bionic/setegid.cpp \
266    bionic/__set_errno.cpp \
267    bionic/seteuid.cpp \
268    bionic/setlocale.cpp \
269    bionic/signalfd.cpp \
270    bionic/sigaction.cpp \
271    bionic/sigaddset.cpp \
272    bionic/sigdelset.cpp \
273    bionic/sigemptyset.cpp \
274    bionic/sigfillset.cpp \
275    bionic/sigismember.cpp \
276    bionic/signal.cpp \
277    bionic/sigpending.cpp \
278    bionic/sigprocmask.cpp \
279    bionic/sigsuspend.cpp \
280    bionic/sigwait.cpp \
281    bionic/stat.cpp \
282    bionic/statvfs.cpp \
283    bionic/strerror.cpp \
284    bionic/strerror_r.cpp \
285    bionic/strsignal.cpp \
286    bionic/stubs.cpp \
287    bionic/symlink.cpp \
288    bionic/sysconf.cpp \
289    bionic/thread_atexit.cpp \
290    bionic/tdestroy.cpp \
291    bionic/timer.cpp \
292    bionic/tmpfile.cpp \
293    bionic/unlink.cpp \
294    bionic/utimes.cpp \
295    bionic/wait.cpp \
296    bionic/wchar.cpp \
297
298# These are shared by all the 32-bit targets, but not the 64-bit ones.
299ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
300libc_bionic_src_files += \
301    bionic/mmap.cpp \
302
303endif
304
305libc_tzcode_src_files := \
306    tzcode/asctime.c \
307    tzcode/difftime.c \
308    tzcode/localtime.c \
309    tzcode/strftime.c \
310    tzcode/strptime.c \
311
312libc_upstream_freebsd_src_files := \
313    upstream-freebsd/lib/libc/stdio/clrerr.c \
314    upstream-freebsd/lib/libc/stdio/fclose.c \
315    upstream-freebsd/lib/libc/stdio/fdopen.c \
316    upstream-freebsd/lib/libc/stdio/feof.c \
317    upstream-freebsd/lib/libc/stdio/ferror.c \
318    upstream-freebsd/lib/libc/stdio/fgetln.c \
319    upstream-freebsd/lib/libc/stdio/fgetpos.c \
320    upstream-freebsd/lib/libc/stdio/fgets.c \
321    upstream-freebsd/lib/libc/stdio/fileno.c \
322    upstream-freebsd/lib/libc/stdio/flags.c \
323    upstream-freebsd/lib/libc/stdio/fopen.c \
324    upstream-freebsd/lib/libc/stdio/fpurge.c \
325    upstream-freebsd/lib/libc/stdio/fputs.c \
326    upstream-freebsd/lib/libc/stdio/fsetpos.c \
327    upstream-freebsd/lib/libc/stdio/funopen.c \
328    upstream-freebsd/lib/libc/stdio/fwalk.c \
329    upstream-freebsd/lib/libc/stdio/fwrite.c \
330    upstream-freebsd/lib/libc/stdio/getc.c \
331    upstream-freebsd/lib/libc/stdio/getchar.c \
332    upstream-freebsd/lib/libc/stdio/makebuf.c \
333    upstream-freebsd/lib/libc/stdio/mktemp.c \
334    upstream-freebsd/lib/libc/stdio/putc.c \
335    upstream-freebsd/lib/libc/stdio/putchar.c \
336    upstream-freebsd/lib/libc/stdio/puts.c \
337    upstream-freebsd/lib/libc/stdio/putw.c \
338    upstream-freebsd/lib/libc/stdio/remove.c \
339    upstream-freebsd/lib/libc/stdio/rget.c \
340    upstream-freebsd/lib/libc/stdio/setbuf.c \
341    upstream-freebsd/lib/libc/stdio/setbuffer.c \
342    upstream-freebsd/lib/libc/stdio/setvbuf.c \
343    upstream-freebsd/lib/libc/stdio/tempnam.c \
344    upstream-freebsd/lib/libc/stdio/tmpnam.c \
345    upstream-freebsd/lib/libc/stdio/wsetup.c \
346    upstream-freebsd/lib/libc/stdlib/abs.c \
347    upstream-freebsd/lib/libc/stdlib/getopt_long.c \
348    upstream-freebsd/lib/libc/stdlib/imaxabs.c \
349    upstream-freebsd/lib/libc/stdlib/imaxdiv.c \
350    upstream-freebsd/lib/libc/stdlib/labs.c \
351    upstream-freebsd/lib/libc/stdlib/llabs.c \
352    upstream-freebsd/lib/libc/stdlib/qsort.c \
353    upstream-freebsd/lib/libc/stdlib/realpath.c \
354    upstream-freebsd/lib/libc/string/wcpcpy.c \
355    upstream-freebsd/lib/libc/string/wcpncpy.c \
356    upstream-freebsd/lib/libc/string/wcscasecmp.c \
357    upstream-freebsd/lib/libc/string/wcscspn.c \
358    upstream-freebsd/lib/libc/string/wcsdup.c \
359    upstream-freebsd/lib/libc/string/wcslcat.c \
360    upstream-freebsd/lib/libc/string/wcslcpy.c \
361    upstream-freebsd/lib/libc/string/wcsncasecmp.c \
362    upstream-freebsd/lib/libc/string/wcsncat.c \
363    upstream-freebsd/lib/libc/string/wcsncmp.c \
364    upstream-freebsd/lib/libc/string/wcsncpy.c \
365    upstream-freebsd/lib/libc/string/wcsnlen.c \
366    upstream-freebsd/lib/libc/string/wcspbrk.c \
367    upstream-freebsd/lib/libc/string/wcsspn.c \
368    upstream-freebsd/lib/libc/string/wcsstr.c \
369    upstream-freebsd/lib/libc/string/wcstok.c \
370    upstream-freebsd/lib/libc/string/wmemchr.c \
371    upstream-freebsd/lib/libc/string/wmemcpy.c \
372    upstream-freebsd/lib/libc/string/wmemmove.c \
373    upstream-freebsd/lib/libc/string/wmemset.c \
374
375libc_upstream_netbsd_src_files := \
376    upstream-netbsd/common/lib/libc/hash/sha1/sha1.c \
377    upstream-netbsd/common/lib/libc/inet/inet_addr.c \
378    upstream-netbsd/libc/compat-43/creat.c \
379    upstream-netbsd/libc/gen/ftw.c \
380    upstream-netbsd/libc/gen/nftw.c \
381    upstream-netbsd/libc/gen/nice.c \
382    upstream-netbsd/libc/gen/popen.c \
383    upstream-netbsd/libc/gen/psignal.c \
384    upstream-netbsd/libc/gen/setjmperr.c \
385    upstream-netbsd/libc/gen/utime.c \
386    upstream-netbsd/libc/inet/inet_ntoa.c \
387    upstream-netbsd/libc/inet/inet_ntop.c \
388    upstream-netbsd/libc/inet/inet_pton.c \
389    upstream-netbsd/libc/isc/ev_streams.c \
390    upstream-netbsd/libc/isc/ev_timers.c \
391    upstream-netbsd/libc/regex/regcomp.c \
392    upstream-netbsd/libc/regex/regerror.c \
393    upstream-netbsd/libc/regex/regexec.c \
394    upstream-netbsd/libc/regex/regfree.c \
395    upstream-netbsd/libc/stdio/getdelim.c \
396    upstream-netbsd/libc/stdio/getline.c \
397    upstream-netbsd/libc/stdlib/bsearch.c \
398    upstream-netbsd/libc/stdlib/div.c \
399    upstream-netbsd/libc/stdlib/drand48.c \
400    upstream-netbsd/libc/stdlib/erand48.c \
401    upstream-netbsd/libc/stdlib/exit.c \
402    upstream-netbsd/libc/stdlib/jrand48.c \
403    upstream-netbsd/libc/stdlib/ldiv.c \
404    upstream-netbsd/libc/stdlib/lldiv.c \
405    upstream-netbsd/libc/stdlib/lrand48.c \
406    upstream-netbsd/libc/stdlib/mrand48.c \
407    upstream-netbsd/libc/stdlib/nrand48.c \
408    upstream-netbsd/libc/stdlib/_rand48.c \
409    upstream-netbsd/libc/stdlib/seed48.c \
410    upstream-netbsd/libc/stdlib/srand48.c \
411    upstream-netbsd/libc/stdlib/tdelete.c \
412    upstream-netbsd/libc/stdlib/tfind.c \
413    upstream-netbsd/libc/stdlib/tsearch.c \
414    upstream-netbsd/libc/string/memccpy.c \
415    upstream-netbsd/libc/string/strcasestr.c \
416    upstream-netbsd/libc/string/strcoll.c \
417    upstream-netbsd/libc/string/strxfrm.c \
418    upstream-netbsd/libc/thread-stub/__isthreaded.c \
419    upstream-netbsd/libc/unistd/killpg.c \
420
421# Architecture specific source files go here
422# =========================================================
423ifeq ($(TARGET_ARCH),arm)
424libc_common_src_files += \
425    bionic/memchr.c \
426    bionic/memmove.c.arm \
427    bionic/memrchr.c \
428    bionic/strchr.cpp \
429    bionic/strnlen.c \
430    string/bcopy.c \
431    string/index.c \
432    string/strlcat.c \
433    string/strlcpy.c \
434    string/strncat.c \
435    string/strncmp.c \
436    string/strncpy.c \
437    string/strrchr.c \
438    upstream-freebsd/lib/libc/string/wcscat.c \
439    upstream-freebsd/lib/libc/string/wcschr.c \
440    upstream-freebsd/lib/libc/string/wcscmp.c \
441    upstream-freebsd/lib/libc/string/wcscpy.c \
442    upstream-freebsd/lib/libc/string/wcslen.c \
443    upstream-freebsd/lib/libc/string/wcsrchr.c \
444    upstream-freebsd/lib/libc/string/wmemcmp.c \
445
446endif # arm
447
448ifeq ($(TARGET_ARCH),mips)
449libc_common_src_files += \
450    bionic/memchr.c \
451    bionic/memcmp.c \
452    bionic/memrchr.c \
453    bionic/strchr.cpp \
454    bionic/strnlen.c \
455    string/bcopy.c \
456    string/index.c \
457    string/strcat.c \
458    string/strcmp.c \
459    string/strcpy.c \
460    string/strlcat.c \
461    string/strlcpy.c \
462    string/strncat.c \
463    string/strncmp.c \
464    string/strncpy.c \
465    string/strrchr.c \
466    upstream-freebsd/lib/libc/string/wcscat.c \
467    upstream-freebsd/lib/libc/string/wcschr.c \
468    upstream-freebsd/lib/libc/string/wcscmp.c \
469    upstream-freebsd/lib/libc/string/wcscpy.c \
470    upstream-freebsd/lib/libc/string/wcslen.c \
471    upstream-freebsd/lib/libc/string/wcsrchr.c \
472    upstream-freebsd/lib/libc/string/wmemcmp.c \
473
474endif # mips
475
476ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
477libc_common_src_files += \
478    bionic/memchr.c \
479    bionic/memcmp.c \
480    bionic/memcpy.c \
481    bionic/memmove.c \
482    bionic/memrchr.c \
483    bionic/memset.c \
484    bionic/strchr.cpp \
485    bionic/strnlen.c \
486    string/bcopy.c \
487    string/index.c \
488    string/strcat.c \
489    string/strcmp.c \
490    string/strcpy.c \
491    string/strlcat.c \
492    string/strlcpy.c \
493    string/strlen.c \
494    string/strncat.c \
495    string/strncmp.c \
496    string/strncpy.c \
497    string/strrchr.c \
498    upstream-freebsd/lib/libc/string/wcscat.c \
499    upstream-freebsd/lib/libc/string/wcschr.c \
500    upstream-freebsd/lib/libc/string/wcscmp.c \
501    upstream-freebsd/lib/libc/string/wcscpy.c \
502    upstream-freebsd/lib/libc/string/wcslen.c \
503    upstream-freebsd/lib/libc/string/wcsrchr.c \
504    upstream-freebsd/lib/libc/string/wmemcmp.c \
505
506endif # x86_64
507
508ifeq ($(TARGET_ARCH),arm)
509  ifeq ($(strip $(TARGET_CPU_VARIANT)),)
510    $(warning TARGET_ARCH is arm, but TARGET_CPU_VARIANT is not defined)
511  endif
512endif
513
514###########################################################
515## Add cpu specific source files.
516##
517## This can be called multiple times, but it will only add
518## the first source file for each unique $(1).
519## $(1): Unique identifier to identify the cpu variant
520##       implementation.
521## $(2): Cpu specific source file.
522###########################################################
523
524define libc-add-cpu-variant-src
525$(if $(filter true,$(_LIBC_ARCH_CPU_VARIANT_HAS_$(1))), \
526	, \
527     $(eval _LIBC_ARCH_CPU_VARIANT_HAS_$(1) := true) \
528     $(eval _LIBC_ARCH_CPU_VARIANT_SRC_FILE.$(1) := $(2)) \
529     $(eval _LIBC_ARCH_CPU_VARIANT_SRC_FILES += $(2)) \
530)
531endef
532
533_LIBC_ARCH_COMMON_SRC_FILES :=
534_LIBC_ARCH_CPU_VARIANT_SRC_FILES :=
535_LIBC_ARCH_STATIC_SRC_FILES :=
536_LIBC_ARCH_DYNAMIC_SRC_FILES :=
537_LIBC_ARCH_ADDITIONAL_DEPENDENCIES :=
538
539libc_common_additional_dependencies += \
540    $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
541include $(LOCAL_PATH)/arch-$(TARGET_ARCH)/$(TARGET_ARCH).mk
542
543libc_bionic_src_files += $(_LIBC_ARCH_COMMON_SRC_FILES)
544libc_bionic_src_files += $(_LIBC_ARCH_CPU_VARIANT_SRC_FILES)
545libc_arch_static_src_files := $(_LIBC_ARCH_STATIC_SRC_FILES)
546libc_arch_dynamic_src_files := $(_LIBC_ARCH_DYNAMIC_SRC_FILES)
547libc_common_additional_dependencies += $(_LIBC_ARCH_ADDITIONAL_DEPENDENCIES)
548
549# Define some common cflags
550# ========================================================
551libc_common_cflags := \
552    -DANDROID_CHANGES \
553    -D_LIBC=1 \
554    -Wall -Wextra \
555
556# Try to catch typical 32-bit assumptions that break with 64-bit pointers.
557libc_common_cflags += \
558    -Werror=pointer-to-int-cast \
559    -Werror=int-to-pointer-cast \
560    -Werror=type-limits \
561
562ifeq ($(strip $(DEBUG_BIONIC_LIBC)),true)
563  libc_common_cflags += -DDEBUG
564endif
565
566# To customize dlmalloc's alignment, set BOARD_MALLOC_ALIGNMENT in
567# the appropriate BoardConfig.mk file.
568#
569ifneq ($(BOARD_MALLOC_ALIGNMENT),)
570  libc_common_cflags += -DMALLOC_ALIGNMENT=$(BOARD_MALLOC_ALIGNMENT)
571endif
572
573ifeq ($(TARGET_ARCH),arm)
574  libc_common_cflags += -DSOFTFLOAT
575  libc_common_cflags += -fstrict-aliasing
576  libc_crt_target_cflags := -mthumb-interwork
577endif # arm
578
579ifeq ($(TARGET_ARCH),mips)
580  ifneq ($(ARCH_MIPS_HAS_FPU),true)
581    libc_common_cflags += -DSOFTFLOAT
582  endif
583  libc_common_cflags += -fstrict-aliasing
584  libc_crt_target_cflags := $(TARGET_GLOBAL_CFLAGS)
585endif # mips
586
587ifeq ($(TARGET_ARCH),x86)
588  libc_crt_target_cflags := -m32
589  libc_crt_target_ldflags := -melf_i386
590endif # x86
591
592ifeq ($(TARGET_ARCH),x86_64)
593  libc_crt_target_cflags := -m64
594  libc_crt_target_ldflags := -melf_x86_64
595endif # x86_64
596
597# Define ANDROID_SMP appropriately.
598ifeq ($(TARGET_CPU_SMP),true)
599    libc_common_cflags += -DANDROID_SMP=1
600else
601    libc_common_cflags += -DANDROID_SMP=0
602endif
603
604# crtbrand.c needs <stdint.h> and a #define for the platform SDK version.
605libc_crt_target_cflags += \
606    -I$(LOCAL_PATH)/include  \
607    -I$(LOCAL_PATH)/arch-$(TARGET_ARCH)/include \
608    -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION) \
609
610# Define some common conlyflags
611libc_common_conlyflags := \
612    -std=gnu99
613
614# Define some common cppflags
615libc_common_cppflags := \
616    -std=gnu++11
617
618# Define some common includes
619# ========================================================
620libc_common_c_includes := \
621		$(LOCAL_PATH)/stdlib  \
622		$(LOCAL_PATH)/string  \
623		$(LOCAL_PATH)/stdio   \
624		external/safe-iop/include
625
626# Define the libc run-time (crt) support object files that must be built,
627# which are needed to build all other objects (shared/static libs and
628# executables)
629# ==========================================================================
630# ARM, MIPS, and x86 all need crtbegin_so/crtend_so.
631#
632# For x86, the .init section must point to a function that calls all
633# entries in the .ctors section. (on ARM this is done through the
634# .init_array section instead).
635#
636# For all the platforms, the .fini_array section must point to a function
637# that will call __cxa_finalize(&__dso_handle) in order to ensure that
638# static C++ destructors are properly called on dlclose().
639#
640libc_crt_target_crtbegin_file := $(LOCAL_PATH)/arch-common/bionic/crtbegin.c
641libc_crt_target_crtbegin_so_file := $(LOCAL_PATH)/arch-common/bionic/crtbegin_so.c
642
643ifeq ($(TARGET_ARCH),arm)
644    libc_crt_target_so_cflags :=
645endif
646ifeq ($(TARGET_ARCH),mips)
647    libc_crt_target_so_cflags := -fPIC
648libc_crt_target_crtbegin_file := $(LOCAL_PATH)/arch-$(TARGET_ARCH)/bionic/crtbegin.c
649endif
650ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
651    libc_crt_target_so_cflags := -fPIC
652endif
653libc_crt_target_so_cflags += $(libc_crt_target_cflags)
654
655# See the comment in crtbrand.c for the reason why we need to generate
656# crtbrand.s before generating crtbrand.o.
657GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.s
658$(GEN): $(LOCAL_PATH)/bionic/crtbrand.c
659	@mkdir -p $(dir $@)
660	$(hide) $(TARGET_CC) $(libc_crt_target_so_cflags) -S \
661		-MD -MF $(@:%.s=%.d) -o $@ $<
662	$(hide) sed -i -e '/\.note\.ABI-tag/s/progbits/note/' $@
663	$(call transform-d-to-p-args,$(@:%.s=%.d),$(@:%.s=%.P))
664-include $(GEN:%.s=%.P)
665ALL_GENERATED_SOURCES += $(GEN)
666
667GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
668$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.s
669	@mkdir -p $(dir $@)
670	$(hide) $(TARGET_CC) $(libc_crt_target_so_cflags) -o $@ -c $<
671ALL_GENERATED_SOURCES += $(GEN)
672
673GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
674$(GEN): $(libc_crt_target_crtbegin_so_file)
675	@mkdir -p $(dir $@)
676	$(hide) $(TARGET_CC) $(libc_crt_target_so_cflags) \
677		-MD -MF $(@:%.o=%.d) -o $@ -c $<
678	$(transform-d-to-p)
679-include $(GEN:%.o=%.P)
680ALL_GENERATED_SOURCES += $(GEN)
681
682GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
683$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend_so.S
684	@mkdir -p $(dir $@)
685	$(hide) $(TARGET_CC) $(libc_crt_target_so_cflags) \
686		-MD -MF $(@:%.o=%.d) -o $@ -c $<
687	$(transform-d-to-p)
688-include $(GEN:%.o=%.P)
689ALL_GENERATED_SOURCES += $(GEN)
690
691# The following two are installed to device
692GEN := $(TARGET_OUT_SHARED_LIBRARIES)/crtbegin_so.o
693$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
694	$(hide) mkdir -p $(dir $@) && cp -f $< $@
695ALL_GENERATED_SOURCES += $(GEN)
696
697GEN := $(TARGET_OUT_SHARED_LIBRARIES)/crtend_so.o
698$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
699	$(hide) mkdir -p $(dir $@) && cp -f $< $@
700ALL_GENERATED_SOURCES += $(GEN)
701
702
703GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o
704$(GEN): $(libc_crt_target_crtbegin_file)
705	@mkdir -p $(dir $@)
706	$(hide) $(TARGET_CC) $(libc_crt_target_cflags) \
707		-MD -MF $(@:%.o=%.d) -o $@ -c $<
708	$(transform-d-to-p)
709-include $(GEN:%.o=%.P)
710ALL_GENERATED_SOURCES += $(GEN)
711
712GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
713$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static1.o $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
714	@mkdir -p $(dir $@)
715	$(hide) $(TARGET_LD) $(libc_crt_target_ldflags) -r -o $@ $^
716ALL_GENERATED_SOURCES += $(GEN)
717
718GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o
719$(GEN): $(libc_crt_target_crtbegin_file)
720	@mkdir -p $(dir $@)
721	$(hide) $(TARGET_CC) $(libc_crt_target_cflags) \
722		-MD -MF $(@:%.o=%.d) -o $@ -c $<
723	$(transform-d-to-p)
724-include $(GEN:%.o=%.P)
725ALL_GENERATED_SOURCES += $(GEN)
726
727GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
728$(GEN): $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic1.o $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbrand.o
729	@mkdir -p $(dir $@)
730	$(hide) $(TARGET_LD) $(libc_crt_target_ldflags) -r -o $@ $^
731ALL_GENERATED_SOURCES += $(GEN)
732
733# We rename crtend.o to crtend_android.o to avoid a
734# name clash between gcc and bionic.
735GEN := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
736$(GEN): $(LOCAL_PATH)/arch-common/bionic/crtend.S
737	@mkdir -p $(dir $@)
738	$(hide) $(TARGET_CC) $(libc_crt_target_cflags) \
739		-MD -MF $(@:%.o=%.d) -o $@ -c $<
740	$(transform-d-to-p)
741-include $(GEN:%.o=%.P)
742ALL_GENERATED_SOURCES += $(GEN)
743
744
745# To enable malloc leak check for statically linked programs, add
746# "WITH_MALLOC_CHECK_LIBC_A := true" to buildspec.mk
747WITH_MALLOC_CHECK_LIBC_A := $(strip $(WITH_MALLOC_CHECK_LIBC_A))
748
749# ========================================================
750# libbionic_ssp.a - stack protector code
751# ========================================================
752#
753# The stack protector code needs to be compiled
754# with -fno-stack-protector, since it modifies the
755# stack canary.
756
757include $(CLEAR_VARS)
758
759LOCAL_SRC_FILES := bionic/__stack_chk_fail.cpp
760LOCAL_CFLAGS := $(libc_common_cflags) -fno-stack-protector -Werror
761LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
762LOCAL_CPPFLAGS := $(libc_common_cppflags)
763LOCAL_C_INCLUDES := $(libc_common_c_includes)
764LOCAL_MODULE := libbionic_ssp
765LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
766LOCAL_SYSTEM_SHARED_LIBRARIES :=
767
768include $(BUILD_STATIC_LIBRARY)
769
770
771# ========================================================
772# libc_tzcode.a - upstream 'tzcode' code
773# ========================================================
774
775include $(CLEAR_VARS)
776
777LOCAL_SRC_FILES := $(libc_tzcode_src_files)
778LOCAL_CFLAGS := \
779    $(libc_common_cflags) \
780    -DSTD_INSPIRED=1 \
781    -DTZDIR=\"/system/usr/share/zoneinfo\" \
782    -DTM_GMTOFF=tm_gmtoff \
783    -DUSG_COMPAT=1
784LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
785LOCAL_CPPFLAGS := $(libc_common_cppflags)
786LOCAL_C_INCLUDES := $(libc_common_c_includes)
787LOCAL_MODULE := libc_tzcode
788LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
789LOCAL_SYSTEM_SHARED_LIBRARIES :=
790
791include $(BUILD_STATIC_LIBRARY)
792
793
794# ========================================================
795# libc_dns.a - modified NetBSD DNS code
796# ========================================================
797
798include $(CLEAR_VARS)
799
800LOCAL_SRC_FILES := $(libc_dns_src_files)
801LOCAL_CFLAGS := \
802    $(libc_common_cflags) \
803    -DINET6 \
804    -I$(LOCAL_PATH)/private \
805    -I$(LOCAL_PATH)/upstream-netbsd/libc/include # for NetBSD private headers
806
807LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
808LOCAL_CPPFLAGS := $(libc_common_cppflags)
809LOCAL_C_INCLUDES := $(libc_common_c_includes)
810LOCAL_MODULE := libc_dns
811LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
812LOCAL_SYSTEM_SHARED_LIBRARIES :=
813
814include $(BUILD_STATIC_LIBRARY)
815
816
817# ========================================================
818# libc_freebsd.a - upstream FreeBSD C library code
819# ========================================================
820#
821# These files are built with the freebsd-compat.h header file
822# automatically included.
823
824include $(CLEAR_VARS)
825
826LOCAL_SRC_FILES := $(libc_upstream_freebsd_src_files)
827LOCAL_CFLAGS := \
828    $(libc_common_cflags) \
829    -I$(LOCAL_PATH)/upstream-freebsd \
830    -I$(LOCAL_PATH)/upstream-freebsd/libc/include \
831    -include upstream-freebsd/freebsd-compat.h
832LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
833LOCAL_CPPFLAGS := $(libc_common_cppflags)
834LOCAL_C_INCLUDES := $(libc_common_c_includes)
835LOCAL_MODULE := libc_freebsd
836LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
837LOCAL_SYSTEM_SHARED_LIBRARIES :=
838
839include $(BUILD_STATIC_LIBRARY)
840
841
842# ========================================================
843# libc_netbsd.a - upstream NetBSD C library code
844# ========================================================
845#
846# These files are built with the netbsd-compat.h header file
847# automatically included.
848
849include $(CLEAR_VARS)
850
851LOCAL_SRC_FILES := $(libc_upstream_netbsd_src_files)
852LOCAL_CFLAGS := \
853    $(libc_common_cflags) \
854    -DPOSIX_MISTAKE \
855    -I$(LOCAL_PATH)/upstream-netbsd \
856    -I$(LOCAL_PATH)/upstream-netbsd/libc/include \
857    -include upstream-netbsd/netbsd-compat.h
858LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
859LOCAL_CPPFLAGS := $(libc_common_cppflags)
860LOCAL_C_INCLUDES := $(libc_common_c_includes)
861LOCAL_MODULE := libc_netbsd
862LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
863LOCAL_SYSTEM_SHARED_LIBRARIES :=
864
865include $(BUILD_STATIC_LIBRARY)
866
867
868# ========================================================
869# libc_bionic.a - home-grown C library code
870# ========================================================
871#
872include $(CLEAR_VARS)
873
874LOCAL_SRC_FILES := $(libc_bionic_src_files)
875LOCAL_CFLAGS := $(libc_common_cflags) -Werror
876LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
877LOCAL_CPPFLAGS := $(libc_common_cppflags)
878LOCAL_C_INCLUDES := $(libc_common_c_includes)
879LOCAL_MODULE := libc_bionic
880LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
881LOCAL_SYSTEM_SHARED_LIBRARIES :=
882
883# Set -DPTHREAD_DEBUG_ENABLED=true to enable support for pthread deadlock prediction.
884# Since this code is experimental it is disabled by default.
885LOCAL_CFLAGS += $(libc_common_cflags) -DPTHREAD_DEBUG_ENABLED=false
886
887include $(BUILD_STATIC_LIBRARY)
888
889
890# ========================================================
891# libc_common.a
892# ========================================================
893
894include $(CLEAR_VARS)
895
896LOCAL_SRC_FILES := $(libc_common_src_files)
897LOCAL_CFLAGS := $(libc_common_cflags)
898LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
899LOCAL_CPPFLAGS := $(libc_common_cppflags)
900LOCAL_C_INCLUDES := $(libc_common_c_includes)
901LOCAL_MODULE := libc_common
902LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
903LOCAL_WHOLE_STATIC_LIBRARIES := \
904    libbionic_ssp \
905    libc_bionic \
906    libc_dns \
907    libc_freebsd \
908    libc_netbsd \
909    libc_tzcode \
910
911LOCAL_SYSTEM_SHARED_LIBRARIES :=
912
913# TODO: split out the asflags.
914LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
915
916include $(BUILD_STATIC_LIBRARY)
917
918
919# ========================================================
920# libc_nomalloc.a
921# ========================================================
922#
923# This is a version of the static C library that does not
924# include malloc. It's useful in situations when the user wants
925# to provide their own malloc implementation, or wants to
926# explicitly disallow the use of the use of malloc,
927# such as in the dynamic loader.
928
929include $(CLEAR_VARS)
930
931LOCAL_SRC_FILES := \
932	$(libc_arch_static_src_files) \
933	$(libc_static_common_src_files) \
934	bionic/libc_init_static.cpp
935
936LOCAL_C_INCLUDES := $(libc_common_c_includes)
937LOCAL_CFLAGS := $(libc_common_cflags) \
938                -DLIBC_STATIC
939LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
940LOCAL_CPPFLAGS := $(libc_common_cppflags)
941
942LOCAL_MODULE := libc_nomalloc
943LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
944LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
945LOCAL_SYSTEM_SHARED_LIBRARIES :=
946
947include $(BUILD_STATIC_LIBRARY)
948
949
950# ========================================================
951# libc.a
952# ========================================================
953include $(CLEAR_VARS)
954
955LOCAL_SRC_FILES := \
956	$(libc_arch_static_src_files) \
957	$(libc_static_common_src_files) \
958	bionic/dlmalloc.c \
959	bionic/malloc_debug_common.cpp \
960	bionic/libc_init_static.cpp
961
962LOCAL_CFLAGS := $(libc_common_cflags) \
963                -DLIBC_STATIC
964LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
965LOCAL_CPPFLAGS := $(libc_common_cppflags)
966LOCAL_C_INCLUDES := $(libc_common_c_includes)
967LOCAL_MODULE := libc
968LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
969LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
970LOCAL_SYSTEM_SHARED_LIBRARIES :=
971
972include $(BUILD_STATIC_LIBRARY)
973
974
975# ========================================================
976# libc.so
977# ========================================================
978include $(CLEAR_VARS)
979
980LOCAL_CFLAGS := $(libc_common_cflags)
981LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
982LOCAL_CPPFLAGS := $(libc_common_cppflags)
983LOCAL_C_INCLUDES := $(libc_common_c_includes)
984
985LOCAL_SRC_FILES := \
986	$(libc_arch_dynamic_src_files) \
987	$(libc_static_common_src_files) \
988	bionic/dlmalloc.c \
989	bionic/malloc_debug_common.cpp \
990	bionic/pthread_debug.cpp \
991	bionic/libc_init_dynamic.cpp
992
993ifeq ($(TARGET_ARCH),arm)
994	LOCAL_NO_CRT := true
995	LOCAL_CFLAGS += -DCRT_LEGACY_WORKAROUND
996
997	LOCAL_SRC_FILES := \
998		arch-common/bionic/crtbegin_so.c \
999		arch-arm/bionic/atexit_legacy.c \
1000		$(LOCAL_SRC_FILES) \
1001		arch-common/bionic/crtend_so.S
1002endif
1003
1004LOCAL_MODULE:= libc
1005LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
1006LOCAL_REQUIRED_MODULES := tzdata
1007
1008# WARNING: The only library libc.so should depend on is libdl.so!  If you add other libraries,
1009# make sure to add -Wl,--exclude-libs=libgcc.a to the LOCAL_LDFLAGS for those libraries.  This
1010# ensures that symbols that are pulled into those new libraries from libgcc.a are not declared
1011# external; if that were the case, then libc would not pull those symbols from libgcc.a as it
1012# should, instead relying on the external symbols from the dependent libraries.  That would
1013# create an "cloaked" dependency on libgcc.a in libc though the libraries, which is not what
1014# you wanted!
1015
1016LOCAL_SHARED_LIBRARIES := libdl
1017LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
1018LOCAL_SYSTEM_SHARED_LIBRARIES :=
1019
1020include $(BUILD_SHARED_LIBRARY)
1021
1022
1023# For all builds, except for the -user build we will enable memory
1024# allocation checking (including memory leaks, buffer overwrites, etc.)
1025# Note that all these checks are also controlled by env. settings
1026# that can enable, or disable specific checks. Note also that some of
1027# the checks are available only in emulator and are implemeted in
1028# libc_malloc_qemu_instrumented.so.
1029ifneq ($(TARGET_BUILD_VARIANT),user)
1030
1031# ========================================================
1032# libc_malloc_debug_leak.so
1033# ========================================================
1034include $(CLEAR_VARS)
1035
1036LOCAL_CFLAGS := \
1037	$(libc_common_cflags) \
1038	-DMALLOC_LEAK_CHECK
1039LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
1040LOCAL_CPPFLAGS := $(libc_common_cppflags)
1041
1042LOCAL_C_INCLUDES := $(libc_common_c_includes)
1043
1044LOCAL_SRC_FILES := \
1045	bionic/debug_mapinfo.cpp \
1046	bionic/debug_stacktrace.cpp \
1047	bionic/malloc_debug_leak.cpp \
1048	bionic/malloc_debug_check.cpp \
1049
1050LOCAL_MODULE:= libc_malloc_debug_leak
1051LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
1052
1053LOCAL_SHARED_LIBRARIES := libc libdl
1054LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
1055LOCAL_SYSTEM_SHARED_LIBRARIES :=
1056LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
1057
1058# Don't install on release build
1059LOCAL_MODULE_TAGS := eng debug
1060
1061include $(BUILD_SHARED_LIBRARY)
1062
1063
1064# ========================================================
1065# libc_malloc_debug_qemu.so
1066# ========================================================
1067include $(CLEAR_VARS)
1068
1069LOCAL_CFLAGS := \
1070	$(libc_common_cflags) \
1071	-DMALLOC_QEMU_INSTRUMENT
1072LOCAL_CONLYFLAGS := $(libc_common_conlyflags)
1073LOCAL_CPPFLAGS := $(libc_common_cppflags)
1074
1075LOCAL_C_INCLUDES := $(libc_common_c_includes)
1076
1077LOCAL_SRC_FILES := \
1078	bionic/malloc_debug_qemu.cpp
1079
1080LOCAL_MODULE:= libc_malloc_debug_qemu
1081LOCAL_ADDITIONAL_DEPENDENCIES := $(libc_common_additional_dependencies)
1082
1083LOCAL_SHARED_LIBRARIES := libc libdl
1084LOCAL_WHOLE_STATIC_LIBRARIES := libc_common
1085LOCAL_SYSTEM_SHARED_LIBRARIES :=
1086
1087# Don't install on release build
1088LOCAL_MODULE_TAGS := eng debug
1089
1090include $(BUILD_SHARED_LIBRARY)
1091
1092endif	#!user
1093
1094
1095# ========================================================
1096include $(call all-makefiles-under,$(LOCAL_PATH))
1097