Build a dynamic userspace.

- Builds (terrible, broken) shared versions of (most) third-party
  dependencies for the userspace.
- Fixes several incorrect dependency mappings in auto-dep.
- Makes auto-dep understand shared libraries (and that some things,
  like OSMesa, don't work with them).
- init must be built static because reasons
- some libraries were cleaned up to fix dependency calculation
- version bumped to 0.99.0 (saten) for eventual 1.0.0 release.
- CDs no longer drop teapot, select-wallpaper (space is available
  for them - we could even make the images smaller)
This commit is contained in:
Kevin Lange 2016-12-03 17:10:48 +09:00
parent f71a960469
commit 39da315a48
11 changed files with 117 additions and 64 deletions

View File

@ -41,19 +41,23 @@ MODULES = $(patsubst modules/%.c,hdd/mod/%.ko,$(wildcard modules/*.c))
HEADERS = $(shell find kernel/include/ -type f -name '*.h')
# Userspace build flags
USER_CFLAGS = -O3 -m32 -Wa,--32 -g -Iuserspace -std=c99 -U__STRICT_ANSI__
USER_CFLAGS = -O3 -m32 -Wa,--32 -g -Iuserspace -std=c99 -U__STRICT_ANSI__ -Lhdd/usr/lib
USER_CXXFLAGS = -O3 -m32 -Wa,--32 -g -Iuserspace
USER_BINFLAGS =
# Userspace binaries and libraries
USER_CFILES = $(shell find userspace -not -wholename '*/lib/*' -name '*.c')
USER_CFILES = $(filter-out userspace/core/init.c,$(shell find userspace -not -wholename '*/lib/*' -not -wholename '*.static.*' -name '*.c'))
USER_CXXFILES = $(shell find userspace -not -wholename '*/lib/*' -name '*.c++')
USER_LIBFILES = $(shell find userspace -wholename '*/lib/*' -name '*.c')
LIBC=hdd/usr/lib/libc.so
# Userspace output files (so we can define metatargets)
USERSPACE = $(foreach file,$(USER_CFILES),$(patsubst %.c,hdd/bin/%,$(notdir ${file})))
USERSPACE += $(foreach file,$(USER_CXXFILES),$(patsubst %.c++,hdd/bin/%,$(notdir ${file})))
USERSPACE += $(foreach file,$(USER_LIBFILES),$(patsubst %.c,%.o,${file}))
USERSPACE += $(foreach file,$(USER_CSTATICFILES),$(patsubst %.static.c,hdd/bin/%,$(notdir ${file})))
USERSPACE += $(LIBC) hdd/bin/init
#USERSPACE += $(foreach file,$(USER_LIBFILES),$(patsubst %.c,%.o,${file}))
CORE_LIBS = $(patsubst %.c,%.o,$(wildcard userspace/lib/*.c))
@ -214,26 +218,35 @@ kernel/%.o: kernel/%.c ${HEADERS}
# Userspace #
#############
# Init must be built static at the moment.
hdd/bin/init: userspace/core/init.c
@${BEG} "CC" "$< (static)"
@${CC} -o $@ -static -Wl,-static $(USER_CFLAGS) $(USER_BINFLAGS) $< ${ERRORS}
@${END} "CC" "$< (static)"
# Libraries
userspace/%.o: userspace/%.c
@${BEG} "CC" "$<"
@${CC} ${USER_CFLAGS} $(shell util/auto-dep.py --cflags $<) -c -o $@ $< ${ERRORS}
@${END} "CC" "$<"
define user-c-rule
$1: $2 $(shell util/auto-dep.py --deps $2) $(LIBC)
@${BEG} "CCSO" "$$<"
@${CC} -o $$@ $(USER_CFLAGS) -shared -fPIC $$(shell util/auto-dep.py --cflags $$<) $$< $$(shell util/auto-dep.py --libs $$<) -lc ${ERRORS}
@${END} "CCSO" "$$<"
endef
$(foreach file,$(USER_LIBFILES),$(eval $(call user-c-rule,$(patsubst %.c,hdd/usr/lib/libtoaru-%.so,$(notdir ${file})),${file})))
# Binaries from C sources
define user-c-rule
$1: $2 $(shell util/auto-dep.py --deps $2)
$1: $2 $(shell util/auto-dep.py --deps $2) $(LIBC)
@${BEG} "CC" "$$<"
@${CC} -o $$@ $(USER_CFLAGS) $(USER_BINFLAGS) $$(shell util/auto-dep.py --cflags $$<) $$< $$(shell util/auto-dep.py --libs $$<) ${ERRORS}
@${CC} -o $$@ $(USER_CFLAGS) $(USER_BINFLAGS) -fPIE $$(shell util/auto-dep.py --cflags $$<) $$< $$(shell util/auto-dep.py --libs $$<) -lc ${ERRORS}
@${END} "CC" "$$<"
endef
$(foreach file,$(USER_CFILES),$(eval $(call user-c-rule,$(patsubst %.c,hdd/bin/%,$(notdir ${file})),${file})))
# Binaries from C++ sources
define user-cxx-rule
$1: $2 $(shell util/auto-dep.py --deps $2)
$1: $2 $(shell util/auto-dep.py --deps $2) $(LIBC)
@${BEG} "C++" "$$<"
@${CXX} -o $$@ $(USER_CXXFLAGS) $(USER_BINFLAGS) $$(shell util/auto-dep.py --cflags $$<) $$< $$(shell util/auto-dep.py --libs $$<) ${ERRORS}
@${CXX} -o $$@ $(USER_CXXFLAGS) $(USER_BINFLAGS) -static -Wl,-static $$(shell util/auto-dep.py --cflags $$<) $$< $$(shell util/auto-dep.py --libs $$<) -lc ${ERRORS}
@${END} "C++" "$$<"
endef
$(foreach file,$(USER_CXXFILES),$(eval $(call user-cxx-rule,$(patsubst %.c++,hdd/bin/%,$(notdir ${file})),${file})))
@ -250,6 +263,32 @@ hdd/usr/lib/libnetwork.a: userspace/lib/network.o
@${AR} rcs $@ ${CORE_LIBS}
@${END} "AR" "$@"
# Bad implementations of shared libraries
hdd/usr/lib/libc.so: ${TOOLCHAIN}/lib/libc.a
cd linker; make libc.so
cp linker/libc.so hdd/usr/lib/
hdd/lib/ld.so: ${TOOLCHAIN}/lib/linker.c
cd linker; make ld.so
mkdir -p hdd/lib
cp linker/ld.so hdd/lib/
define basic-so-wrapper
hdd/usr/lib/lib$(1).so: ${TOOLCHAIN}/lib/lib$(1).a
@${BEG} "SO" "$$@"
@${CC} -shared -Wl,-soname,lib$(1).so -o hdd/usr/lib/lib$(1).so -Lhdd/usr/lib -Wl,--whole-archive ${TOOLCHAIN}/lib/lib$(1).a -Wl,--no-whole-archive $2
@${END} "SO" "$$@"
endef
$(eval $(call basic-so-wrapper,m,))
$(eval $(call basic-so-wrapper,z,))
$(eval $(call basic-so-wrapper,ncurses,))
$(eval $(call basic-so-wrapper,panel,-lncurses))
$(eval $(call basic-so-wrapper,png15,-lz))
$(eval $(call basic-so-wrapper,pixman-1,-lm))
$(eval $(call basic-so-wrapper,cairo,-lpixman-1 -lpng15 -lfreetype))
$(eval $(call basic-so-wrapper,freetype,-lz))
####################
# Hard Disk Images #
####################

View File

@ -17,8 +17,8 @@ char * __kernel_version_format = "%d.%d.%d-%s";
/* Version numbers X.Y.Z */
int __kernel_version_major = 0;
int __kernel_version_minor = 14;
int __kernel_version_lower = 1;
int __kernel_version_minor = 99;
int __kernel_version_lower = 0;
/* Kernel build suffix, which doesn't necessarily
* mean anything, but can be used to distinguish
@ -34,7 +34,7 @@ int __kernel_version_lower = 1;
char * __kernel_version_suffix = KERNEL_VERSION_SUFFIX;
/* The release codename. */
char * __kernel_version_codename = "kuroko";
char * __kernel_version_codename = "saten";
/* Build architecture (should probably not be
* here as a string, but rather some sort of

View File

@ -11,7 +11,11 @@
#include <assert.h>
#include <math.h>
#include "gui/ttk/ttk.h"
#include <cairo.h>
#include "lib/decorations.h"
#include "../ttk.h"
/* TTK {{{ */

View File

@ -14,7 +14,8 @@
#include <stdio.h>
#include "confreader.h"
#include "hashmap.h"
#include "lib/hashmap.h"
static void free_hashmap(void * h) {
hashmap_free(h);

View File

@ -8,10 +8,11 @@
*/
#include <stdint.h>
#include "graphics.h"
#include "yutani.h"
#include "lib/graphics.h"
#include "lib/yutani.h"
#include "lib/shmemfonts.h"
#include "decorations.h"
#include "shmemfonts.h"
uint32_t decor_top_height = 33;
uint32_t decor_bottom_height = 6;

View File

@ -10,10 +10,10 @@
#include "graphics.h"
#include "yutani.h"
uint32_t decor_top_height;
uint32_t decor_bottom_height;
uint32_t decor_left_width;
uint32_t decor_right_width;
extern uint32_t decor_top_height;
extern uint32_t decor_bottom_height;
extern uint32_t decor_left_width;
extern uint32_t decor_right_width;
/*
* Render decorations to a window. A buffer pointer is
@ -22,22 +22,22 @@ uint32_t decor_right_width;
* Run me at least once for each window, and any time you may need to
* redraw them.
*/
void render_decorations(yutani_window_t * window, gfx_context_t * ctx, char * title);
void render_decorations_inactive(yutani_window_t * window, gfx_context_t * ctx, char * title);
extern void render_decorations(yutani_window_t * window, gfx_context_t * ctx, char * title);
extern void render_decorations_inactive(yutani_window_t * window, gfx_context_t * ctx, char * title);
/*
* Run me once to set things up
*/
void init_decorations();
extern void init_decorations();
uint32_t decor_width();
uint32_t decor_height();
extern uint32_t decor_width();
extern uint32_t decor_height();
int decor_handle_event(yutani_t * yctx, yutani_msg_t * m);
extern int decor_handle_event(yutani_t * yctx, yutani_msg_t * m);
/* Callbacks for handle_event */
void decor_set_close_callback(void (*callback)(yutani_window_t *));
void decor_set_resize_callback(void (*callback)(yutani_window_t *));
extern void decor_set_close_callback(void (*callback)(yutani_window_t *));
extern void decor_set_resize_callback(void (*callback)(yutani_window_t *));
/* Responses from handle_event */
#define DECOR_OTHER 1

View File

@ -6,7 +6,8 @@
#include <stdint.h>
#include <string.h>
#include "kbd.h"
#include "lib/kbd.h"
#include "rline.h"
void rline_redraw(rline_context_t * context) {

View File

@ -14,8 +14,9 @@
#include FT_FREETYPE_H
#include FT_CACHE_H
#include "yutani.h"
#include "graphics.h"
#include "lib/yutani.h"
#include "lib/graphics.h"
#include "shmemfonts.h"
#include "utf8decode.h"

View File

@ -7,12 +7,13 @@
#include <syscall.h>
#include "yutani.h"
#include "pex.h"
#include "graphics.h"
#include "kbd.h"
#include "mouse.h"
#include "hashmap.h"
#include "list.h"
#include "lib/pex.h"
#include "lib/graphics.h"
#include "lib/kbd.h"
#include "lib/hashmap.h"
#include "lib/list.h"
yutani_msg_t * yutani_wait_for(yutani_t * y, uint32_t type) {
do {

View File

@ -10,13 +10,15 @@ except KeyError:
# This is not good, but we need to let it happen for the make file
TOOLCHAIN_PATH = ""
force_static = ("OSMesa","GLU")
class Classifier(object):
dependency_hints = {
# Core libraries
'<math.h>': (None, '-lm', []),
'<cairo.h>': ('cairo', '-lcairo', ['<ft2build.h>', '<pixman.h>']),
'<ft2build.h>': ('freetype2', '-lfreetype', []),
'<cairo.h>': ('cairo', '-lcairo', ['<ft2build.h>', '<pixman.h>', '<png.h>']),
'<ft2build.h>': ('freetype2', '-lfreetype', ['<zlib.h>']),
'<pixman.h>': ('pixman-1', '-lpixman-1', ['<math.h>']),
'<GL/osmesa.h>': (None, '-lOSMesa', []),
'<GL/glu.h>': (None, '-lGLU', []),
@ -24,29 +26,29 @@ class Classifier(object):
'<panel.h>': (None, '-lpanel', ['<ncurses.h>']),
'<menu.h>': (None, '-lmenu', ['<ncurses.h>']),
'<zlib.h>': (None, '-lz', ['<math.h>']),
'<png.h>': (None, '-lpng', ['<zlib.h>']),
'<png.h>': (None, '-lpng15', ['<zlib.h>']),
# Toaru Standard Library
'"lib/toaru_auth.h"': (None, 'userspace/lib/toaru_auth.o', ['"lib/sha2.h"']),
'"lib/kbd.h"': (None, 'userspace/lib/kbd.o', []),
'"lib/list.h"': (None, 'userspace/lib/list.o', []),
'"lib/hashmap.h"': (None, 'userspace/lib/hashmap.o', ['"lib/list.h"']),
'"lib/tree.h"': (None, 'userspace/lib/tree.o', ['"lib/list.h"']),
'"lib/testing.h"': (None, 'userspace/lib/testing.o', []),
'"lib/pthread.h"': (None, 'userspace/lib/pthread.o', []),
'"lib/sha2.h"': (None, 'userspace/lib/sha2.o', []),
'"lib/pex.h"': (None, 'userspace/lib/pex.o', []),
'"lib/graphics.h"': (None, 'userspace/lib/graphics.o', ['<png.h>']),
'"lib/shmemfonts.h"': (None, 'userspace/lib/shmemfonts.o', ['"lib/graphics.h"', '<ft2build.h>']),
'"lib/rline.h"': (None, 'userspace/lib/rline.o', ['"lib/kbd.h"']),
'"lib/confreader.h"': (None, 'userspace/lib/confreader.o', ['"lib/hashmap.h"']),
'"lib/network.h"': (None, 'userspace/lib/network.o', []),
'"lib/http_parser.h"': (None, 'userspace/lib/http_parser.o', []),
'<toaru.h>': (None, '-ltoaru', ['<png.h>','<ft2build.h>','<cairo.h>']),
'"lib/toaru_auth.h"': (None, '-ltoaru-toaru_auth', ['"lib/sha2.h"']),
'"lib/kbd.h"': (None, '-ltoaru-kbd', []),
'"lib/list.h"': (None, '-ltoaru-list', []),
'"lib/hashmap.h"': (None, '-ltoaru-hashmap', ['"lib/list.h"']),
'"lib/tree.h"': (None, '-ltoaru-tree', ['"lib/list.h"']),
'"lib/testing.h"': (None, '-ltoaru-testing', []),
'"lib/pthread.h"': (None, '-ltoaru-pthread', []),
'"lib/sha2.h"': (None, '-ltoaru-sha2', []),
'"lib/pex.h"': (None, '-ltoaru-pex', []),
'"lib/graphics.h"': (None, '-ltoaru-graphics', ['<png.h>']),
'"lib/shmemfonts.h"': (None, '-ltoaru-shmemfonts', ['"lib/graphics.h"', '<ft2build.h>']),
'"lib/rline.h"': (None, '-ltoaru-rline', ['"lib/kbd.h"']),
'"lib/confreader.h"': (None, '-ltoaru-confreader', ['"lib/hashmap.h"']),
'"lib/network.h"': (None, '-ltoaru-network', []),
'"lib/http_parser.h"': (None, '-ltoaru-http_parser', []),
# Yutani Libraries
'"lib/yutani.h"': (None, 'userspace/lib/yutani.o', ['"lib/list.h"', '"lib/pex.h"', '"lib/graphics.h"', '"lib/hashmap.h"']),
'"lib/decorations.h"': (None, 'userspace/lib/decorations.o', ['"lib/shmemfonts.h"', '"lib/graphics.h"', '"lib/yutani.h"']),
'"gui/ttk/ttk.h"': (None, 'userspace/gui/ttk/lib/ttk-core.o', ['"lib/decorations.h"', '"lib/hashmap.h"', '<cairo.h>', '<math.h>']),
'"gui/terminal/lib/termemu.h"':
(None, 'userspace/gui/terminal/lib/termemu.o', []),
'"lib/yutani.h"': (None, '-ltoaru-yutani', ['"lib/kbd.h"', '"lib/list.h"', '"lib/pex.h"', '"lib/graphics.h"', '"lib/hashmap.h"']),
'"lib/decorations.h"': (None, '-ltoaru-decorations', ['"lib/shmemfonts.h"', '"lib/graphics.h"', '"lib/yutani.h"']),
'"gui/ttk/ttk.h"': (None, '-ltoaru-ttk', ['"lib/decorations.h"', '"lib/hashmap.h"', '<cairo.h>', '<math.h>']),
'"gui/terminal/lib/termemu.h"': (None, '-ltoaru-termemu', ['"lib/graphics.h"']),
}
def __init__(self, filename):
@ -103,7 +105,10 @@ def todep(name):
"""Convert a library name to an archive path or object file name."""
if name.startswith("-l"):
name = name.replace("-l","",1)
return "%s/lib%s.a" % (TOOLCHAIN_PATH + '/lib', name)
if name in force_static:
return "%s/lib%s.a" % (TOOLCHAIN_PATH + '/lib', name)
else:
return "%s/lib%s.so" % ('hdd/usr/lib', name)
else:
return name

View File

@ -20,7 +20,7 @@ if [[ $TOOLCHAIN/ = $PWD/* ]]; then
exit 1
fi
BLACKLIST="userspace/tests/* userspace/gui/gl/teapot.c userspace/gui/basic/select-wallpaper.c hdd/usr/share/wallpapers/{grandcanyon,paris,southbay,yokohama,yosemite}.png"
BLACKLIST="userspace/tests/* hdd/usr/share/wallpapers/{grandcanyon,paris,southbay,yokohama,yosemite}.png"
# Rebuild
echo "Rebuilding... (ignore warnings about time skew, this is intentional)"