summaryrefslogtreecommitdiffstats
path: root/usr/klibc/Kbuild
blob: 8b132190a12db17cb89ee9201af48bebb7346063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#
# Kbuild file for klibc
#

# Tell that we are building klibc
export klibc-build := y

# Generate syscall stubs
klib-y += syscalls/
# Generate socket calls stubs
klib-y += socketcalls/
# zlib, if configured
klib-$(CONFIG_KLIBC_ZLIB) += zlib/
# arch specific .o files
klib-y += arch/$(KLIBCARCHDIR)/

klib-y += vsnprintf.o snprintf.o vsprintf.o sprintf.o \
	  asprintf.o vasprintf.o \
	  vsscanf.o sscanf.o ctypes.o \
	  strntoumax.o strntoimax.o \
	  atoi.o atol.o atoll.o \
	  strtol.o strtoll.o strtoul.o strtoull.o \
	  strtoimax.o strtoumax.o \
	  globals.o exit.o atexit.o onexit.o \
	  execl.o execle.o execv.o execvpe.o execvp.o execlp.o execlpe.o \
	  fork.o vfork.o wait.o wait3.o waitpid.o system.o \
	  setpgrp.o getpgrp.o daemon.o \
	  printf.o vprintf.o fprintf.o vfprintf.o perror.o \
	  statfs.o fstatfs.o umount.o \
	  creat.o open.o openat.o \
	  fread2.o fwrite2.o fgets.o fputc.o fputs.o puts.o putchar.o \
	  clock_nanosleep.o nanosleep.o sleep.o usleep.o \
	  strtotimespec.o strtotimeval.o \
	  raise.o abort.o assert.o alarm.o pause.o \
	  __signal.o sysv_signal.o bsd_signal.o siglist.o sigabbrev.o \
	  siglongjmp.o \
	  sigaction.o sigpending.o sigprocmask.o sigsuspend.o \
	  pselect.o ppoll.o \
	  pread.o pwrite.o \
	  brk.o sbrk.o malloc.o realloc.o zalloc.o calloc.o \
	  mmap.o shm_open.o shm_unlink.o \
	  memcpy.o memcmp.o memset.o memccpy.o memmem.o memswap.o \
	  memmove.o memchr.o memrchr.o bzero.o \
	  strcasecmp.o strncasecmp.o strndup.o strerror.o strsignal.o \
	  strcat.o strchr.o strcmp.o strcpy.o strdup.o strlen.o strnlen.o \
	  strncat.o strlcpy.o strlcat.o \
	  strstr.o strncmp.o strncpy.o strrchr.o \
	  strxspn.o strspn.o strcspn.o strpbrk.o strsep.o strtok.o \
	  strtok_r.o \
	  fnmatch.o \
	  gethostname.o getdomainname.o getcwd.o \
	  seteuid.o setegid.o \
	  getenv.o setenv.o putenv.o __put_env.o unsetenv.o \
	  clearenv.o nullenv.o \
	  getopt.o getopt_long.o readdir.o scandir.o alphasort.o remove.o \
	  syslog.o closelog.o pty.o isatty.o reboot.o \
	  gettimeofday.o settimeofday.o time.o \
	  lseek.o nice.o getpriority.o \
	  futimesat.o utime.o utimes.o \
	  qsort.o bsearch.o \
	  lrand48.o jrand48.o mrand48.o nrand48.o srand48.o seed48.o \
	  inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
	  inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
	  accept.o send.o recv.o \
	  access.o chmod.o chown.o dup2.o mknod.o poll.o rename.o renameat.o \
	  fstat.o fstatat.o lstat.o stat.o \
	  lchown.o link.o rmdir.o unlink.o mkdir.o \
	  readlink.o realpath.o select.o symlink.o pipe.o \
	  ctype/isalnum.o ctype/isalpha.o ctype/isascii.o \
	  ctype/isblank.o ctype/iscntrl.o ctype/isdigit.o \
	  ctype/isgraph.o ctype/islower.o ctype/isprint.o \
	  ctype/ispunct.o ctype/isspace.o ctype/isupper.o \
	  ctype/isxdigit.o ctype/tolower.o ctype/toupper.o \
	  userdb/getgrgid.o userdb/getgrnam.o userdb/getpwnam.o \
	  userdb/getpwuid.o userdb/root_group.o userdb/root_user.o \
	  setmntent.o endmntent.o getmntent.o \
	  stdio/fclose.o stdio/fopen.o stdio/fdopen.o \
	  stdio/fread.o stdio/fwrite.o stdio/fflush.o \
	  stdio/ungetc.o stdio/fgetc.o \
	  stdio/fseek.o stdio/ftell.o stdio/rewind.o \
	  stdio/fileno.o stdio/feof.o stdio/ferror.o stdio/clearerr.o \
	  sysconf/sysconf.o

klib-$(CONFIG_KLIBC_ERRLIST) += errlist.o

ifeq ($(CONFIG_KLIBC_ERRLIST),y)
KLIBCCFLAGS_strerror.o += -DWITH_ERRLIST
endif

# These pass a huge maximum length to the corresponding length-limiting
# functions
KLIBCCFLAGS_sprintf.o += $(call cc-option,-Wno-format-truncation, )
KLIBCCFLAGS_vsprintf.o += $(call cc-option,-Wno-format-truncation, )

