Index: HelenOS.config
===================================================================
--- HelenOS.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ HelenOS.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -300,18 +300,5 @@
 @ "icc" Intel C Compiler
 @ "gcc_native" GNU C Compiler (native)
-! [PLATFORM=amd64|PLATFORM=ia32] COMPILER (choice)
-
-% Compiler
-@ "gcc_cross" GNU C Compiler (cross-compiler)
-@ "gcc_helenos" GNU C Compiler (experimental HelenOS-specific cross-compiler)
-@ "icc" Intel C Compiler
-@ "gcc_native" GNU C Compiler (native)
-! [PLATFORM=ia64] COMPILER (choice)
-
-% Compiler
-@ "gcc_cross" GNU C Compiler (cross-compiler)
-@ "gcc_helenos" GNU C Compiler (experimental HelenOS-specific cross-compiler)
-@ "gcc_native" GNU C Compiler (native)
-! [PLATFORM=riscv64] COMPILER (choice)
+! [PLATFORM=amd64|PLATFORM=ia32|PLATFORM=ia64] COMPILER (choice)
 
 % Compiler
@@ -320,6 +307,11 @@
 @ "gcc_helenos" GNU C Compiler (experimental HelenOS-specific cross-compiler)
 @ "gcc_native" GNU C Compiler (native)
-! [PLATFORM=mips32|PLATFORM=ppc32|PLATFORM=abs32le|PLATFORM=arm32|PLATFORM=sparc64] COMPILER (choice)
-
+! [PLATFORM=mips32|PLATFORM=ppc32|PLATFORM=abs32le|PLATFORM=arm32|PLATFORM=sparc64|PLATFORM=riscv64] COMPILER (choice)
+
+% Clang Integrated Assembler
+@ "default" Use architecture default.
+@ "yes" Use integrated assembler.
+@ "no" Use GNU Assembler.
+! [COMPILER=clang] INTEGRATED_AS (choice)
 
 ## Cross-compiler target for abstract architecture
@@ -621,6 +613,13 @@
 ! CONFIG_STRIP_BINARIES (n/y)
 
-% Optimize for size
-! CONFIG_OPTIMIZE_FOR_SIZE (n/y)
+% Optimization level
+@ "3" Level 3 (recommended).
+@ "2" Level 2.
+@ "1" Level 1.
+@ "0" Disable optimizations.
+@ "s" Optimize for size.
+@ "g" Enable only optimizations that don't harm debugging.
+@ "fast" Level 3 + aggressive optimizations that can affect adherence to standards.
+! OPTIMIZATION (choice)
 
 % Barebone build with essential binaries only 
Index: boot/Makefile
===================================================================
--- boot/Makefile	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ boot/Makefile	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -38,4 +38,8 @@
 
 build_dist: clean_dist
+	mkdir -p "$(DIST_PATH)/srv/"
+	mkdir -p "$(DIST_PATH)/lib/"
+	mkdir -p "$(DIST_PATH)/app/"
+	mkdir -p "$(DIST_PATH)/test/"
 	for file in $(RD_SRVS) ; do \
 		cp "$$file" "$(DIST_PATH)/srv/" ; \
@@ -45,5 +49,5 @@
 	done
 ifeq ($(CONFIG_DEVEL_FILES), y)
-	mkdir "$(DIST_PATH)/inc/c/"
+	mkdir -p "$(DIST_PATH)/inc/c/"
 	cp -r -L "$(USPACE_PATH)/lib/c/include/." "$(DIST_PATH)/inc/c/"
 	cp -r -L "$(ROOT_PATH)/abi/include/." "$(DIST_PATH)/inc/c/"
Index: boot/Makefile.build
===================================================================
--- boot/Makefile.build	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ boot/Makefile.build	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -36,47 +36,46 @@
 DEFS = -DBOOT -DRELEASE=$(RELEASE) "-DCOPYRIGHT=$(COPYRIGHT)" "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
 
+AFLAGS =
 LFLAGS = --fatal-warnings
 
