Index: uspace/lib/c/arch/amd64/Makefile.common
===================================================================
--- uspace/lib/c/arch/amd64/Makefile.common	(revision 5b0cf635022b821f28f7a014ad5b39d005cd7666)
+++ uspace/lib/c/arch/amd64/Makefile.common	(revision e9dba436d9889d3165e64f44a57e7177939eacd8)
@@ -31,5 +31,8 @@
 # XXX: clang doesn't support this flag, but the optimization is OS-specific,
 #      so it isn't used for amd64-unknown-elf target.
-GCC_CFLAGS += -mno-tls-direct-seg-refs
+
+ifneq ($(COMPILER),clang)
+	COMMON_CFLAGS += -mno-tls-direct-seg-refs
+endif
 
 LFLAGS += --gc-sections
Index: uspace/lib/posix/Makefile
===================================================================
--- uspace/lib/posix/Makefile	(revision 5b0cf635022b821f28f7a014ad5b39d005cd7666)
+++ uspace/lib/posix/Makefile	(revision e9dba436d9889d3165e64f44a57e7177939eacd8)
@@ -45,4 +45,18 @@
 	$(LIBSOFTINT_PREFIX)/libsoftint.a
 
+SPECS = gcc.specs
+LIBC_LINKER_SCRIPT = $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
+LIBC_STARTUP_FILE = $(shell sed -n -e 's/^.*STARTUP(\(.*\)).*$$/\1/p' $(LIBC_LINKER_SCRIPT))
+EXPORT_LINKER_SCRIPT = link.ld
+EXPORT_STARTUP_FILE = crt0.o
+
+EXPORT_FILES = \
+	../math/libmath.a \
+	../clui/libclui.a \
+	$(MERGED_C_LIBRARY) \
+	$(EXPORT_STARTUP_FILE) \
+	$(EXPORT_LINKER_SCRIPT) \
+	$(SPECS)
+
 REDEFS_HIDE_LIBC = redefs-hide-libc-symbols.list
 
@@ -53,5 +67,5 @@
 	libc.o
 
-EXTRA_OUTPUT = $(FIXED_C_LIBRARY) $(FIXED_POSIX_LIBRARY) $(MERGED_C_LIBRARY)
+EXTRA_OUTPUT = $(FIXED_C_LIBRARY) $(FIXED_POSIX_LIBRARY) $(MERGED_C_LIBRARY) $(SPECS) $(EXPORT_LINKER_SCRIPT) $(EXPORT_STARTUP_FILE)
 
 SOURCES = \
@@ -83,8 +97,76 @@
 	test/scanf.c
 
+EXPORT_CPPFLAGS = \
+	-specs $(EXPORT_DIR)/lib/gcc.specs \
+	-isystem $(EXPORT_DIR)/include
+
+EXPORT_LDFLAGS = \
+	-L$(EXPORT_DIR)/lib \
+	--whole-archive -lc -lmath --no-whole-archive \
+	-T link.ld
+
+EXPORT_CFLAGS = \
+	$(EXPORT_CPPFLAGS) \
+	$(addprefix -Xlinker , $(EXPORT_LDFLAGS))
+
 include $(USPACE_PREFIX)/Makefile.common
 
-$(INCLUDE_LIBC): ../c/include
-	ln -s -f -n ../$^ $@
+$(SPECS): $(CONFIG_MAKEFILE)
+	echo '*self_spec:' > $@.new
+	echo '+ $(COMMON_CFLAGS)' >> $@.new
+	echo >> $@.new
+	echo '*lib:' >> $@.new
+	echo '--whole-archive -lc -lmath --no-whole-archive' >> $@.new
+	echo >> $@.new
+	mv $@.new $@
+
+$(EXPORT_LINKER_SCRIPT): $(LIBC_LINKER_SCRIPT)
+	sed 's/STARTUP(.*)/STARTUP(crt0.o)/' $< > $@
+
+$(EXPORT_STARTUP_FILE): $(LIBC_STARTUP_FILE)
+	cp $< $@
+
+$(INCLUDE_LIBC): $(shell find ../c/include -name '*.h')
+	cp -r -L --remove-destination -T ../c/include $@
+	find ../c/include -type f -and -not -name '*.h' -delete
+
+export: $(EXPORT_DIR)/config
+
+$(EXPORT_DIR)/config: export-libs export-includes
+	echo '# Generated file, do not modify.' >> $@.new
+	echo 'HELENOS_CROSS_PATH="$(shell dirname $(CC))"' >> $@.new
+	echo 'HELENOS_TARGET="$(TARGET)"' >> $@.new
+	echo 'HELENOS_CPPFLAGS="$(EXPORT_CPPFLAGS)"' >> $@.new
+	echo 'HELENOS_CFLAGS="$(EXPORT_CFLAGS)"' >> $@.new
+	echo 'HELENOS_LDFLAGS="$(EXPORT_LDFLAGS)"' >> $@.new
+	mv $@.new $@
+
+export-libs: $(EXPORT_FILES) export-includes
+	mkdir -p $(EXPORT_DIR)/lib
+	cp -L $(EXPORT_FILES) $(EXPORT_DIR)/lib
+
+export-includes: $(INCLUDE_LIBC) $(shell find ./include ../c/arch/$(UARCH)/include $(ROOT_PATH)/abi/include -name '*.h')
+	mkdir -p $(EXPORT_DIR)/include
+	rm -rf $(EXPORT_DIR)/include.new
+	cp -r -L -T ./include/posix $(EXPORT_DIR)/include.new
+	cp -r -L -T ./include/libc $(EXPORT_DIR)/include.new/libc
+	cp -r -L ../c/arch/$(UARCH)/include/* $(EXPORT_DIR)/include.new/libc
+	cp -r -L $(ROOT_PATH)/abi/include/* $(EXPORT_DIR)/include.new
+	mkdir -p $(EXPORT_DIR)/include.new/libclui
+	cp -L ../clui/tinput.h $(EXPORT_DIR)/include.new/libclui
+	
+	find "$(EXPORT_DIR)/include.new/libc" "$(EXPORT_DIR)/include.new/libclui" -name '*.h' -exec sed \
+		-e 's:#include <:#include <libc/:' \
+		-e 's:#include <libc/abi/:#include <abi/:' \
+		-e 's:#include <libc/_bits/:#include <_bits/:' \
+		-e 's:#include <libc/libc/:#include <libc/:' \
+		-i {} \;
+	find "$(EXPORT_DIR)/include.new" -name '*.h' -exec sed \
+		-e 's:#include "posix/:#include ":' \
+		-e 's:#include <posix/:#include <:' \
+		-i {} \;
+	
+	rm -rf $(EXPORT_DIR)/include
+	mv $(EXPORT_DIR)/include.new $(EXPORT_DIR)/include
 
 $(FIXED_C_LIBRARY): $(LIBC_FILE) $(REDEFS_HIDE_LIBC)
@@ -97,3 +179,2 @@
 $(REDEFS_HIDE_LIBC): $(SOURCES)
 	sed -n -e 's/_HIDE_LIBC_SYMBOL(\(.*\))/\1 __helenos_libc_\1/p' $(SOURCES) >$@
-
