Index: uspace/lib/posix/Makefile
===================================================================
--- uspace/lib/posix/Makefile	(revision 7f9df7b96a72566de47074ddcc443093aa8aa3e8)
+++ uspace/lib/posix/Makefile	(revision b500939e7aad56109d15f8461cd7a787061e9bc4)
@@ -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,80 @@
 	test/scanf.c
 
+EXPORT_CPPFLAGS = \
+	-specs $$(HELENOS_EXPORT_ROOT)/lib/gcc.specs \
+	-isystem $$(HELENOS_EXPORT_ROOT)/include
+
+EXPORT_LDFLAGS = \
+	-L$$(HELENOS_EXPORT_ROOT)/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.mk $(EXPORT_DIR)/config.rc
+
+$(EXPORT_DIR)/config.mk: export-libs export-includes
+	echo '# Generated file, do not modify.' >> $@.new
+	echo '# Do not forget to set HELENOS_EXPORT_ROOT.' >> $@.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_DIR)/config.rc: $(EXPORT_DIR)/config.mk
+	sed 's:$$(HELENOS_EXPORT_ROOT):$$HELENOS_EXPORT_ROOT:g' < $< >$@
+
+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 +183,2 @@
 $(REDEFS_HIDE_LIBC): $(SOURCES)
 	sed -n -e 's/_HIDE_LIBC_SYMBOL(\(.*\))/\1 __helenos_libc_\1/p' $(SOURCES) >$@
-
