2018-01-21 17:40:27 +01:00
|
|
|
|
2018-02-27 22:37:23 +01:00
|
|
|
libc_CC := x86_64-managarm-gcc
|
2018-01-21 17:40:27 +01:00
|
|
|
libc_CXX := x86_64-managarm-g++
|
|
|
|
|
2018-02-27 22:37:23 +01:00
|
|
|
libc_CPPFLAGS := -Wall
|
2018-01-21 19:51:23 +01:00
|
|
|
libc_CPPFLAGS += -I$(TREE_PATH)/options/internal/private
|
|
|
|
libc_CPPFLAGS += -I$(TREE_PATH)/options/ansi/include
|
|
|
|
libc_CPPFLAGS += -I$(TREE_PATH)/options/linux/include
|
|
|
|
libc_CPPFLAGS += -I$(TREE_PATH)/options/lsb/include
|
|
|
|
libc_CPPFLAGS += -I$(TREE_PATH)/options/posix/include
|
|
|
|
libc_CPPFLAGS += -I$(TREE_PATH)/options/internal/include
|
|
|
|
libc_CPPFLAGS += -I$(TREE_PATH)/sysdeps/managarm/include
|
2018-01-21 17:40:27 +01:00
|
|
|
libc_CPPFLAGS += -Igen
|
|
|
|
libc_CPPFLAGS += -I$(FRIGG_PATH)/include
|
|
|
|
libc_CPPFLAGS += -DFRIGG_HAVE_LIBC -DFRIGG_HIDDEN
|
|
|
|
|
2018-02-27 22:37:23 +01:00
|
|
|
libc_CFLAGS := $(libc_CPPFLAGS) -fPIC -O2
|
|
|
|
libc_CFLAGS += -fno-builtin
|
|
|
|
|
2018-01-21 17:40:27 +01:00
|
|
|
libc_CXXFLAGS := $(libc_CPPFLAGS) -fPIC -O2
|
|
|
|
libc_CXXFLAGS += -fno-builtin -fno-rtti -fno-exceptions
|
|
|
|
|
2018-01-21 19:51:23 +01:00
|
|
|
libc_BEGIN := options/internal/gcc-extra/mlibc_crtbegin.o
|
|
|
|
libc_END := options/internal/gcc-extra/mlibc_crtend.o
|
2018-01-21 17:40:27 +01:00
|
|
|
|
2018-01-24 21:17:53 +01:00
|
|
|
libc_gendir := gen
|
2018-01-21 17:40:27 +01:00
|
|
|
|
2018-01-24 19:52:23 +01:00
|
|
|
libc_include_dirs := options/internal/include \
|
|
|
|
options/ansi/include \
|
|
|
|
options/posix/include \
|
|
|
|
options/lsb/include \
|
2018-02-04 12:41:14 +01:00
|
|
|
options/linux/include \
|
|
|
|
sysdeps/managarm/include
|
2018-01-24 19:52:23 +01:00
|
|
|
|
2018-01-24 21:17:53 +01:00
|
|
|
pretty = @echo '\t\e[1m$2\e[0m $3'; if ! $1; then \
|
|
|
|
echo "\e[31mError in" '\e[1m$2\e[0m\e[31m $3!\e[39m' \
|
|
|
|
"Command line was:"; echo '\e[31m$1\e[39m'; exit 1; fi
|
|
|
|
quiet = @if ! $1; then \
|
|
|
|
echo "\e[31mError in" '\e[1m$2\e[0m\e[31m $3!\e[39m'\
|
|
|
|
"Command line was:"; echo '\e[31m$1\e[39m'; exit 1; fi
|
|
|
|
|
|
|
|
proto_cmd = $(PROTOC) \
|
|
|
|
--plugin=protoc-gen-frigg=$(MANAGARM_BUILD_PATH)/tools/frigg_pb/bin/frigg_pb \
|
|
|
|
--frigg_out=$(libc_gendir) --proto_path=$(MANAGARM_SRC_PATH)/bragi/proto $<
|
|
|
|
compile_s_cmd = $(libc_AS) -o $@ $($libc_ASFLAGS) $<
|
2018-02-27 22:37:23 +01:00
|
|
|
compile_c_cmd = $(libc_CC) -c -o $@ -std=c11 $(libc_CFLAGS) $<
|
|
|
|
compile_cxx_cmd = $(libc_CXX) -c -o $@ -std=c++17 $(libc_CXXFLAGS) $<
|
2018-01-24 20:35:22 +01:00
|
|
|
link_cxx_cmd = x86_64-managarm-g++ -shared -o $@ -nostdlib \
|
|
|
|
$(libc_BEGIN) $(libc_objects) -l:ld-init.so $(libc_END)
|
2018-01-24 19:52:23 +01:00
|
|
|
install_header_cmd = install -Dp $< $@
|
2018-01-24 20:11:15 +01:00
|
|
|
install_slib_cmd = install -Dp $< $@
|
2018-03-30 16:11:44 +02:00
|
|
|
install_crt_cmd = install -Dp $< $@
|
2018-01-24 20:11:15 +01:00
|
|
|
|
2018-01-24 21:17:53 +01:00
|
|
|
proto_pretty = $(call pretty,$(proto_cmd),protoc,$@)
|
|
|
|
compile_s_pretty = $(call pretty,$(compile_s_cmd),as,$@)
|
2018-02-27 22:37:23 +01:00
|
|
|
compile_c_pretty = $(call pretty,$(compile_c_cmd),cc,$@)
|
2018-01-24 20:35:22 +01:00
|
|
|
compile_cxx_pretty = $(call pretty,$(compile_cxx_cmd),c++,$@)
|
|
|
|
link_cxx_pretty = $(call pretty,$(link_cxx_cmd),link,$@)
|
2018-01-24 20:11:15 +01:00
|
|
|
install_header_pretty = $(call pretty,$(install_header_cmd),install,$@)
|
|
|
|
install_slib_pretty = $(call pretty,$(install_slib_cmd),install,$@)
|
2018-03-30 16:11:44 +02:00
|
|
|
install_crt_pretty = $(call pretty,$(install_crt_cmd),install,$@)
|
2018-01-24 19:52:23 +01:00
|
|
|
|
2018-01-24 19:38:04 +01:00
|
|
|
#Ansi
|
|
|
|
libc_includes := alloca.h \
|
|
|
|
assert.h \
|
|
|
|
ctype.h \
|
|
|
|
errno.h \
|
2018-03-25 20:09:23 +02:00
|
|
|
fenv.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
inttypes.h \
|
|
|
|
limits.h \
|
|
|
|
locale.h \
|
|
|
|
math.h \
|
2018-01-24 20:10:18 +01:00
|
|
|
bits/ansi/clockid_t.h \
|
|
|
|
bits/ansi/seek.h \
|
|
|
|
bits/ansi/timespec.h \
|
|
|
|
bits/ansi/time_t.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
setjmp.h \
|
|
|
|
signal.h \
|
|
|
|
stdio.h \
|
|
|
|
stdlib.h \
|
|
|
|
string.h \
|
|
|
|
time.h \
|
|
|
|
wchar.h
|
|
|
|
#Internal
|
2018-03-30 16:11:44 +02:00
|
|
|
libc_includes += \
|
|
|
|
bits/ensure.h \
|
|
|
|
bits/feature.h \
|
2018-01-24 20:10:18 +01:00
|
|
|
bits/machine.h \
|
|
|
|
bits/null.h \
|
|
|
|
bits/size_t.h \
|
2018-01-27 18:11:00 +01:00
|
|
|
bits/types.h \
|
2018-01-24 20:10:18 +01:00
|
|
|
bits/wchar_t.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
stdint.h
|
|
|
|
#Linux
|
2018-04-07 01:26:31 +02:00
|
|
|
libc_includes += \
|
|
|
|
asm/ioctls.h \
|
|
|
|
getopt.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
linux/bpf_common.h \
|
2018-03-01 19:00:52 +01:00
|
|
|
linux/bsg.h \
|
|
|
|
linux/cdrom.h \
|
|
|
|
linux/hdreg.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
linux/filter.h \
|
2018-03-01 19:00:52 +01:00
|
|
|
linux/fs.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
linux/input.h \
|
2018-02-10 19:44:25 +01:00
|
|
|
linux/kd.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
linux/magic.h \
|
2018-02-10 19:44:25 +01:00
|
|
|
linux/major.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
linux/netlink.h \
|
2018-03-01 19:00:52 +01:00
|
|
|
linux/pci_regs.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
linux/sched.h \
|
|
|
|
linux/sockios.h \
|
|
|
|
linux/types.h \
|
2018-03-01 19:00:52 +01:00
|
|
|
linux/videodev2.h \
|
2018-02-10 19:44:25 +01:00
|
|
|
linux/vt.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
malloc.h \
|
2018-02-10 22:05:53 +01:00
|
|
|
memory.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
mntent.h \
|
2018-03-01 19:00:52 +01:00
|
|
|
net/if_arp.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
poll.h \
|
2018-02-10 22:05:53 +01:00
|
|
|
pty.h \
|
2018-03-01 19:00:52 +01:00
|
|
|
scsi/sg.h \
|
|
|
|
scsi/scsi.h \
|
|
|
|
scsi/scsi_ioctl.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
stdio_ext.h \
|
|
|
|
sys/epoll.h \
|
|
|
|
sys/inotify.h \
|
|
|
|
sys/ioctl.h \
|
|
|
|
sys/mount.h \
|
2018-02-09 13:44:33 +01:00
|
|
|
sys/prctl.h \
|
|
|
|
sys/ptrace.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
sys/random.h \
|
|
|
|
sys/sendfile.h \
|
2018-02-09 12:38:25 +01:00
|
|
|
sys/signalfd.h \
|
|
|
|
sys/sysmacros.h \
|
2018-02-10 19:44:25 +01:00
|
|
|
sys/timerfd.h \
|
|
|
|
values.h
|
2018-01-24 19:38:04 +01:00
|
|
|
#LSB
|
|
|
|
libc_includes += sys/auxv.h
|
|
|
|
#Posix
|
|
|
|
libc_includes += arpa/inet.h \
|
|
|
|
byteswap.h \
|
|
|
|
dirent.h \
|
|
|
|
dlfcn.h \
|
|
|
|
endian.h \
|
|
|
|
fcntl.h \
|
|
|
|
fnmatch.h \
|
|
|
|
ftw.h \
|
|
|
|
glob.h \
|
|
|
|
grp.h \
|
|
|
|
langinfo.h \
|
|
|
|
libgen.h \
|
2018-01-24 20:10:18 +01:00
|
|
|
bits/posix/blkcnt_t.h \
|
|
|
|
bits/posix/blksize_t.h \
|
|
|
|
bits/posix/dev_t.h \
|
|
|
|
bits/posix/file.h \
|
|
|
|
bits/posix/fsblkcnt_t.h \
|
|
|
|
bits/posix/fsfilcnt_t.h \
|
|
|
|
bits/posix/gid_t.h \
|
|
|
|
bits/posix/id_t.h \
|
|
|
|
bits/posix/in_addr_t.h \
|
|
|
|
bits/posix/ino_t.h \
|
|
|
|
bits/posix/in_port_t.h \
|
|
|
|
bits/posix/iovec.h \
|
|
|
|
bits/posix/locale_t.h \
|
|
|
|
bits/posix/mode_t.h \
|
|
|
|
bits/posix/nlink_t.h \
|
|
|
|
bits/posix/nl_item.h \
|
|
|
|
bits/posix/off_t.h \
|
|
|
|
bits/posix/pid_t.h \
|
|
|
|
bits/posix/posix_errno.h \
|
|
|
|
bits/posix/posix_signal.h \
|
|
|
|
bits/posix/posix_stdio.h \
|
|
|
|
bits/posix/posix_stdlib.h \
|
|
|
|
bits/posix/posix_string.h \
|
|
|
|
bits/posix/sa_family_t.h \
|
2018-02-09 14:32:35 +01:00
|
|
|
bits/posix/siginfo_t.h \
|
2018-01-24 20:10:18 +01:00
|
|
|
bits/posix/socklen_t.h \
|
|
|
|
bits/posix/ssize_t.h \
|
|
|
|
bits/posix/stat.h \
|
|
|
|
bits/posix/suseconds_t.h \
|
|
|
|
bits/posix/timeval.h \
|
|
|
|
bits/posix/uid_t.h \
|
2018-01-24 19:38:04 +01:00
|
|
|
net/if.h \
|
|
|
|
netdb.h \
|
|
|
|
netinet/in.h \
|
|
|
|
netinet/ip.h \
|
|
|
|
pthread.h \
|
|
|
|
pwd.h \
|
|
|
|
sched.h \
|
|
|
|
spawn.h \
|
|
|
|
strings.h \
|
|
|
|
sys/file.h \
|
|
|
|
sys/mman.h \
|
|
|
|
sys/param.h \
|
|
|
|
sys/resource.h \
|
|
|
|
sys/select.h \
|
|
|
|
sys/socket.h \
|
|
|
|
sys/statfs.h \
|
|
|
|
sys/stat.h \
|
|
|
|
sys/statvfs.h \
|
|
|
|
sys/time.h \
|
|
|
|
sys/types.h \
|
|
|
|
sys/uio.h \
|
|
|
|
sys/un.h \
|
|
|
|
sys/utsname.h \
|
|
|
|
sys/vfs.h \
|
|
|
|
sys/wait.h \
|
|
|
|
syslog.h \
|
|
|
|
termios.h \
|
|
|
|
unistd.h
|
2018-02-04 12:41:14 +01:00
|
|
|
# sysdeps/managarm
|
|
|
|
libc_includes += bits/abi.h
|
2018-01-24 19:38:04 +01:00
|
|
|
|
2018-01-24 19:52:23 +01:00
|
|
|
$(foreach d,$(libc_include_dirs),\
|
2018-01-24 20:11:15 +01:00
|
|
|
$(eval $(SYSROOT_PATH)/usr/include/%.h: $d/%.h ; $(value install_header_pretty)))
|
2018-01-24 18:10:23 +01:00
|
|
|
|
|
|
|
$(SYSROOT_PATH)/usr/lib/libc.so: libc.so
|
2018-01-24 20:11:15 +01:00
|
|
|
$(install_slib_pretty)
|
2018-01-24 18:10:23 +01:00
|
|
|
|
2018-03-30 16:11:44 +02:00
|
|
|
$(SYSROOT_PATH)/usr/lib/crt0.o: sysdeps/managarm/crt-src/crt0.o
|
|
|
|
$(install_crt_pretty)
|
|
|
|
|
2018-02-27 22:37:23 +01:00
|
|
|
libc_code_dirs := options/ansi/generic \
|
|
|
|
options/ansi/musl-generic-math
|
2018-01-24 18:10:23 +01:00
|
|
|
libc_code_dirs += options/linux/generic
|
|
|
|
libc_code_dirs += options/lsb/generic
|
2018-02-04 12:41:14 +01:00
|
|
|
libc_code_dirs += options/posix/generic \
|
|
|
|
options/posix/musl-generic
|
2018-01-28 16:56:15 +01:00
|
|
|
libc_code_dirs += options/internal/generic \
|
|
|
|
options/internal/gcc \
|
2018-01-24 18:10:23 +01:00
|
|
|
options/internal/gcc-extra \
|
|
|
|
options/internal/x86_64
|
2018-01-28 16:56:15 +01:00
|
|
|
|
2018-05-11 17:22:46 +02:00
|
|
|
libc_code_dirs += sysdeps/managarm/crt-src \
|
|
|
|
sysdeps/managarm/generic \
|
|
|
|
sysdeps/managarm/x86_64
|
2018-01-24 18:10:23 +01:00
|
|
|
|
|
|
|
libc_s_sources := $(wildcard $(TREE_PATH)/options/internal/x86_64/*.S)
|
2018-05-11 17:22:46 +02:00
|
|
|
libc_s_sources += $(wildcard $(TREE_PATH)/sysdeps/managarm/x86_64/*.S)
|
2018-01-21 17:40:27 +01:00
|
|
|
|
2018-02-27 22:37:23 +01:00
|
|
|
libc_c_sources := $(wildcard $(TREE_PATH)/options/ansi/musl-generic-math/*.c)
|
|
|
|
|
2018-01-21 19:51:23 +01:00
|
|
|
libc_cxx_sources := $(wildcard $(TREE_PATH)/options/ansi/generic/*.cpp)
|
|
|
|
libc_cxx_sources += $(wildcard $(TREE_PATH)/options/linux/generic/*.cpp)
|
|
|
|
libc_cxx_sources += $(wildcard $(TREE_PATH)/options/lsb/generic/*.cpp)
|
|
|
|
libc_cxx_sources += $(wildcard $(TREE_PATH)/options/posix/generic/*.cpp)
|
2018-02-04 12:41:14 +01:00
|
|
|
libc_cxx_sources += $(wildcard $(TREE_PATH)/options/posix/musl-generic/*.cpp)
|
2018-01-28 16:56:15 +01:00
|
|
|
libc_cxx_sources += $(wildcard $(TREE_PATH)/options/internal/generic/*.cpp)
|
2018-01-21 19:51:23 +01:00
|
|
|
libc_cxx_sources += $(wildcard $(TREE_PATH)/options/internal/gcc/*.cpp)
|
|
|
|
libc_cxx_sources += $(wildcard $(TREE_PATH)/sysdeps/managarm/generic/*.cpp)
|
2018-01-21 17:40:27 +01:00
|
|
|
|
2018-01-24 20:35:22 +01:00
|
|
|
libc_objects := $(patsubst $(TREE_PATH)/%.S,%.o,$(libc_s_sources))
|
2018-02-27 22:37:23 +01:00
|
|
|
libc_objects += $(patsubst $(TREE_PATH)/%.c,%.o,$(libc_c_sources))
|
2018-01-24 18:10:23 +01:00
|
|
|
libc_objects += $(patsubst $(TREE_PATH)/%.cpp,%.o,$(libc_cxx_sources))
|
2018-01-21 17:40:27 +01:00
|
|
|
|
|
|
|
libc_AS := x86_64-managarm-as
|
|
|
|
libc_ASFLAGS :=
|
|
|
|
|
2018-01-24 18:10:23 +01:00
|
|
|
vpath %.h $(TREE_PATH)
|
2018-01-21 17:40:27 +01:00
|
|
|
vpath %.S $(TREE_PATH)
|
2018-02-27 22:37:23 +01:00
|
|
|
vpath %.c $(TREE_PATH)
|
2018-01-21 17:40:27 +01:00
|
|
|
vpath %.cpp $(TREE_PATH)
|
|
|
|
|
2018-01-24 18:10:23 +01:00
|
|
|
$(libc_code_dirs):
|
2018-01-24 21:17:53 +01:00
|
|
|
$(call quiet,mkdir -p $@,mkdir,$@)
|
2018-01-21 17:40:27 +01:00
|
|
|
|
|
|
|
$(libc_gendir):
|
2018-01-24 21:17:53 +01:00
|
|
|
$(call quiet,mkdir -p $@,mkdir,$@)
|
2018-01-21 17:40:27 +01:00
|
|
|
|
2018-01-24 18:10:23 +01:00
|
|
|
%.o: %.S | $(libc_code_dirs)
|
2018-01-24 21:17:53 +01:00
|
|
|
$(compile_s_pretty)
|
2018-01-21 17:40:27 +01:00
|
|
|
|
2018-02-27 22:37:23 +01:00
|
|
|
# TODO: Speed up compilation by calling GCC only once.
|
|
|
|
%.o: %.c | $(libc_code_dirs)
|
|
|
|
$(compile_c_pretty)
|
|
|
|
@$(libc_CC) $(libc_CPPFLAGS) -std=c11 -MM -MP -MF $(@:%.o=%.d) -MT "$@" -MT "$(@:%.o=%.d)" $<
|
|
|
|
|
2018-01-24 20:35:22 +01:00
|
|
|
# TODO: Speed up compilation by calling GCC only once.
|
2018-01-24 18:10:23 +01:00
|
|
|
%.o: %.cpp | $(libc_code_dirs)
|
2018-01-24 20:35:22 +01:00
|
|
|
$(compile_cxx_pretty)
|
2018-02-27 22:37:23 +01:00
|
|
|
@$(libc_CXX) $(libc_CPPFLAGS) -std=c++17 -MM -MP -MF $(@:%.o=%.d) -MT "$@" -MT "$(@:%.o=%.d)" $<
|
2018-01-21 17:40:27 +01:00
|
|
|
|
|
|
|
libc.so: $(libc_objects) $(libc_BEGIN) $(libc_END)
|
2018-01-24 20:35:22 +01:00
|
|
|
$(link_cxx_pretty)
|
2018-01-21 17:40:27 +01:00
|
|
|
|
|
|
|
gen-libc: $(libc_gendir)/posix.frigg_pb.hpp $(libc_gendir)/fs.frigg_pb.hpp
|
|
|
|
|
2018-01-24 18:10:23 +01:00
|
|
|
install-headers-libc: $(addprefix $(SYSROOT_PATH)/usr/include/,$(libc_includes))
|
|
|
|
|
|
|
|
install-libc: $(addprefix $(SYSROOT_PATH)/usr/include/,$(libc_includes))
|
2018-03-30 16:11:44 +02:00
|
|
|
install-libc: $(SYSROOT_PATH)/usr/lib/crt0.o
|
2018-01-24 18:10:23 +01:00
|
|
|
install-libc: $(SYSROOT_PATH)/usr/lib/libc.so
|
2018-01-21 17:40:27 +01:00
|
|
|
|
|
|
|
$(libc_gendir)/%.frigg_pb.hpp: $(MANAGARM_SRC_PATH)/bragi/proto/%.proto | $(libc_gendir)
|
2018-01-24 21:17:53 +01:00
|
|
|
$(proto_pretty)
|
2018-01-24 18:10:23 +01:00
|
|
|
|
2018-01-24 20:35:37 +01:00
|
|
|
-include $(libc_objects:%.o=%.d)
|
|
|
|
|