-GCC_CFLAGS = $(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
-	-finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
-	-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
+# FIXME: This condition is a workaround for issue #693.
+ifneq ($(BARCH),mips32)
+	AFLAGS += --fatal-warnings
+endif
+
+COMMON_CFLAGS = $(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
+	-ffreestanding -fno-builtin -nostdlib -nostdinc \
+	-fexec-charset=UTF-8 -finput-charset=UTF-8
+
+GCC_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
 	-std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
 	-pipe
 
-ICC_CFLAGS = $(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
-	-Werror-implicit-function-declaration -wd170
+ICC_CFLAGS = -Wall -Wmissing-prototypes -Werror-implicit-function-declaration -wd170
 
-CLANG_CFLAGS = $(INCLUDES) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
-	-finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
-	-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
+CLANG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
 	-Werror-implicit-function-declaration -Wwrite-strings \
-	-pipe
+	-pipe  -fno-stack-protector -fno-PIC
 
 ifeq ($(CONFIG_DEBUG),y)
-	GCC_CFLAGS += -Werror
-	ICC_CFLAGS += -Werror
+	COMMON_CFLAGS += -Werror
 endif
 
 ifeq ($(CONFIG_LINE_DEBUG),y)
-	GCC_CFLAGS += -g
-	ICC_CFLAGS += -g
-	CLANG_CFLAGS += -g
+	COMMON_CFLAGS += -g
 endif
 
 ifeq ($(COMPILER),gcc_native)
-	CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS) $(EXTRA_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
 
 ifeq ($(COMPILER),gcc_cross)
-	CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS) $(EXTRA_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
 
 ifeq ($(COMPILER),gcc_helenos)
-	CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS) $(EXTRA_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
@@ -84,10 +83,10 @@
 
 ifeq ($(COMPILER),icc)
-	CFLAGS = $(ICC_CFLAGS) $(EXTRA_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(ICC_CFLAGS) $(EXTRA_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
 
 ifeq ($(COMPILER),clang)
-	CFLAGS = $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
@@ -105,4 +104,6 @@
 endif
 
+AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
+
 $(BOOT_OUTPUT): $(RAW)
 	$(OBJCOPY) -O $(BFD_OUTPUT) $< $@
@@ -112,8 +113,8 @@
 
 $(LINK): $(DEPEND)
-	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $(LINK).in | grep -v "^\#" > $(LINK)
+	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -D__LINKER__ -E -x c $(LINK).in | grep -v "^\#" > $(LINK)
 
 %.o: %.S $(DEPEND)
-	$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
+	$(CC) $(DEFS) $(CFLAGS) $(AS_CFLAGS) -D__ASM__ -c $< -o $@
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
@@ -127,5 +128,5 @@
 
 %.o: %.s $(DEPEND)
-	$(AS) $(AFLAGS) -o $@ $<
+	$(CC) $(DEFS) $(CFLAGS) $(AS_CFLAGS) -D__ASM__ -c $< -o $@
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ as asm
Index: defaults/amd64/Makefile.config
===================================================================
--- defaults/amd64/Makefile.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ defaults/amd64/Makefile.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -10,4 +10,7 @@
 # Compiler
 COMPILER = gcc_cross
+
+# In case compiler is clang, whether or not to use its integrated assembler.
+INTEGRATED_AS = default
 
 # Debug build
@@ -73,2 +76,5 @@
 # GRUB boot loader architecture
 GRUB_ARCH = pc
+
+# Optimization level
+OPTIMIZATION = 3
Index: defaults/arm32/Makefile.config
===================================================================
--- defaults/arm32/Makefile.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ defaults/arm32/Makefile.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -7,4 +7,7 @@
 # Compiler
 COMPILER = gcc_cross
+
+# In case compiler is clang, whether or not to use its integrated assembler.
+INTEGRATED_AS = default
 
 # Debug build
@@ -37,2 +40,5 @@
 # What is your output device?
 CONFIG_HID_OUT = generic
+
+# Optimization level
+OPTIMIZATION = 3
Index: defaults/ia32/Makefile.config
===================================================================
--- defaults/ia32/Makefile.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ defaults/ia32/Makefile.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -10,4 +10,7 @@
 # Compiler
 COMPILER = gcc_cross
+
+# In case compiler is clang, whether or not to use its integrated assembler.
+INTEGRATED_AS = default
 
 # Debug build
@@ -85,2 +88,5 @@
 # GRUB boot loader architecture
 GRUB_ARCH = pc
+
+# Optimization level
+OPTIMIZATION = 3
Index: defaults/ia64/Makefile.config
===================================================================
--- defaults/ia64/Makefile.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ defaults/ia64/Makefile.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -7,4 +7,7 @@
 # Compiler
 COMPILER = gcc_cross
+
+# In case compiler is clang, whether or not to use its integrated assembler.
+INTEGRATED_AS = default
 
 # Debug build
@@ -49,2 +52,5 @@
 # Output device class
 CONFIG_HID_OUT = generic
+
+# Optimization level
+OPTIMIZATION = 3
Index: defaults/mips32/Makefile.config
===================================================================
--- defaults/mips32/Makefile.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ defaults/mips32/Makefile.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -7,4 +7,7 @@
 # Compiler
 COMPILER = gcc_cross
+
+# In case compiler is clang, whether or not to use its integrated assembler.
+INTEGRATED_AS = default
 
 # Debug build
@@ -46,2 +49,5 @@
 # Barebone build with essential binaries only
 CONFIG_BAREBONE = y
+
+# Optimization level
+OPTIMIZATION = 3
Index: defaults/ppc32/Makefile.config
===================================================================
--- defaults/ppc32/Makefile.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ defaults/ppc32/Makefile.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -7,4 +7,7 @@
 # Compiler
 COMPILER = gcc_cross
+
+# In case compiler is clang, whether or not to use its integrated assembler.
+INTEGRATED_AS = default
 
 # Lazy FPU context switching
@@ -46,2 +49,5 @@
 # OHCI root hub power switch, ganged is enough
 OHCI_POWER_SWITCH = ganged
+
+# Optimization level
+OPTIMIZATION = 3
Index: defaults/sparc64/Makefile.config
===================================================================
--- defaults/sparc64/Makefile.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ defaults/sparc64/Makefile.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -7,4 +7,7 @@
 # Compiler
 COMPILER = gcc_cross
+
+# In case compiler is clang, whether or not to use its integrated assembler.
+INTEGRATED_AS = default
 
 # Support for SMP
@@ -55,2 +58,5 @@
 # Start AP processors by the loader
 CONFIG_AP = y
+
+# Optimization level
+OPTIMIZATION = 3
Index: defaults/special/Makefile.config
===================================================================
--- defaults/special/Makefile.config	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ defaults/special/Makefile.config	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -4,4 +4,7 @@
 # Compiler
 COMPILER = gcc_cross
+
+# In case compiler is clang, whether or not to use its integrated assembler.
+INTEGRATED_AS = default
 
 # Support for SMP
@@ -32,2 +35,4 @@
 RCU = PREEMPT_A
 
+# Optimization level
+OPTIMIZATION = 3
Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/Makefile	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -82,45 +82,32 @@
 INCLUDES_FLAGS = $(addprefix -I,$(INCLUDES))
 
-ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
-	OPTIMIZATION = s
-else
-	OPTIMIZATION = 3
-endif
-
 DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DCOPYRIGHT=$(COPYRIGHT)" "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
 
-GCC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
-	-finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
-	-std=gnu99 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
-	-Werror-implicit-function-declaration -Wwrite-strings \
-	-pipe
-
-ICC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
+COMMON_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
+	-ffreestanding -fno-builtin -nostdlib -nostdinc \
+	-fexec-charset=UTF-8 -finput-charset=UTF-8
+
+GCC_CFLAGS = -std=gnu99 -Wall -Wextra -Wno-unused-parameter \
+	-Wmissing-prototypes -Werror-implicit-function-declaration \
+	-Wwrite-strings -pipe
+
+ICC_CFLAGS = -Wall -Wmissing-prototypes \
 	-Werror-implicit-function-declaration -wd170
 
-# clang does not support following options but I am not sure whether
-# something won't break because of that:
-# -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) -finput-charset=UTF-8
-CLANG_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-ffreestanding -fno-builtin -nostdlib -nostdinc \
-	-std=gnu99 -Wall -Werror -Wextra -Wno-unused-parameter -Wmissing-prototypes \
-	-Werror-implicit-function-declaration -Wwrite-strings \
-	-integrated-as -pipe -target $(CLANG_TARGET)
+CLANG_CFLAGS = -std=gnu99 -Wall -Wextra -Wno-unused-parameter \
+	-Wno-missing-field-initializers -Wno-unused-command-line-argument \
+	-Wmissing-prototypes -Werror-implicit-function-declaration \
+	-Wwrite-strings -pipe -fno-stack-protector -fno-PIC
 
 ifeq ($(CONFIG_DEBUG),y)
-	GCC_CFLAGS += -Werror
-	ICC_CFLAGS += -Werror
+	COMMON_CFLAGS += -Werror
 endif
 
 ifeq ($(CONFIG_LTO),y)
-	GCC_CFLAGS += -flto
+	COMMON_CFLAGS += -flto
 endif
 
 ifeq ($(CONFIG_LINE_DEBUG),y)
-	GCC_CFLAGS += -g
-	ICC_CFLAGS += -g
-	CLANG_CFLAGS += -g
+	COMMON_CFLAGS += -g
 endif
 
@@ -129,6 +116,13 @@
 # AFLAGS and LFLAGS must be initialized before the inclusion.
 #
-AFLAGS = --fatal-warnings
+AFLAGS =
 LFLAGS = -n -T $(LINK) -M --fatal-warnings
+
+# FIXME: This condition is a workaround for issues #693 and #694.
+ifneq ($(KARCH),sparc64)
+ifneq ($(KARCH),mips32)
+	AFLAGS += --fatal-warnings
+endif
+endif
 
 #
@@ -162,5 +156,5 @@
 
 ifeq ($(COMPILER),gcc_native)
-	CFLAGS = $(GCC_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 	INSTRUMENTATION = -finstrument-functions
@@ -168,5 +162,5 @@
 
 ifeq ($(COMPILER),gcc_cross)
-	CFLAGS = $(GCC_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 	INSTRUMENTATION = -finstrument-functions
@@ -174,5 +168,5 @@
 
 ifeq ($(COMPILER),gcc_helenos)
-	CFLAGS = $(GCC_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 	INSTRUMENTATION = -finstrument-functions
@@ -180,5 +174,5 @@
 
 ifeq ($(COMPILER),icc)
-	CFLAGS = $(ICC_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(ICC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 	INSTRUMENTATION =
@@ -186,7 +180,7 @@
 
 ifeq ($(COMPILER),clang)
-	CFLAGS = $(CLANG_CFLAGS)
+	CFLAGS = $(COMMON_CFLAGS) $(CLANG_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
-	INSTRUMENTATION =
+	INSTRUMENTATION = -finstrument-functions
 endif
 
@@ -390,5 +384,10 @@
 AUTOGENS_AG := $(ARCH_AUTOGENS_AG) $(GENARCH_AUTOGENS_AG)
 
-LFLAGS_LTO := $(addprefix -Xlinker ,$(LFLAGS))
+AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
+LD_CFLAGS := $(addprefix -Xlinker ,$(LFLAGS))
+
+ifeq ($(COMPILER),clang)
+	AS_CFLAGS += -mllvm -asm-macro-max-nesting-depth=1000
+endif
 
 ifeq ($(CONFIG_SYMTAB),y)
@@ -410,5 +409,5 @@
 $(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
 ifeq ($(CONFIG_LTO),y)
-	$(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
+	$(CC) $(DEFS) $(CFLAGS) $(LD_CFLAGS) -Xlinker -Map -Xlinker $(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
 else
 	$(LD) $(LFLAGS) -Map $(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
@@ -423,15 +422,15 @@
 %.h: %.ag
 	$(AUTOGEN) probe $< >$<.probe.c
-	$(CC) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
+	$(CC_AUTOGEN) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
 	$(AUTOGEN) generate $< <$<.probe.s >$@   
 
 %.o: %.S $(DEPEND)
-	$(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c -o $@ $<
+	$(CC) $(DEFS) $(CFLAGS) $(AS_CFLAGS) -D__ASM__ -c -o $@ $<
 ifeq ($(PRECHECK),y)
-	$(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(GCC_CFLAGS) -D__ASM__
+	$(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
 endif
 
 %.o: %.s $(DEPEND)
-	$(AS) $(AFLAGS) -o $@ $<
+	$(CC) $(DEFS) $(CFLAGS) $(AS_CFLAGS) -D__ASM__ -c -o $@ $<
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ as asm $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
@@ -445,10 +444,10 @@
 
 $(REAL_MAP).o: $(REAL_MAP).bin
-	echo "$(AS_PROLOG)""$(SYMTAB_SECTION)"" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@
+	echo "$(AS_PROLOG)""$(SYMTAB_SECTION)"" .incbin \"$<\"" | $(CC) $(CFLAGS) $(AS_CFLAGS) -x assembler -c -o $@ -
 
 $(REAL_MAP).bin: $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
-	echo "$(AS_PROLOG)""$(SYMTAB_SECTION)" | $(AS) $(AFLAGS) -o $(EMPTY_MAP)
+	echo "$(AS_PROLOG)""$(SYMTAB_SECTION)" | $(CC) $(CFLAGS) $(AS_CFLAGS) -x assembler -c -o $(EMPTY_MAP) -
 ifeq ($(CONFIG_LTO),y)
-	$(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
+	$(CC) $(DEFS) $(CFLAGS) $(LD_CFLAGS) -Xlinker -Map -Xlinker $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
 else
 	$(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
@@ -460,7 +459,7 @@
 	# on architectures that have bss after symtab
 	
-	echo "$(AS_PROLOG)""$(SYMTAB_SECTION)"" .incbin \"$@\"" | $(AS) $(AFLAGS) -o $(SIZEOK_MAP)
+	echo "$(AS_PROLOG)""$(SYMTAB_SECTION)"" .incbin \"$@\"" | $(CC) $(CFLAGS) $(AS_CFLAGS) -x assembler -c -o $(SIZEOK_MAP) -
 ifeq ($(CONFIG_LTO),y)
-	$(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
+	$(CC) $(DEFS) $(CFLAGS) $(LD_CFLAGS) -Xlinker -Map -Xlinker $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
 else
 	$(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
Index: kernel/arch/abs32le/Makefile.inc
===================================================================
--- kernel/arch/abs32le/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/abs32le/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -35,5 +35,5 @@
 	
 	ifeq ($(CROSS_TARGET),mips32)
-		GCC_CFLAGS += -mno-abicalls
+		COMMON_CFLAGS += -mno-abicalls
 	endif
 endif
Index: kernel/arch/amd64/Makefile.inc
===================================================================
--- kernel/arch/amd64/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/amd64/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -32,8 +32,5 @@
 
 FPU_NO_CFLAGS = -mno-sse -mno-sse2
-CMN1 = -m64 -mcmodel=$(MEMORY_MODEL) -mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer
-GCC_CFLAGS += $(CMN1)
-ICC_CFLAGS += $(CMN1)
-CLANG_CFLAGS += $(CMN1)
+COMMON_CFLAGS += -m64 -mcmodel=$(MEMORY_MODEL) -mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer
 
 BITS = 64
@@ -44,7 +41,5 @@
 
 ifeq ($(PROCESSOR),opteron)
-	CMN2 := -march=opteron
-	GCC_CFLAGS += $(CMN2)
-	ICC_CFLAGS += $(CMN2)
+	COMMON_CFLAGS += -march=opteron
 endif
 
Index: kernel/arch/arm32/Makefile.inc
===================================================================
--- kernel/arch/arm32/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/arm32/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -33,5 +33,5 @@
 ATSIGN = %
 
-GCC_CFLAGS += -fno-omit-frame-pointer -mapcs-frame -march=$(subst _,-,$(PROCESSOR_ARCH)) -mno-unaligned-access -mfpu=vfpv3
+COMMON_CFLAGS += -fno-omit-frame-pointer -mapcs-frame -march=$(subst _,-,$(PROCESSOR_ARCH)) -mno-unaligned-access -mfpu=vfpv3
 
 ifeq ($(CONFIG_FPU),y)
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/ia32/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -34,8 +34,5 @@
 ENDIANESS = LE
 
-CMN1 = -m32 -fno-omit-frame-pointer
-GCC_CFLAGS += $(CMN1)
-ICC_CFLAGS += $(CMN1)
-CLANG_CFLAGS += $(CMN1)
+COMMON_CFLAGS += -m32 -fno-omit-frame-pointer
 
 ## Accepted CPUs
@@ -43,31 +40,28 @@
 
 ifeq ($(PROCESSOR),i486)
-	CMN2 = -march=i486
+	COMMON_CFLAGS += -march=i486
 endif
 
 ifeq ($(PROCESSOR),athlon_xp)
-	CMN2 = -march=athlon-xp
+	COMMON_CFLAGS += -march=athlon-xp
 endif
 
 ifeq ($(PROCESSOR),athlon_mp)
-	CMN2 = -march=athlon-mp
+	COMMON_CFLAGS += -march=athlon-mp
 endif
 
 ifeq ($(PROCESSOR),pentium3)
-	CMN2 = -march=pentium3
+	COMMON_CFLAGS += -march=pentium3
 endif
 
 ifeq ($(PROCESSOR),pentium4)
-	CMN2 = -march=pentium4
+	COMMON_CFLAGS += -march=pentium4
 endif
 
 ifeq ($(PROCESSOR),core)
-	CMN2 = -march=prescott
+	COMMON_CFLAGS += -march=prescott
 endif
 
 FPU_NO_CFLAGS = -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow
-GCC_CFLAGS += $(CMN2)
-ICC_CFLAGS += $(CMN2)
-CLANG_CFLAGS += $(CMN2)
 
 ARCH_SOURCES = \
Index: kernel/arch/ia64/Makefile.inc
===================================================================
--- kernel/arch/ia64/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/ia64/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -30,7 +30,5 @@
 BFD_ARCH = ia64-elf64
 
-CMN1 = -mconstant-gp -fno-unwind-tables -mfixed-range=f32-f127
-GCC_CFLAGS += $(CMN1)
-ICC_CFLAGS += $(CMN1)
+COMMON_CFLAGS += -mconstant-gp -fno-unwind-tables -mfixed-range=f32-f127
 
 AFLAGS += -mconstant-gp
Index: kernel/arch/mips32/Makefile.inc
===================================================================
--- kernel/arch/mips32/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/mips32/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -29,5 +29,5 @@
 BFD_ARCH = mips
 BFD = binary
-GCC_CFLAGS += -msoft-float -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mabi=32
+COMMON_CFLAGS += -msoft-float -mno-abicalls -G 0 -fno-zero-initialized-in-bss -mabi=32
 AS_PROLOG = .module softfloat;
 
@@ -40,15 +40,15 @@
 	BFD_NAME = elf32-tradlittlemips
 	ENDIANESS = LE
-	GCC_CFLAGS += -march=r4000
+	COMMON_CFLAGS += -march=r4000
 endif
 ifeq ($(MACHINE),bmalta)
 	BFD_NAME = elf32-tradbigmips
 	ENDIANESS = BE
-	GCC_CFLAGS += -D__BE__ -march=4kc
+	COMMON_CFLAGS += -D__BE__ -march=4kc
 endif
 ifeq ($(MACHINE),lmalta)
 	BFD_NAME = elf32-tradlittlemips
 	ENDIANESS = LE
-	GCC_CFLAGS += -march=4kc
+	COMMON_CFLAGS += -march=4kc
 endif
 
Index: kernel/arch/ppc32/Makefile.inc
===================================================================
--- kernel/arch/ppc32/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/ppc32/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -31,5 +31,5 @@
 BFD = binary
 
-GCC_CFLAGS += -mcpu=powerpc -msoft-float -m32
+COMMON_CFLAGS += -mcpu=powerpc -msoft-float -m32
 AFLAGS += -a32
 LFLAGS += -no-check-sections
Index: kernel/arch/riscv64/Makefile.inc
===================================================================
--- kernel/arch/riscv64/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/riscv64/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -31,5 +31,5 @@
 BFD = binary
 
-GCC_CFLAGS += -mcmodel=medany
+COMMON_CFLAGS += -mcmodel=medany
 
 BITS = 64
Index: kernel/arch/sparc64/Makefile.inc
===================================================================
--- kernel/arch/sparc64/Makefile.inc	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ kernel/arch/sparc64/Makefile.inc	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -31,5 +31,5 @@
 BFD = binary
 
-GCC_CFLAGS += -m64 -mcpu=ultrasparc -mcmodel=medlow -mno-fpu
+COMMON_CFLAGS += -m64 -mcpu=ultrasparc -mcmodel=medlow -mno-fpu
 
 LFLAGS += -no-check-sections
Index: tools/autotool.py
===================================================================
--- tools/autotool.py	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ tools/autotool.py	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -54,4 +54,5 @@
 PACKAGE_GCC = "preferably version 4.7.0 or newer"
 PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
+PACKAGE_CLANG = "reasonably recent version of clang needs to be installed"
 
 COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
@@ -210,5 +211,4 @@
 	target = None
 	gnu_target = None
-	clang_target = None
 	helenos_target = None
 	cc_args = []
@@ -220,10 +220,8 @@
 		if (config['CROSS_TARGET'] == "arm32"):
 			gnu_target = "arm-linux-gnueabi"
-			clang_target = "arm-unknown-none"
 			helenos_target = "arm-helenos-gnueabi"
 		
 		if (config['CROSS_TARGET'] == "ia32"):
 			gnu_target = "i686-pc-linux-gnu"
-			clang_target = "i686-unknown-none"
 			helenos_target = "i686-pc-helenos"
 		
@@ -231,5 +229,4 @@
 			cc_args.append("-mabi=32")
 			gnu_target = "mipsel-linux-gnu"
-			clang_target = "mipsel-unknown-none"
 			helenos_target = "mipsel-helenos"
 	
@@ -237,5 +234,4 @@
 		target = config['PLATFORM']
 		gnu_target = "amd64-linux-gnu"
-		clang_target = "x86_64-unknown-none"
 		helenos_target = "amd64-helenos"
 	
@@ -243,5 +239,4 @@
 		target = config['PLATFORM']
 		gnu_target = "arm-linux-gnueabi"
-		clang_target = "arm-unknown-none-eabi"
 		helenos_target = "arm-helenos-gnueabi"
 	
@@ -249,5 +244,4 @@
 		target = config['PLATFORM']
 		gnu_target = "i686-pc-linux-gnu"
-		clang_target = "i686-unknown-none"
 		helenos_target = "i686-pc-helenos"
 	
@@ -264,5 +258,4 @@
 			target = config['PLATFORM']
 			gnu_target = "mipsel-linux-gnu"
-			clang_target = "mipsel-unknown-none"
 			helenos_target = "mipsel-helenos"
 		
@@ -270,5 +263,4 @@
 			target = "mips32eb"
 			gnu_target = "mips-linux-gnu"
-			clang_target = "mips-unknown-none"
 			helenos_target = "mips-helenos"
 	
@@ -280,5 +272,4 @@
 			target = config['PLATFORM']
 			gnu_target = "mips64el-linux-gnu"
-			clang_target = "mips64el-unknown-none"
 			helenos_target = "mips64el-helenos"
 	
@@ -286,5 +277,4 @@
 		target = config['PLATFORM']
 		gnu_target = "ppc-linux-gnu"
-		clang_target = "ppc-unknown-none"
 		helenos_target = "ppc-helenos"
 	
@@ -292,5 +282,4 @@
 		target = config['PLATFORM']
 		gnu_target = "riscv64-unknown-linux-gnu"
-		clang_target = "riscv-unknown-none"
 		helenos_target = "riscv64-helenos"
 	
@@ -298,8 +287,7 @@
 		target = config['PLATFORM']
 		gnu_target = "sparc64-linux-gnu"
-		clang_target = "sparc-unknown-none"
 		helenos_target = "sparc64-helenos"
 	
-	return (target, cc_args, gnu_target, clang_target, helenos_target)
+	return (target, cc_args, gnu_target, helenos_target)
 
 def check_app(args, name, details):
@@ -351,4 +339,14 @@
 	return found
 
+def check_clang(path, prefix, common, details):
+	"Check for clang"
+	
+	common['CLANG'] = "%sclang" % prefix
+	
+	if (not path is None):
+		common['CLANG'] = "%s/%s" % (path, common['CLANG'])
+	
+	check_app([common['CLANG'], "--version"], "clang", details)
+
 def check_gcc(path, prefix, common, details):
 	"Check for GCC"
@@ -427,6 +425,5 @@
 	outf.close()
 	
-	args = [common['CC']]
-	args.extend(common['CC_ARGS'])
+	args = common['CC_AUTOGEN'].split(' ')
 	args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
 	
@@ -547,6 +544,5 @@
 	outf.close()
 	
-	args = [common['CC']]
-	args.extend(common['CC_ARGS'])
+	args = common['CC_AUTOGEN'].split(' ')
 	args.extend(["-S", "-o", PROBE_INT128_OUTPUT, PROBE_INT128_SOURCE])
 	
@@ -852,7 +848,6 @@
 		
 		# Compiler
-		common['CC_ARGS'] = []
 		if (config['COMPILER'] == "gcc_cross"):
-			target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
+			target, cc_args, gnu_target, helenos_target = get_target(config)
 			
 			if (target is None) or (gnu_target is None):
@@ -867,9 +862,9 @@
 			
 			check_common(common, "GCC")
-			common['CC'] = common['GCC']
-			common['CC_ARGS'].extend(cc_args)
+			common['CC'] = " ".join([common['GCC']] + cc_args)
+			common['CC_AUTOGEN'] = common['CC']
 		
 		if (config['COMPILER'] == "gcc_helenos"):
-			target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
+			target, cc_args, gnu_target, helenos_target = get_target(config)
 			
 			if (target is None) or (helenos_target is None):
@@ -884,6 +879,6 @@
 			
 			check_common(common, "GCC")
-			common['CC'] = common['GCC']
-			common['CC_ARGS'].extend(cc_args)
+			common['CC'] = " ".join([common['GCC']] + cc_args)
+			common['CC_AUTOGEN'] = common['CC']
 		
 		if (config['COMPILER'] == "gcc_native"):
@@ -893,4 +888,5 @@
 			check_common(common, "GCC")
 			common['CC'] = common['GCC']
+			common['CC_AUTOGEN'] = common['CC']
 		
 		if (config['COMPILER'] == "icc"):
@@ -900,10 +896,11 @@
 			
 			common['CC'] = "icc"
+			common['CC_AUTOGEN'] = common['CC']
 		
 		if (config['COMPILER'] == "clang"):
-			target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
-			
-			if (target is None) or (gnu_target is None) or (clang_target is None):
-				print_error(["Unsupported compiler target for clang.",
+			target, cc_args, gnu_target, helenos_target = get_target(config)
+			
+			if (target is None) or (gnu_target is None):
+				print_error(["Unsupported compiler target.",
 				             "Please contact the developers of HelenOS."])
 			
@@ -911,14 +908,16 @@
 			prefix = "%s-" % gnu_target
 			
-			check_app(["clang", "--version"], "clang compiler", "preferably version 1.0 or newer")
-			check_gcc(path, prefix, common, PACKAGE_GCC)
-			check_binutils(path, prefix, common, PACKAGE_BINUTILS)
-			
-			check_common(common, "GCC")
-			common['CC'] = "clang"
-			common['CC_ARGS'].extend(cc_args)
-			common['CC_ARGS'].append("-target")
-			common['CC_ARGS'].append(clang_target)
-			common['CLANG_TARGET'] = clang_target
+			check_binutils(path, prefix, common, PACKAGE_CROSS)
+			check_clang(path, prefix, common, PACKAGE_CLANG)
+			
+			check_common(common, "CLANG")
+			common['CC'] = " ".join([common['CLANG']] + cc_args)
+			common['CC_AUTOGEN'] = common['CC'] + " -no-integrated-as"
+			
+			if (config['INTEGRATED_AS'] == "yes"):
+				common['CC'] += " -integrated-as"
+			
+			if (config['INTEGRATED_AS'] == "no"):
+				common['CC'] += " -no-integrated-as"
 		
 		check_python()
Index: tools/toolchain.sh
===================================================================
--- tools/toolchain.sh	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ tools/toolchain.sh	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -283,4 +283,6 @@
 	ORIGINAL="`pwd`"
 	
+	mkdir -p "${OUTSIDE}"
+	
 	cd "${OUTSIDE}"
 	check_error $? "Unable to change directory to ${OUTSIDE}."
@@ -443,8 +445,6 @@
 	
 	echo ">>> Removing previous content"
-	$REAL_INSTALL && cleanup_dir "${PREFIX}"
 	cleanup_dir "${WORKDIR}"
 	
-	$REAL_INSTALL && create_dir "${PREFIX}" "destination directory"
 	create_dir "${OBJDIR}" "GCC object directory"
 	
@@ -478,5 +478,5 @@
 		"--target=${TARGET}" \
 		"--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
-		--disable-nls --disable-werror
+		--disable-nls --disable-werror --enable-gold
 	check_error $? "Error configuring binutils."
 	
@@ -486,9 +486,5 @@
 	
 	change_title "binutils: install (${PLATFORM})"
-	if $REAL_INSTALL ; then
-		make install
-	else
-		make install "DESTDIR=${INSTALL_DIR}"
-	fi
+	make install "DESTDIR=${INSTALL_DIR}"
 	check_error $? "Error installing binutils."
 	
@@ -513,9 +509,5 @@
 	
 	change_title "GCC: install (${PLATFORM})"
-	if $REAL_INSTALL ; then
-		PATH="${PATH}:${PREFIX}/bin" make install-gcc
-	else
-		PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
-	fi
+	PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
 	check_error $? "Error installing GCC."
 	
@@ -531,5 +523,5 @@
 			"--target=${TARGET}" \
 			"--prefix=${PREFIX}" "--program-prefix=${TARGET}-" \
-			--enable-werror=no
+			--enable-werror=no --without-guile
 		check_error $? "Error configuring GDB."
 		
@@ -539,12 +531,21 @@
 		
 		change_title "GDB: make (${PLATFORM})"
-		if $REAL_INSTALL ; then
-			PATH="${PATH}:${PREFIX}/bin" make install
-		else
-			PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install "DESTDIR=${INSTALL_DIR}"
-		fi
+		PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install "DESTDIR=${INSTALL_DIR}"
 		check_error $? "Error installing GDB."
 	fi
 	
+	# Symlink clang and lld to the install path.
+	CLANG=`which clang 2> /dev/null || echo "/usr/bin/clang"`
+	LLD=`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`
+	
+	ln -s $CLANG "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-clang"
+	ln -s $LLD "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-ld.lld"
+	
+	if $REAL_INSTALL ; then
+		echo ">>> Moving to the destination directory."
+		cleanup_dir "${PREFIX}"
+		echo mv "${INSTALL_DIR}/${PREFIX}" "${PREFIX}"
+		mv "${INSTALL_DIR}/${PREFIX}" "${PREFIX}"
+	fi
 	
 	cd "${BASEDIR}"
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -160,6 +160,13 @@
 LIBNETTL_PREFIX = $(LIB_PREFIX)/nettl
 
-AFLAGS = --fatal-warnings
+AFLAGS =
 LFLAGS = --fatal-warnings
+
+# FIXME: This condition is a workaround for issues #692 and #693.
+ifneq ($(KARCH),ia64)
+ifneq ($(KARCH),mips32)
+	AFLAGS += --fatal-warnings
+endif
+endif
 
 ifeq ($(STATIC_NEEDED),y)
@@ -203,10 +210,4 @@
 endif
 
-ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
-	OPTIMIZATION = s
-else
-	OPTIMIZATION = 3
-endif
-
 # PCUT-based unit tests
 ifneq ($(TEST_SOURCES),)
@@ -234,33 +235,26 @@
 	find . -name '*.lo' -follow -exec rm \{\} \;
 
-GCC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
-	-finput-charset=UTF-8 -ffreestanding -fno-builtin -ffunction-sections \
-	-nostdlib -nostdinc -Wall -Wextra -Wno-clobbered -Wno-unused-parameter \
-	-Wmissing-prototypes -std=gnu99 -Werror-implicit-function-declaration \
-	-Wwrite-strings -pipe -ggdb -D__$(ENDIANESS)__
-
-ICC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
-	-finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
-	-Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
-	-Werror-implicit-function-declaration -Wwrite-strings \
-	-pipe -g -D__$(ENDIANESS)__
-
-# clang does not support following options but I am not sure whether
-# something won't break because of that:
-# -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) -finput-charset=UTF-8
-CLANG_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-ffreestanding -fno-builtin -nostdlib -nostdinc \
-	-Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
+COMMON_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
+	-ffreestanding -fno-builtin -nostdlib -nostdinc -fexec-charset=UTF-8 \
+	-finput-charset=UTF-8 -D__$(ENDIANESS)__
+
+GCC_CFLAGS = -ffunction-sections -Wall -Wextra -Wno-clobbered \
+	-Wno-unused-parameter -Wmissing-prototypes -std=gnu99 \
+	-Werror-implicit-function-declaration \
+	-Wwrite-strings -pipe
+
+ICC_CFLAGS = -Wall -Wextra -Wno-clobbered -Wno-unused-parameter \
+	-Wmissing-prototypes -Werror-implicit-function-declaration \
+	-Wwrite-strings -pipe
+
+# -Wno-missing-prototypes is there because it warns about main().
+# This should be fixed elsewhere.
+CLANG_CFLAGS = -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-typedef-redefinition \
+	-Wno-missing-prototypes -Wno-unused-command-line-argument \
 	-std=gnu99 -Werror-implicit-function-declaration -Wwrite-strings \
-	-integrated-as -pipe -g -target $(CLANG_TARGET) -D__$(ENDIANESS)__
-
-LIB_CFLAGS = $(CFLAGS) -fPIC
-LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
+	-pipe -fno-stack-protector -fno-PIC
 
 ifeq ($(CONFIG_DEBUG),y)
-	GCC_CFLAGS += -Werror
-	ICC_CFLAGS += -Werror
+	COMMON_CFLAGS += -Werror
 endif
 
@@ -273,5 +267,5 @@
 # Prepare for POSIX before including platform specific stuff
 ifeq ($(POSIX_COMPAT),y)
-	CFLAGS = -I$(LIBPOSIX_PREFIX)/include/posix -I$(LIBPOSIX_PREFIX)/include/
+	CFLAGS += -I$(LIBPOSIX_PREFIX)/include/posix -I$(LIBPOSIX_PREFIX)/include/
 	BASE_LIBS = $(LIBPOSIX_PREFIX)/libposixaslibc.a $(LIBPOSIX_PREFIX)/libc4posix.a $(LIBSOFTINT_PREFIX)/libsoftint.a
 endif
@@ -288,31 +282,37 @@
 
 ifeq ($(COMPILER),gcc_cross)
-	CFLAGS += $(GCC_CFLAGS)
+	CFLAGS += $(COMMON_CFLAGS) $(GCC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
 
 ifeq ($(COMPILER),gcc_helenos)
-	CFLAGS += $(GCC_CFLAGS)
+	CFLAGS += $(COMMON_CFLAGS) $(GCC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
 
 ifeq ($(COMPILER),gcc_native)
-	CFLAGS += $(GCC_CFLAGS)
+	CFLAGS += $(COMMON_CFLAGS) $(GCC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
 
 ifeq ($(COMPILER),icc)
-	CFLAGS += $(ICC_CFLAGS)
+	CFLAGS += $(COMMON_CFLAGS) $(ICC_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
 
 ifeq ($(COMPILER),clang)
-	CFLAGS += $(CLANG_CFLAGS)
+	CFLAGS += $(COMMON_CFLAGS) $(CLANG_CFLAGS)
 	DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
 endif
+
+LIB_CFLAGS = $(CFLAGS) -fPIC
+LIB_LFLAGS = $(LFLAGS) -shared -soname $(LSONAME) --whole-archive
 
 ifneq ($(MAKECMDGOALS),clean)
 -include $(DEPEND)
 endif
+
+AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
+LD_CFLAGS := $(addprefix -Xlinker ,$(LFLAGS))
 
 OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
@@ -378,5 +378,5 @@
 
 %.o: %.S $(DEPEND)
-	$(GCC) $(DEFS) $(GCC_CFLAGS) $(EXTRA_CFLAGS) -D__ASM__ -c $< -o $@
+	$(CC) $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__ -c $< -o $@
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) -D__ASM__
@@ -384,5 +384,5 @@
 
 %.o: %.s $(DEPEND)
-	$(AS) $(AFLAGS) -o $@ $<
+	$(CC) $(DEFS) $(CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__ -c $< -o $@
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ as asm
@@ -402,5 +402,5 @@
 
 %.lo: %.S $(DEPEND)
-	$(CC) $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) -D__ASM__ -c $< -o $@
+	$(CC) $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__ -c $< -o $@
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) -D__ASM__
@@ -408,5 +408,5 @@
 
 %.lo: %.s $(DEPEND)
-	$(AS) $(AFLAGS) -o $@ $<
+	$(CC) $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS) $(AS_CFLAGS) -D__ASM__ -c $< -o $@
 ifeq ($(PRECHECK),y)
 	$(JOBFILE) $(JOB) $< $@ as asm
Index: uspace/app/bdsh/cmds/builtin_cmds.c
===================================================================
--- uspace/app/bdsh/cmds/builtin_cmds.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/app/bdsh/cmds/builtin_cmds.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -79,8 +79,7 @@
 		return (char *)NULL;
 
-	for(i=0; builtin_aliases[i] != NULL; i++) {
+	for(i=0; builtin_aliases[i] != NULL; i+=2) {
 		if (!str_cmp(builtin_aliases[i], command))
-			return (char *)builtin_aliases[++i];
-		i++;
+			return (char *)builtin_aliases[i+1];
 	}
 
Index: uspace/app/bdsh/cmds/mod_cmds.c
===================================================================
--- uspace/app/bdsh/cmds/mod_cmds.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/app/bdsh/cmds/mod_cmds.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -96,8 +96,7 @@
 		return (char *)NULL;
 
-	for(i=0; mod_aliases[i] != NULL; i++) {
+	for(i=0; mod_aliases[i] != NULL; i+=2) {
 		if (!str_cmp(mod_aliases[i], command))
-			return (char *)mod_aliases[++i];
-		i++;
+			return (char *)mod_aliases[i+1];
 	}
 
Index: uspace/app/fontviewer/fontviewer.c
===================================================================
--- uspace/app/fontviewer/fontviewer.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/app/fontviewer/fontviewer.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -78,5 +78,5 @@
 				points += increment;
 		
-			if ((event->key == KC_DOWN)) {
+			if (event->key == KC_DOWN) {
 				if (points <= increment) {
 					points = 1;
Index: uspace/app/nic/nic.c
===================================================================
--- uspace/app/nic/nic.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/app/nic/nic.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -120,4 +120,5 @@
 	if (sess == NULL) {
 		printf("Error connecting to service.\n");
+		rc = EIO;
 		goto error;
 	}
@@ -209,5 +210,5 @@
 }
 
-static const char *nic_multicast_mode_str(nic_unicast_mode_t mode)
+static const char *nic_multicast_mode_str(nic_multicast_mode_t mode)
 {
 	switch (mode) {
@@ -220,5 +221,5 @@
 }
 
-static const char *nic_broadcast_mode_str(nic_unicast_mode_t mode)
+static const char *nic_broadcast_mode_str(nic_broadcast_mode_t mode)
 {
 	switch (mode) {
Index: uspace/app/sbi/src/builtin/bi_task.c
===================================================================
--- uspace/app/sbi/src/builtin/bi_task.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/app/sbi/src/builtin/bi_task.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -114,5 +114,5 @@
 	}
 
-	cmd[dim] = '\0';
+	cmd[dim] = NULL;
 
 	if (os_exec((char * const *)cmd) != EOK) {
Index: uspace/app/sbi/src/run_expr.c
===================================================================
--- uspace/app/sbi/src/run_expr.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/app/sbi/src/run_expr.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -2886,5 +2886,5 @@
 				/* Is it static/nonstatic? */
 				var_sn = stree_symbol_has_attr(
-				    var_to_symbol(var), sac_static);
+				    var_to_symbol(var), sac_static) ? sn_static : sn_nonstatic;
 				if (var_sn == sn) {
 					/* Compute field type. XXX Memoize. */
Index: uspace/app/tetris/tetris.c
===================================================================
--- uspace/app/tetris/tetris.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/app/tetris/tetris.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -443,4 +443,5 @@
 void usage(void)
 {
+	fprintf(stderr, "%s", copyright);
 	fprintf(stderr, "usage: tetris [-ps] [-k keys]\n");
 	exit(1);
Index: uspace/drv/audio/sb16/dsp.c
===================================================================
--- uspace/drv/audio/sb16/dsp.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/drv/audio/sb16/dsp.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -75,5 +75,5 @@
 		[DSP_NO_BUFFER] = "NO BUFFER",
 	};
-	if (state < ARRAY_SIZE(state_names))
+	if ((size_t)state < ARRAY_SIZE(state_names))
 		return state_names[state];
 	return "UNKNOWN";
@@ -144,7 +144,9 @@
 {
 	dsp_write(dsp, SET_SAMPLING_RATE_OUTPUT);
-	dsp_write(dsp, rate >> 8);
-	dsp_write(dsp, rate & 0xff);
-	ddf_log_verbose("Sampling rate: %hhx:%hhx.", rate >> 8, rate & 0xff);
+	uint8_t rate_lo = rate & 0xff;
+	uint8_t rate_hi = rate >> 8;
+	dsp_write(dsp, rate_hi);
+	dsp_write(dsp, rate_lo);
+	ddf_log_verbose("Sampling rate: %hhx:%hhx.", rate_hi, rate_lo);
 }
 
@@ -202,9 +204,4 @@
 	
 	return ret;
-}
-
-static inline size_t sample_count(pcm_sample_format_t format, size_t byte_count)
-{
-	return byte_count / pcm_sample_format_size(format);
 }
 
Index: uspace/drv/bus/isa/i8237.c
===================================================================
--- uspace/drv/bus/isa/i8237.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/drv/bus/isa/i8237.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -371,5 +371,5 @@
 	
 	/* 16 bit transfers are a bit special */
-	ddf_msg(LVL_DEBUG, "Unspoiled address %#" PRIx32 " (size %" PRIu16 ")",
+	ddf_msg(LVL_DEBUG, "Unspoiled address %#" PRIx32 " (size %" PRIu32 ")",
 	    pa, size);
 	if (is_dma16(channel)) {
@@ -388,5 +388,5 @@
 	
 	ddf_msg(LVL_DEBUG, "Setting channel %u to address %#" PRIx32 " "
-	    "(size %" PRIu16 "), mode %hhx.", channel, pa, size, mode);
+	    "(size %" PRIu32 "), mode %hhx.", channel, pa, size, mode);
 	
 	/* Mask DMA request */
Index: uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c
===================================================================
--- uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -78,5 +78,5 @@
 
 	/* Allow less data on input. */
-	if (dir == USB_DIRECTION_IN) {
+	if (direction == USB_DIRECTION_IN) {
 		OHCI_MEM32_SET(instance->status, TD_STATUS_ROUND_FLAG);
 	}
Index: uspace/drv/bus/usb/ohci/ohci_rh.c
===================================================================
--- uspace/drv/bus/usb/ohci/ohci_rh.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/drv/bus/usb/ohci/ohci_rh.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -367,5 +367,5 @@
 	case USB_HUB_FEATURE_C_PORT_RESET:        /*20*/
 		usb_log_debug2("Clearing port C_CONNECTION, C_ENABLE, "
-		    "C_SUSPEND, C_OC or C_RESET on port %"PRIu16".\n", port);
+		    "C_SUSPEND, C_OC or C_RESET on port %u.\n", port);
 		/* Bit offsets correspond to the feature number */
 		OHCI_WR(hub->registers->rh_port_status[port],
@@ -416,5 +416,5 @@
 	case USB_HUB_FEATURE_PORT_RESET:   /*4*/
 		usb_log_debug2("Setting port POWER, ENABLE, SUSPEND or RESET "
-		    "on port %"PRIu16".\n", port);
+		    "on port %u.\n", port);
 		/* Bit offsets correspond to the feature number */
 		OHCI_WR(hub->registers->rh_port_status[port], 1 << feature);
Index: uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.c
===================================================================
--- uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -267,5 +267,5 @@
 	amdm37x_dispc_t *dispc = vis->dev_ctx;
 	const visual_t visual = mode.cell_visual.pixel_visual;
-	assert(visual < sizeof(pixel2visual_table) / sizeof(pixel2visual_table[0]));
+	assert((size_t)visual < sizeof(pixel2visual_table) / sizeof(pixel2visual_table[0]));
 	const unsigned bpp = pixel2visual_table[visual].bpp;
 	pixel2visual_t p2v = pixel2visual_table[visual].func;
Index: uspace/drv/fb/kfb/port.c
===================================================================
--- uspace/drv/fb/kfb/port.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/drv/fb/kfb/port.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -66,4 +66,5 @@
 
 typedef struct {
+	sysarg_t paddr;
 	sysarg_t width;
 	sysarg_t height;
@@ -85,71 +86,24 @@
 static vslmode_list_element_t pixel_mode;
 
-static pixel_t color_table[16] = {
-	[COLOR_BLACK]       = 0x000000,
-	[COLOR_BLUE]        = 0x0000f0,
-	[COLOR_GREEN]       = 0x00f000,
-	[COLOR_CYAN]        = 0x00f0f0,
-	[COLOR_RED]         = 0xf00000,
-	[COLOR_MAGENTA]     = 0xf000f0,
-	[COLOR_YELLOW]      = 0xf0f000,
-	[COLOR_WHITE]       = 0xf0f0f0,
-
-	[COLOR_BLACK + 8]   = 0x000000,
-	[COLOR_BLUE + 8]    = 0x0000ff,
-	[COLOR_GREEN + 8]   = 0x00ff00,
-	[COLOR_CYAN + 8]    = 0x00ffff,
-	[COLOR_RED + 8]     = 0xff0000,
-	[COLOR_MAGENTA + 8] = 0xff00ff,
-	[COLOR_YELLOW + 8]  = 0xffff00,
-	[COLOR_WHITE + 8]   = 0xffffff,
-};
-
-static inline void attrs_rgb(char_attrs_t attrs, pixel_t *bgcolor, pixel_t *fgcolor)
-{
-	switch (attrs.type) {
-	case CHAR_ATTR_STYLE:
-		switch (attrs.val.style) {
-		case STYLE_NORMAL:
-			*bgcolor = color_table[COLOR_WHITE];
-			*fgcolor = color_table[COLOR_BLACK];
-			break;
-		case STYLE_EMPHASIS:
-			*bgcolor = color_table[COLOR_WHITE];
-			*fgcolor = color_table[COLOR_RED];
-			break;
-		case STYLE_INVERTED:
-			*bgcolor = color_table[COLOR_BLACK];
-			*fgcolor = color_table[COLOR_WHITE];
-			break;
-		case STYLE_SELECTED:
-			*bgcolor = color_table[COLOR_RED];
-			*fgcolor = color_table[COLOR_WHITE];
-			break;
-		}
-		break;
-	case CHAR_ATTR_INDEX:
-		*bgcolor = color_table[(attrs.val.index.bgcolor & 7) |
-		    ((attrs.val.index.attr & CATTR_BRIGHT) ? 8 : 0)];
-		*fgcolor = color_table[(attrs.val.index.fgcolor & 7) |
-		    ((attrs.val.index.attr & CATTR_BRIGHT) ? 8 : 0)];
-		break;
-	case CHAR_ATTR_RGB:
-		*bgcolor = attrs.val.rgb.bgcolor;
-		*fgcolor = attrs.val.rgb.fgcolor;
-		break;
-	}
-}
-
 static int kfb_claim(visualizer_t *vs)
 {
-	return EOK;
+	return physmem_map(kfb.paddr + kfb.offset,
+	    ALIGN_UP(kfb.size, PAGE_SIZE) >> PAGE_WIDTH,
+	    AS_AREA_READ | AS_AREA_WRITE, (void *) &kfb.addr);
 }
 
 static int kfb_yield(visualizer_t *vs)
 {
+	int rc;
+
 	if (vs->mode_set) {
 		vs->ops.handle_damage = NULL;
 	}
 
+	rc = physmem_unmap(kfb.addr);
+	if (rc != EOK)
+		return rc;
+
+	kfb.addr = NULL;
 	return EOK;
 }
@@ -211,7 +165,14 @@
 {
 	visualizer_t *vsl;
+	int rc;
 
 	vsl = (visualizer_t *) ddf_fun_data_get((ddf_fun_t *)arg);
 	graph_visualizer_connection(vsl, iid, icall, NULL);
+
+	if (kfb.addr != NULL) {
+		rc = physmem_unmap(kfb.addr);
+		if (rc == EOK)
+			kfb.addr = NULL;
+	}
 }
 
@@ -266,4 +227,5 @@
 	kfb.width = width;
 	kfb.height = height;
+	kfb.paddr = paddr;
 	kfb.offset = offset;
 	kfb.scanline = scanline;
@@ -343,10 +305,4 @@
 	kfb.size = scanline * height;
 	kfb.addr = AS_AREA_ANY;
-	
-	rc = physmem_map(paddr + offset,
-	    ALIGN_UP(kfb.size, PAGE_SIZE) >> PAGE_WIDTH,
-	    AS_AREA_READ | AS_AREA_WRITE, (void *) &kfb.addr);
-	if (rc != EOK)
-		return rc;
 	
 	ddf_fun_t *fun_vs = ddf_fun_create(dev, fun_exposed, "vsl0");
Index: uspace/drv/nic/e1k/e1k.c
===================================================================
--- uspace/drv/nic/e1k/e1k.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/drv/nic/e1k/e1k.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -365,13 +365,16 @@
 	if (ctrl & CTRL_SLU) {
 		ctrl &= ~(CTRL_SLU);
+		E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
 		fibril_mutex_unlock(&e1000->ctrl_lock);
+		
 		thread_usleep(10);
+		
 		fibril_mutex_lock(&e1000->ctrl_lock);
+		ctrl = E1000_REG_READ(e1000, E1000_CTRL);
 		ctrl |= CTRL_SLU;
+		E1000_REG_WRITE(e1000, E1000_CTRL, ctrl);
 	}
 	
 	fibril_mutex_unlock(&e1000->ctrl_lock);
-	
-	e1000_link_restart(e1000);
 }
 
Index: uspace/drv/nic/rtl8139/driver.c
===================================================================
--- uspace/drv/nic/rtl8139/driver.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/drv/nic/rtl8139/driver.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -125,17 +125,9 @@
 
 
-/** Disable interrupts on controller
+/** Set interrupts on controller
  *
  *  @param rtl8139  The card private structure
  */
-inline static void rtl8139_hw_int_disable(rtl8139_t *rtl8139)
-{
-	pio_write_16(rtl8139->io_port + IMR, 0x0);
-}
-/** Enable interrupts on controller
- *
- *  @param rtl8139  The card private structure
- */
-inline static void rtl8139_hw_int_enable(rtl8139_t *rtl8139)
+inline static void rtl8139_hw_int_set(rtl8139_t *rtl8139)
 {
 	pio_write_16(rtl8139->io_port + IMR, rtl8139->int_mask);
@@ -274,18 +266,4 @@
 }
 
-/**  Provide OR in the 32bit register (set selected bits to 1)
- *
- *   @param rtl8139     The rtl8139 structure
- *   @param reg_offset  Register offset in the device IO space
- *   @param bits_add    The value to or
- */
-inline static void rtl8139_hw_reg_add_32(rtl8139_t * rtl8139, size_t reg_offset,
-    uint32_t bits_add)
-{
-	uint32_t value = pio_read_32(rtl8139->io_port + reg_offset);
-	value |= bits_add;
-	pio_write_32(rtl8139->io_port + reg_offset, value);
-}
-
 /**  Unset selected bits in 8bit register
  *
@@ -301,19 +279,4 @@
 	pio_write_8(rtl8139->io_port + reg_offset, value);
 }
-
-/**  Unset selected bits in 32bit register
- *
- *   @param rtl8139     The rtl8139 structure
- *   @param reg_offset  Register offset in the device IO space
- *   @param bits_add    The mask of bits to remove
- */
-inline static void rtl8139_hw_reg_rem_32(rtl8139_t * rtl8139, size_t reg_offset,
-    uint32_t bits_add)
-{
-	uint32_t value = pio_read_32(rtl8139->io_port + reg_offset);
-	value &= ~bits_add;
-	pio_write_32(rtl8139->io_port + reg_offset, value);
-}
-
 
 static int rtl8139_set_addr(ddf_fun_t *fun, const nic_address_t *);
@@ -871,5 +834,5 @@
 
 	/* Turn the interrupts on again */
-	rtl8139_hw_int_enable(rtl8139);
+	rtl8139_hw_int_set(rtl8139);
 };
 
@@ -955,5 +918,5 @@
 
 	rtl8139->int_mask = RTL_DEFAULT_INTERRUPTS;
-	rtl8139_hw_int_enable(rtl8139);
+	rtl8139_hw_int_set(rtl8139);
 
 	int rc = irc_enable_interrupt(rtl8139->irq);
@@ -2120,5 +2083,5 @@
 		/* Disable timer interrupts while working with timer-related data */
 		rtl8139->int_mask = 0;
-		rtl8139_hw_int_enable(rtl8139);
+		rtl8139_hw_int_set(rtl8139);
 
 		rtl8139->poll_timer = new_timer;
@@ -2143,5 +2106,5 @@
 	}
 
-	rtl8139_hw_int_enable(rtl8139);
+	rtl8139_hw_int_set(rtl8139);
 
 	fibril_mutex_unlock(&rtl8139->rx_lock);
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/Makefile	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -194,5 +194,5 @@
 %.h: %.ag
 	$(AUTOGEN) probe $< >$<.probe.c
-	$(CC) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
+	$(CC_AUTOGEN) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
 	$(AUTOGEN) generate $< <$<.probe.s >$@   
 
Index: uspace/lib/c/arch/amd64/Makefile.common
===================================================================
--- uspace/lib/c/arch/amd64/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/amd64/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -27,6 +27,5 @@
 #
 
-GCC_CFLAGS += -mno-tls-direct-seg-refs -fno-omit-frame-pointer
-CLANG_CFLAGS += -fno-omit-frame-pointer
+COMMON_CFLAGS += -mno-tls-direct-seg-refs -fno-omit-frame-pointer
 LFLAGS += --gc-sections
 
Index: uspace/lib/c/arch/amd64/include/libarch/elf_linux.h
===================================================================
--- uspace/lib/c/arch/amd64/include/libarch/elf_linux.h	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/amd64/include/libarch/elf_linux.h	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -34,5 +34,5 @@
 
 #ifndef LIBC_amd64_ELF_LINUX_H_
-#define LBIC_amd64_ELF_LINUX_H_
+#define LIBC_amd64_ELF_LINUX_H_
 
 #include <libarch/istate.h>
Index: uspace/lib/c/arch/arm32/Makefile.common
===================================================================
--- uspace/lib/c/arch/arm32/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/arm32/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -28,5 +28,5 @@
 #
 
-GCC_CFLAGS += -ffixed-r9 -mtp=soft -fno-omit-frame-pointer -mapcs-frame \
+COMMON_CFLAGS += -ffixed-r9 -mtp=soft -fno-omit-frame-pointer -mapcs-frame \
 	-march=$(subst _,-,$(PROCESSOR_ARCH))
 
@@ -34,5 +34,5 @@
 
 ifeq ($(CONFIG_FPU),y)
-	GCC_CFLAGS += -mfloat-abi=hard
+	COMMON_CFLAGS += -mfloat-abi=hard
 else
 	BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
Index: uspace/lib/c/arch/ia32/Makefile.common
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/ia32/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -28,11 +28,10 @@
 
 ifeq ($(PROCESSOR),i486)
-	GCC_CFLAGS += -march=i486 
+	COMMON_CFLAGS += -march=i486
 else
-	GCC_CFLAGS += -march=pentium
+	COMMON_CFLAGS += -march=pentium
 endif
 
-GCC_CFLAGS += -mno-tls-direct-seg-refs -fno-omit-frame-pointer
-CLANG_CFLAGS += -fno-omit-frame-pointer
+COMMON_CFLAGS += -mno-tls-direct-seg-refs -fno-omit-frame-pointer
 LFLAGS += --gc-sections
 
Index: uspace/lib/c/arch/ia64/Makefile.common
===================================================================
--- uspace/lib/c/arch/ia64/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/ia64/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -27,5 +27,5 @@
 #
 
-GCC_CFLAGS += -fno-unwind-tables
+COMMON_CFLAGS += -fno-unwind-tables
 
 ENDIANESS = LE
Index: uspace/lib/c/arch/mips32/Makefile.common
===================================================================
--- uspace/lib/c/arch/mips32/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/mips32/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -27,5 +27,5 @@
 #
 
-GCC_CFLAGS += -msoft-float -mabi=32
+COMMON_CFLAGS += -msoft-float -mabi=32
 BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
 AS_PROLOG = .module softfloat;.abicalls;
@@ -38,9 +38,9 @@
 
 ifeq ($(MACHINE),msim)
-	GCC_CFLAGS += -march=r4000 
+	COMMON_CFLAGS += -march=r4000
 endif
 
 ifeq ($(MACHINE),lmalta)
-	GCC_CFLAGS += -march=4kc
+	COMMON_CFLAGS += -march=4kc
 endif
 
Index: uspace/lib/c/arch/mips32eb/Makefile.common
===================================================================
--- uspace/lib/c/arch/mips32eb/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/mips32eb/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -27,5 +27,5 @@
 #
 
-GCC_CFLAGS += -msoft-float -mabi=32
+COMMON_CFLAGS += -msoft-float -mabi=32
 BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
 AS_PROLOG = .module softfloat;.abicalls;
@@ -38,5 +38,5 @@
 
 ifeq ($(MACHINE),bmalta)
-	GCC_CFLAGS += -march=4kc
+	COMMON_CFLAGS += -march=4kc
 endif
 
Index: uspace/lib/c/arch/ppc32/Makefile.common
===================================================================
--- uspace/lib/c/arch/ppc32/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/ppc32/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -33,5 +33,5 @@
 endif
 
-GCC_CFLAGS += -mcpu=powerpc -m$(FLOATS)-float -m32
+COMMON_CFLAGS += -mcpu=powerpc -m$(FLOATS)-float -m32
 BASE_LIBS += $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
 AFLAGS += -a32
Index: uspace/lib/c/arch/sparc64/Makefile.common
===================================================================
--- uspace/lib/c/arch/sparc64/Makefile.common	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/arch/sparc64/Makefile.common	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -28,10 +28,10 @@
 
 ifeq ($(PROCESSOR),sun4v)
-GCC_CFLAGS += -mcpu=niagara -mno-vis
+COMMON_CFLAGS += -mcpu=niagara -mno-vis
 else
-GCC_CFLAGS += -mcpu=ultrasparc
+COMMON_CFLAGS += -mcpu=ultrasparc
 endif
 
-GCC_CFLAGS += -m64 -mcmodel=medlow
+COMMON_CFLAGS += -m64 -mcmodel=medlow
 
 LFLAGS += -no-check-sections --gc-sections
Index: uspace/lib/c/generic/cap.c
===================================================================
--- uspace/lib/c/generic/cap.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/generic/cap.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -185,6 +185,5 @@
 	sunit = NULL;
 
-	if (cap->cunit < 0 || cap->cunit >= CU_LIMIT)
-		assert(false);
+	assert(cap->cunit < CU_LIMIT);
 
 	rc = ipow10_u64(cap->dp, &div);
Index: uspace/lib/c/include/types/label.h
===================================================================
--- uspace/lib/c/include/types/label.h	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/include/types/label.h	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -124,4 +124,6 @@
 } label_pcnt_t;
 
+#define LPC_LIMIT (lpc_minix + 1)
+
 #endif
 
Index: uspace/lib/c/test/odict.c
===================================================================
--- uspace/lib/c/test/odict.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/c/test/odict.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -272,5 +272,4 @@
 
 		v = seq_next(v);
-		++i;
 	}
 }
Index: uspace/lib/fdisk/src/fdisk.c
===================================================================
--- uspace/lib/fdisk/src/fdisk.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/fdisk/src/fdisk.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -1015,5 +1015,5 @@
 	max_blocks = fdisk_ba_align_up(dev, max_blocks);
 
-	pcnt = -1;
+	pcnt = LPC_LIMIT;
 
 	switch (pspec->fstype) {
@@ -1034,5 +1034,5 @@
 	}
 
-	if (pcnt < 0)
+	if (pcnt == LPC_LIMIT)
 		return EINVAL;
 
Index: uspace/lib/hound/src/client.c
===================================================================
--- uspace/lib/hound/src/client.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/hound/src/client.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -48,5 +48,5 @@
 
 /** Stream structure */
-typedef struct hound_stream {
+struct hound_stream {
 	/** link in context's list */
 	link_t link;
@@ -59,5 +59,5 @@
 	/** Stream flags */
 	int flags;
-} hound_stream_t;
+};
 
 /**
@@ -72,5 +72,5 @@
 
 /** Hound client context structure */
-typedef struct hound_context {
+struct hound_context {
 	/** Audio session */
 	hound_sess_t *session;
@@ -89,5 +89,5 @@
 	/** Assigned context id */
 	hound_context_id_t id;
-} hound_context_t;
+};
 
 /**
Index: uspace/lib/nettl/src/amap.c
===================================================================
--- uspace/lib/nettl/src/amap.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/nettl/src/amap.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -58,4 +58,20 @@
 #include <stdint.h>
 #include <stdlib.h>
+
+/** Convert association map flags to port range flags.
+ *
+ * @param flags Association map flags
+ * @return Port range flags
+ */
+static portrng_flags_t aflags_to_pflags(amap_flags_t flags)
+{
+	portrng_flags_t pflags;
+
+	pflags = 0;
+	if ((flags & af_allow_system) != 0)
+		pflags |= pf_allow_system;
+
+	return pflags;
+}
 
 /** Create association map.
@@ -378,5 +394,5 @@
 	mepp = *epp;
 
-	rc = portrng_alloc(repla->portrng, epp->local.port, arg, flags,
+	rc = portrng_alloc(repla->portrng, epp->local.port, arg, aflags_to_pflags(flags),
 	    &mepp.local.port);
 	if (rc != EOK) {
@@ -422,5 +438,5 @@
 	mepp = *epp;
 
-	rc = portrng_alloc(laddr->portrng, epp->local.port, arg, flags,
+	rc = portrng_alloc(laddr->portrng, epp->local.port, arg, aflags_to_pflags(flags),
 	    &mepp.local.port);
 	if (rc != EOK) {
@@ -466,5 +482,5 @@
 	mepp = *epp;
 
-	rc = portrng_alloc(llink->portrng, epp->local.port, arg, flags,
+	rc = portrng_alloc(llink->portrng, epp->local.port, arg, aflags_to_pflags(flags),
 	    &mepp.local.port);
 	if (rc != EOK) {
@@ -498,5 +514,5 @@
 	mepp = *epp;
 
-	rc = portrng_alloc(map->unspec, epp->local.port, arg, flags,
+	rc = portrng_alloc(map->unspec, epp->local.port, arg, aflags_to_pflags(flags),
 	    &mepp.local.port);
 	if (rc != EOK) {
Index: uspace/lib/usb/src/usb.c
===================================================================
--- uspace/lib/usb/src/usb.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/usb/src/usb.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -73,5 +73,5 @@
 const char *usb_str_transfer_type(usb_transfer_type_t t)
 {
-	if (t >= ARRAY_SIZE(str_transfer_type)) {
+	if ((size_t)t >= ARRAY_SIZE(str_transfer_type)) {
 		return "invalid";
 	}
@@ -86,5 +86,5 @@
 const char *usb_str_transfer_type_short(usb_transfer_type_t t)
 {
-	if (t >= ARRAY_SIZE(str_transfer_type_short)) {
+	if ((size_t)t >= ARRAY_SIZE(str_transfer_type_short)) {
 		return "invl";
 	}
Index: uspace/lib/usbdev/src/devdrv.c
===================================================================
--- uspace/lib/usbdev/src/devdrv.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/lib/usbdev/src/devdrv.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -53,5 +53,5 @@
 
 /** USB device structure. */
-typedef struct usb_device {
+struct usb_device {
 	/** Connection to device on USB bus */
 	usb_dev_session_t *bus_session;
@@ -95,5 +95,5 @@
 	 */
 	void *driver_data;
-} usb_device_t;
+};
 
 /** Count number of pipes the driver expects.
Index: uspace/srv/fs/cdfs/cdfs_ops.c
===================================================================
--- uspace/srv/fs/cdfs/cdfs_ops.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/srv/fs/cdfs/cdfs_ops.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -117,4 +117,5 @@
 } cdfs_dir_flag_t;
 
+/** Directory record */
 typedef struct {
 	uint8_t length;
@@ -134,4 +135,22 @@
 } __attribute__((packed)) cdfs_dir_t;
 
+/** Directory record for the root directory */
+typedef struct {
+	uint8_t length;
+	uint8_t ea_length;
+	
+	uint32_t_lb lba;
+	uint32_t_lb size;
+	
+	cdfs_timestamp_t timestamp;
+	uint8_t flags;
+	uint8_t unit_size;
+	uint8_t gap_size;
+	uint16_t_lb sequence_nr;
+	
+	uint8_t name_length;
+	uint8_t name[1];
+} __attribute__((packed)) cdfs_root_dir_t;
+
 typedef struct {
 	uint8_t flags; /* reserved in primary */
@@ -155,5 +174,5 @@
 	uint32_t opt_path_table_msb;
 	
-	cdfs_dir_t root_dir;
+	cdfs_root_dir_t root_dir;
 	uint8_t pad0;
 	
Index: uspace/srv/fs/exfat/exfat_ops.c
===================================================================
--- uspace/srv/fs/exfat/exfat_ops.c	(revision c188c62aa2ffa4dc0f6451547f7cdb1966d6eb8d)
+++ uspace/srv/fs/exfat/exfat_ops.c	(revision 81b9d3ed6af6996e5039aa44755f6f7a9b396e2f)
@@ -595,4 +595,7 @@
 int exfat_node_put(fs_node_t *fn)
 {
+	if (fn == NULL)
+		return EOK;
+
 	exfat_node_t *nodep = EXFAT_NODE(fn);
 	bool destroy = false;
@@ -932,5 +935,5 @@
 int exfat_free_block_count(service_id_t service_id, uint64_t *count)
 {
-	fs_node_t *node;
+	fs_node_t *node = NULL;
 	exfat_node_t *bmap_node;
 	exfat_bs_t *bs;
@@ -945,5 +948,4 @@
 
 	bs = block_bb_get(service_id);
-	node = NULL;
 	rc = exfat_bitmap_get(&node, service_id);
 	if (rc != EOK)