# Clang 14 optimises zalloc() to recursively call calloc(), without
# this option
KLIBCCFLAGS_zalloc.o += $(call cc-option,-fno-builtin-malloc, )

# sigsuspend.c includes <klibc/havesyscall.h> generated by syscalls/
# build, so require that to build first
$(obj)/sigsuspend.o: $(obj)/syscalls/klib.list

#####
# Shared definitions
LIBC     := libc.a
SOLIB    := libc.so
SOHASH   := klibc.so
CRT0     := arch/$(KLIBCARCHDIR)/crt0.o
SHARED_STUB := shared-stub.o

always   := $(LIBC)
ifdef KLIBCSHAREDFLAGS
always   += $(SOLIB) $(SOHASH) $(SHARED_STUB)
endif
LIBC     := $(call objectify,$(LIBC))
SOLIB    := $(call objectify,$(SOLIB))
SOHASH   := $(call objectify,$(SOHASH))
CRT0     := $(call objectify,$(CRT0))
SHARED_STUB := $(call objectify,$(SHARED_STUB))

SOLIBHASH = $(shell cat $(SOLIB).hash)

#####
# Readable errormessages extracted from src..
targets += errlist.c
quiet_cmd_errlist = GEN     $@
      cmd_errlist = $(PERL) $< $(call flags,KLIBCCPPFLAGS) -errlist > $@ \
                    || rm -f $@

$(obj)/errlist.c: $(srctree)/$(src)/makeerrlist.pl
	$(call cmd,errlist)


# all .o files for all dirs
klib-o-files = $(shell cat $(obj)/klib.list \
		$(addsuffix /klib.list, $(klib-dirs)))
######
# Build static library: libc.a
targets += libc.a __static_init.o
quiet_cmd_libc = KLIBCAR $@
      cmd_libc = rm -f $@;						\
                 $(KLIBCAR) Dcq $@					\
		 $(call objectify,__static_init.o) $(klib-o-files);	\
                 $(KLIBCRANLIB) $@

$(LIBC): $(call objectify,__static_init.o) $(obj)/klib.list FORCE
	$(call if_changed,libc)

######
# Build shared library
targets += libc.so __shared_init.o

quiet_cmd_libcso = KLIBCLD $@
      cmd_libcso = $(KLIBCLD) $(KLIBCLDFLAGS) $(KLIBCSHAREDFLAGS) -o $@ \
			--start-group					\
				$(CRT0)					\
				$(call objectify,__shared_init.o)	\
				$(klib-o-files)				\
				$(KLIBCLIBGCC)				\
			--end-group

$(SOLIB): $(call objectify,__shared_init.o) $(obj)/klib.list FORCE
	$(call if_changed,libcso)


#####
# Build sha1 hash values
targets     += klibc.so libc.so.hash
hostprogs-y := sha1hash
clean-files += klibc-???????????????????????????.so

quiet_cmd_solibhash = HASH    $@
      cmd_solibhash = $(KLIBCNM) $< | egrep '^[0-9a-fA-F]+ [ADRTW] ' | \
                                        sort | $(obj)/sha1hash > $@
$(SOLIB).hash: $(SOLIB) $(obj)/sha1hash FORCE
	$(call if_changed,solibhash)

quiet_cmd_sohash = GEN     $@
      cmd_sohash = cat $< > $@;                                           \
                     $(KLIBCSTRIP) $(KLIBCSTRIPFLAGS) $@;                 \
		     chmod a+x $@;					  \
                     rm -f $(obj)/klibc-???????????????????????????.so;   \
                     ln -f $@ $(obj)/klibc-$(SOLIBHASH).so
$(SOHASH): $(SOLIB) $(SOLIB).hash
	$(call cmd,sohash)


#####
# build shared-stub.o
targets += shared-stub.o

quiet_cmd_interp = BUILD   $@
      cmd_interp = $(KLIBCCC) $(klibccflags) -D__ASSEMBLY__     \
                             -DLIBDIR=\"$(SHLIBDIR)\"         \
			     -DSOHASH=\"$(SOLIBHASH)\" \
			     -c -o $@ $<

$(SHARED_STUB): $(obj)/shared-stub.S $(SOLIB).hash
	$(call if_changed,interp)

#####
# Install klibc
install-rule:
	@echo "  INSTALL klibc to $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib"
	$(Q)$(foreach f, $(LIBC) $(CRT0), \
	  $(shell $(install-data) $(f) \
	          $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib))
ifdef KLIBCSHAREDFLAGS
	$(Q)$(foreach f, $(SOLIB) $(SHARED_STUB), \
	  $(shell $(install-data) $(f) \
	          $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib))
	$(Q)$(install-lib) $(obj)/klibc-$(SOLIBHASH).so \
	                      $(INSTALLROOT)$(INSTALLDIR)/$(KLIBCCROSS)lib
	$(Q)$(install-lib) $(obj)/klibc-$(SOLIBHASH).so \
	                      $(INSTALLROOT)$(SHLIBDIR)
endif

# Directories to visit during clean and install
subdir- := arch/$(KLIBCARCHDIR)/