Index: HelenOS.config
===================================================================
--- HelenOS.config	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ HelenOS.config	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -1,4 +1,4 @@
 #
-# Copyright (c) 2006 Ondrej Palkovsky 
+# Copyright (c) 2006 Ondrej Palkovsky
 # All rights reserved.
 #
@@ -27,7 +27,8 @@
 #
 
-## General configuration directives
-
-# Platform
+
+## General platform options
+
+% Platform
 @ "amd64" AMD64/Intel EM64T (PC)
 @ "arm32" ARM 32-bit
@@ -41,5 +42,5 @@
 ! PLATFORM (choice)
 
-# Machine
+% Machine type
 @ "msim" MSIM
 @ "simics" Simics
@@ -48,10 +49,35 @@
 ! [PLATFORM=mips32] MACHINE (choice)
 
-# Machine type
+% Machine type
 @ "i460GX" i460GX chipset machine
 @ "ski" Ski ia64 simulator
 ! [PLATFORM=ia64] MACHINE (choice)
 
-# Compiler
+% CPU type
+@ "pentium4" Pentium 4
+@ "pentium3" Pentium 3
+@ "core" Core Solo/Duo
+@ "athlon-xp" Athlon XP
+@ "athlon-mp" Athlon MP
+! [PLATFORM=ia32|PLATFORM=ia32xen] MACHINE (choice)
+
+% CPU type
+@ "opteron" Opteron
+! [PLATFORM=amd64] MACHINE (choice)
+
+% CPU type
+@ "us" UltraSPARC I-II subarchitecture
+@ "us3" UltraSPARC III-IV subarchitecture
+! [PLATFORM=sparc64] MACHINE (choice)
+
+% Ramdisk format
+@ "tmpfs" TMPFS image
+@ "fat" FAT16 image
+! RDFMT (choice)
+
+
+## Compiler options
+
+% Compiler
 @ "gcc_cross" GCC Cross-compiler
 @ "gcc_native" GCC Native
@@ -60,5 +86,5 @@
 ! [PLATFORM=amd64|PLATFORM=ia32|PLATFORM=ia32xen] COMPILER (choice)
 
-# Compiler
+% Compiler
 @ "gcc_cross" GCC Cross-compiler
 @ "gcc_native" GCC Native
@@ -66,5 +92,5 @@
 ! [PLATFORM=ia64] COMPILER (choice)
 
-# Compiler
+% Compiler
 @ "gcc_cross" GCC Cross-compiler
 @ "gcc_native" GCC Native
@@ -72,9 +98,124 @@
 ! [PLATFORM=sparc64] COMPILER (choice)
 
-# Compiler
+% Compiler
 @ "gcc_cross" GCC Cross-compiler
 @ "gcc_native" GCC Native
 ! [PLATFORM=arm32|PLATFORM=mips32|PLATFORM=ppc32|PLATFORM=ppc64] COMPILER (choice)
 
-# Debug build
+
+## Debug build options
+
+% Debug build
 ! CONFIG_DEBUG (y/n)
+
+
+## Kernel features options
+
+% Support for SMP
+! [PLATFORM=ia32|PLATFORM=amd64|PLATFORM=ia32xen|PLATFORM=sparc64|PLATFORM=ia64] CONFIG_SMP (y/n)
+
+% Improved support for hyperthreading
+! [(PLATFORM=ia32|PLATFORM=amd64|PLATFORM=ia32xen)&CONFIG_SMP=y] CONFIG_HT (y/n)
+
+% Simics BIOS AP boot fix
+! [(PLATFORM=ia32|PLATFORM=amd64)&CONFIG_SMP=y] CONFIG_SIMICS_FIX (y/n)
+
+% Lazy FPU context switching
+! [(PLATFORM=mips32&MACHINE!=msim&MACHINE!=simics)|PLATFORM=amd64|PLATFORM=ia32|PLATFORM=ia64|PLATFORM=sparc64|PLATFORM=ia32xen] CONFIG_FPU_LAZY (y/n)
+
+% Use VHPT
+! [PLATFORM=ia64] CONFIG_VHPT (n/y)
+
+% Use TSB
+! [PLATFORM=sparc64] CONFIG_TSB (y/n)
+
+% Support for Z8530 serial port
+! [PLATFORM=sparc64] CONFIG_Z8530 (y/n)
+
+% Support for NS16550 serial port
+! [PLATFORM=sparc64|(PLATFORM=ia64&MACHINE!=ski)] CONFIG_NS16550 (n/y)
+
+% Support for Serengeti console
+! [PLATFORM=sparc64] CONFIG_SGCN (y/n)
+
+% IOSapic on default address support
+! [PLATFORM=ia64&MACHINE!=ski] CONFIG_IOSAPIC (y/n)
+
+% Interrupt-driven driver for Legacy Keyboard?
+! [CONFIG_NS16550=n&CONFIG_IOSAPIC=y&MACHINE!=ski] CONFIG_I8042_INTERRUPT_DRIVEN (y/n)
+
+% Interrupt-driven driver for NS16550?
+! [CONFIG_NS16550=y&((PLATFORM!=ia64)|CONFIG_IOSAPIC=y)&MACHINE!=ski] CONFIG_NS16550_INTERRUPT_DRIVEN (y/n)
+
+% Virtually indexed D-cache support
+! [PLATFORM=sparc64] CONFIG_VIRT_IDX_DCACHE (y/n)
+
+% Support for userspace debuggers
+! CONFIG_UDEBUG (n/y)
+
+% Kernel console support
+! CONFIG_KCONSOLE (y/n)
+
+% Detailed kernel logging
+! CONFIG_LOG (n/y)
+
+% Deadlock detection support for spinlocks
+! [CONFIG_DEBUG=y&CONFIG_SMP=y] CONFIG_DEBUG_SPINLOCK (y/n)
+
+% Watchpoint on rewriting AS with zero
+! [CONFIG_DEBUG=y&(PLATFORM=amd64|PLATFORM=ia32|PLATFORM=ia32xen)] CONFIG_DEBUG_AS_WATCHPOINT (y/n)
+
+% Save all interrupt registers
+! [CONFIG_DEBUG=y&(PLATFORM=amd64|PLATFORM=mips32|PLATFORM=ia32|PLATFORM=ia32xen)] CONFIG_DEBUG_ALLREGS (y/n)
+
+% Compile kernel tests
+! CONFIG_TEST (y/n)
+
+
+## Hardware support
+
+% Framebuffer support
+! [(PLATFORM=mips32&MACHINE=lgxemul)|(PLATFORM=mips32&MACHINE=bgxemul)|(PLATFORM=ia32)|(PLATFORM=amd64)|(PLATFORM=arm32)] CONFIG_FB (y/n)
+
+% Framebuffer width
+@ "640"
+@ "800"
+@ "1024"
+@ "1152"
+@ "1280"
+@ "1400"
+@ "1440"
+@ "1600"
+@ "2048"
+! [(PLATFORM=ia32|PLATFORM=amd64)&CONFIG_FB=y] CONFIG_VESA_WIDTH (choice)
+
+% Framebuffer height
+@ "480"
+@ "600"
+@ "768"
+@ "852"
+@ "900"
+@ "960"
+@ "1024"
+@ "1050"
+@ "1200"
+@ "1536"
+! [(PLATFORM=ia32|PLATFORM=amd64)&CONFIG_FB=y] CONFIG_VESA_HEIGHT (choice)
+
+% Framebuffer depth
+@ "8"
+@ "16"
+@ "24"
+! [(PLATFORM=ia32|PLATFORM=amd64)&CONFIG_FB=y] CONFIG_VESA_BPP (choice)
+
+% Start AP processors by the loader
+! [PLATFORM=sparc64] CONFIG_SMP (y/n)
+
+% Use Block Address Translation by the loader
+! [PLATFORM=ppc32] CONFIG_BAT (y/n)
+
+% Preserve A.OUT header in isofs.b
+! [PLATFORM=sparc64] CONFIG_AOUT_ISOFS_B (y/n)
+
+% External ramdisk
+! [PLATFORM=sparc64] CONFIG_RD_EXTERNAL (y/n)
Index: Makefile
===================================================================
--- Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -37,5 +37,4 @@
 ifeq ($(PLATFORM),amd64)
 	KARCH = amd64
-	MACHINE = opteron
 	UARCH = amd64
 	BARCH = amd64
@@ -112,33 +111,22 @@
 
 all:
-	tools/config.py HelenOS.config default $(PLATFORM) $(COMPILER) $(CONFIG_DEBUG)
+	tools/config.py HelenOS.config default
 	$(MAKE) -C . build
 
-build:
-ifneq ($(MACHINE),)
-	$(MAKE) -C kernel ARCH=$(KARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG) MACHINE=$(MACHINE)
-else
-	$(MAKE) -C kernel ARCH=$(KARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG)
-endif
-	$(MAKE) -C uspace ARCH=$(UARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG)
-ifneq ($(IMAGE),)
-	$(MAKE) -C boot ARCH=$(BARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG) IMAGE=$(IMAGE)
-else
-	$(MAKE) -C boot ARCH=$(BARCH) COMPILER=$(COMPILER) CONFIG_DEBUG=$(CONFIG_DEBUG)
-endif
+build: Makefile.config
+	$(MAKE) -C kernel ARCH=$(KARCH)
+	$(MAKE) -C uspace ARCH=$(UARCH)
+	$(MAKE) -C boot ARCH=$(BARCH) IMAGE=$(IMAGE)
 
-config:
+config: HelenOS.config
 	tools/config.py HelenOS.config
 
-distclean:
-	-$(MAKE) -C kernel distclean
-	-$(MAKE) -C uspace distclean
-	-$(MAKE) -C boot distclean
+distclean: clean
 	rm -f Makefile.config tools/*.pyc
 
 clean:
-	-$(MAKE) -C kernel clean
-	-$(MAKE) -C uspace clean
-	-$(MAKE) -C boot clean
+	-$(MAKE) -C kernel clean ARCH=$(KARCH)
+	-$(MAKE) -C uspace clean ARCH=$(UARCH)
+	-$(MAKE) -C boot clean ARCH=$(BARCH) IMAGE=$(IMAGE)
 
 cscope:
Index: boot/Makefile
===================================================================
--- boot/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ boot/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
--include Makefile.config
+-include ../Makefile.config
 
 ## Paths
@@ -51,18 +51,10 @@
 endif
 
-.PHONY: all build config distclean clean generic_clean
+.PHONY: all build clean generic_clean
 
-all:
-	../tools/config.py boot.config default $(ARCH) $(COMPILER) $(CONFIG_DEBUG) $(IMAGE)
-	$(MAKE) -C . build
+all: ../Makefile.config build
 
 -include arch/$(ARCH)/Makefile.inc
 
-config:
-	../tools/config.py boot.config
-
-distclean: clean
-	-rm Makefile.config
-
 generic_clean:
 	-rm generic/*.o genarch/*.o
Index: boot/arch/arm32/loader/Makefile
===================================================================
--- boot/arch/arm32/loader/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ boot/arch/arm32/loader/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -28,5 +28,5 @@
 
 include ../../../../version
-include ../../../Makefile.config
+include ../../../../Makefile.config
 
 ## Toolchain configuration
Index: boot/arch/ia64/loader/Makefile
===================================================================
--- boot/arch/ia64/loader/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ boot/arch/ia64/loader/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -28,5 +28,5 @@
 
 include ../../../../version
-include ../../../Makefile.config
+include ../../../../Makefile.config
 
 ## Toolchain configuration
Index: boot/arch/mips32/loader/Makefile
===================================================================
--- boot/arch/mips32/loader/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ boot/arch/mips32/loader/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -28,5 +28,5 @@
 
 include ../../../../version
-include ../../../Makefile.config
+include ../../../../Makefile.config
 
 ## Toolchain configuration
Index: boot/arch/ppc32/loader/Makefile
===================================================================
--- boot/arch/ppc32/loader/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ boot/arch/ppc32/loader/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -28,5 +28,5 @@
 
 include ../../../../version
-include ../../../Makefile.config
+include ../../../../Makefile.config
 
 ## Toolchain configuration
Index: boot/arch/ppc64/loader/Makefile
===================================================================
--- boot/arch/ppc64/loader/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ boot/arch/ppc64/loader/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -28,5 +28,5 @@
 
 include ../../../../version
-include ../../../Makefile.config
+include ../../../../Makefile.config
 
 ## Toolchain configuration
Index: boot/arch/sparc64/loader/Makefile
===================================================================
--- boot/arch/sparc64/loader/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ boot/arch/sparc64/loader/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -28,5 +28,5 @@
 
 include ../../../../version
-include ../../../Makefile.config
+include ../../../../Makefile.config
 
 ## Toolchain configuration
Index: ot/boot.config
===================================================================
--- boot/boot.config	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ 	(revision )
@@ -1,90 +1,0 @@
-#
-# Copyright (c) 2006 Ondrej Palkovsky 
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-## General configuration directives
-
-# Architecture
-@ "amd64" AMD64/Intel EM64T
-@ "arm32" ARM 32-bit
-@ "ia32" Intel IA-32
-@ "ia32xen" Intel IA-32 on Xen hypervisor
-@ "ia64" Intel IA-64
-@ "mips32" MIPS 32-bit
-@ "ppc32" PowerPC 32-bit
-@ "ppc64" PowerPC 64-bit
-@ "sparc64" Sun UltraSPARC
-! ARCH (choice)
-
-# Compiler                                                                                                        
-@ "gcc_cross" GCC Cross-compiler                                                                                  
-@ "gcc_native" GCC Native                                                                                         
-@ "icc_native" ICC Native                                                                                         
-@ "suncc_native" Sun Studio C Compiler                                                                             
-! [ARCH=amd64|ARCH=ia32|ARCH=ia32xen] COMPILER (choice)                                               
-                                                                                                                  
-# Compiler                                                                                                        
-@ "gcc_cross" GCC Cross-compiler                                                                                  
-@ "gcc_native" GCC Native                                                                                         
-@ "icc_native" ICC Native                                                                                         
-! [ARCH=ia64] COMPILER (choice)                                                                               
-                                                                                                                  
-# Compiler                                                                                                        
-@ "gcc_cross" GCC Cross-compiler                                                                                  
-@ "gcc_native" GCC Native                                                                                         
-@ "suncc_native" Sun Studio C Compiler                                                                             
-! [ARCH=sparc64] COMPILER (choice)                                                                            
-                                                                                                                  
-# Compiler                                                                                                        
-@ "gcc_cross" GCC Cross-compiler                                                                                  
-@ "gcc_native" GCC Native                                                                                         
-! [ARCH=arm32|ARCH=mips32|ARCH=ppc32|ARCH=ppc64] COMPILER (choice)
-
-# Start AP processors by the loader
-! [ARCH=sparc64] CONFIG_SMP (y/n)
-
-# Debug bootloader
-! [ARCH=ppc32] CONFIG_DEBUG (n/y)
-
-# Use Block Address Translation
-! [ARCH=ppc32] CONFIG_BAT (y/n)
-
-# Target image
-@ "binary" Binary image (MSIM)
-@ "ecoff" Ecoff image (GXEmul)
-! [ARCH=mips32] IMAGE (choice)
-
-# Ramdisk format
-@ "tmpfs" TMPFS image
-@ "fat" FAT16 image
-! RDFMT (choice)
-
-# Preserve A.OUT header in isofs.b
-! [ARCH=sparc64] CONFIG_AOUT_ISOFS_B (y/n)
-
-# External ramdisk 
-! [ARCH=sparc64] CONFIG_RD_EXTERNAL (y/n)
Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ kernel/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -31,6 +31,6 @@
 #
 
--include ../version
--include Makefile.config
+include ../version
+-include ../Makefile.config
 
 INCLUDES = generic/include
@@ -360,20 +360,13 @@
 GENARCH_OBJECTS := $(addsuffix .o,$(basename $(GENARCH_SOURCES)))
 
-.PHONY: all build config distclean clean archlinks depend disasm
-
-all:
-	../tools/config.py kernel.config default $(ARCH) $(COMPILER) $(CONFIG_DEBUG) $(MACHINE)
+.PHONY: all build clean archlinks depend disasm
+
+all: ../Makefile.config
+	-rm Makefile.depend
 	$(MAKE) -C . build
 
 build: kernel.bin disasm
 
-config:
-	-rm Makefile.depend
-	../tools/config.py kernel.config
-
 -include Makefile.depend
-
-distclean: clean
-	-rm Makefile.config
 
 clean:
Index: rnel/kernel.config
===================================================================
--- kernel/kernel.config	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ 	(revision )
@@ -1,191 +1,0 @@
-#
-# Copyright (c) 2006 Ondrej Palkovsky 
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-## General configuration directives
-
-# Architecture
-@ "amd64" AMD64/Intel EM64T
-@ "arm32" ARM 32-bit
-@ "ia32" Intel IA-32
-@ "ia32xen" Intel IA-32 on Xen hypervisor
-@ "ia64" Intel IA-64
-@ "mips32" MIPS 32-bit
-@ "ppc32" PowerPC 32-bit
-@ "ppc64" PowerPC 64-bit
-@ "sparc64" Sun UltraSPARC 64-bit
-! ARCH (choice)
-
-# Compiler
-@ "gcc_cross" GCC Cross-compiler
-@ "gcc_native" GCC Native
-@ "icc_native" ICC Native
-@ "suncc_native" Sun Studio C Compiler
-! [ARCH=amd64|ARCH=ia32|ARCH=ia32xen] COMPILER (choice)
-
-# Compiler
-@ "gcc_cross" GCC Cross-compiler
-@ "gcc_native" GCC Native
-@ "icc_native" ICC Native
-! [ARCH=ia64] COMPILER (choice)
-
-# Compiler
-@ "gcc_cross" GCC Cross-compiler
-@ "gcc_native" GCC Native
-@ "suncc_native" Sun Studio C Compiler
-! [ARCH=sparc64] COMPILER (choice)
-
-# Compiler
-@ "gcc_cross" GCC Cross-compiler
-@ "gcc_native" GCC Native
-! [ARCH=arm32|ARCH=mips32|ARCH=ppc32|ARCH=ppc64] COMPILER (choice)
-
-# CPU type
-@ "pentium4" Pentium 4
-@ "pentium3" Pentium 3
-@ "core" Core Solo/Duo
-@ "athlon-xp" Athlon XP
-@ "athlon-mp" Athlon MP
-! [ARCH=ia32|ARCH=ia32xen] MACHINE (choice)
-
-# CPU type
-@ "opteron" Opteron
-! [ARCH=amd64] MACHINE (choice)
-
-# CPU type
-@ "us" UltraSPARC I-II subarchitecture
-@ "us3" UltraSPARC III-IV subarchitecture
-! [ARCH=sparc64] MACHINE (choice)
-
-# Machine type
-@ "msim" MSIM Simulator
-@ "simics" Virtutech Simics simulator
-@ "lgxemul" GXEmul Little Endian
-@ "bgxemul" GXEmul Big Endian
-! [ARCH=mips32] MACHINE (choice)
-
-# Framebuffer support
-! [(ARCH=mips32&MACHINE=lgxemul)|(ARCH=mips32&MACHINE=bgxemul)|(ARCH=ia32)|(ARCH=amd64)|(ARCH=arm32)] CONFIG_FB (y/n)
-
-# Framebuffer width
-@ "640"
-@ "800"
-@ "1024"
-@ "1152"
-@ "1280"
-@ "1400"
-@ "1440"
-@ "1600"
-@ "2048"
-! [(ARCH=ia32|ARCH=amd64)&CONFIG_FB=y] CONFIG_VESA_WIDTH (choice)
-
-# Framebuffer height
-@ "480"
-@ "600"
-@ "768"
-@ "852"
-@ "900"
-@ "960"
-@ "1024"
-@ "1050"
-@ "1200"
-@ "1536"
-! [(ARCH=ia32|ARCH=amd64)&CONFIG_FB=y] CONFIG_VESA_HEIGHT (choice)
-
-# Framebuffer depth
-@ "8"
-@ "16"
-@ "24"
-! [(ARCH=ia32|ARCH=amd64)&CONFIG_FB=y] CONFIG_VESA_BPP (choice)
-
-# Support for SMP
-! [ARCH=ia32|ARCH=amd64|ARCH=ia32xen|ARCH=sparc64|ARCH=ia64] CONFIG_SMP (y/n)
-
-# Improved support for hyperthreading
-! [(ARCH=ia32|ARCH=amd64|ARCH=ia32xen)&CONFIG_SMP=y] CONFIG_HT (y/n)
-
-# Simics BIOS AP boot fix
-! [(ARCH=ia32|ARCH=amd64)&CONFIG_SMP=y] CONFIG_SIMICS_FIX (y/n)
-
-# Lazy FPU context switching
-! [(ARCH=mips32&MACHINE!=msim&MACHINE!=simics)|ARCH=amd64|ARCH=ia32|ARCH=ia64|ARCH=sparc64|ARCH=ia32xen] CONFIG_FPU_LAZY (y/n)
-
-# Use VHPT
-! [ARCH=ia64] CONFIG_VHPT (n/y)
-
-# Use TSB
-! [ARCH=sparc64] CONFIG_TSB (y/n)
-
-# Support for Z8530 serial port
-! [ARCH=sparc64] CONFIG_Z8530 (y/n)
-
-# Support for NS16550 serial port
-! [ARCH=sparc64|(ARCH=ia64&MACHINE!=ski)] CONFIG_NS16550 (n/y)
-
-# Support for Serengeti console
-! [ARCH=sparc64] CONFIG_SGCN (y/n)
-
-# IOSapic on default address support
-! [ARCH=ia64&MACHINE!=ski] CONFIG_IOSAPIC (y/n)
-
-# Interrupt-driven driver for Legacy Keyboard?
-! [CONFIG_NS16550=n&CONFIG_IOSAPIC=y&MACHINE!=ski] CONFIG_I8042_INTERRUPT_DRIVEN (y/n)
-
-# Interrupt-driven driver for NS16550?
-! [CONFIG_NS16550=y&((ARCH!=ia64)|CONFIG_IOSAPIC=y)&MACHINE!=ski] CONFIG_NS16550_INTERRUPT_DRIVEN (y/n)
-
-# Virtually indexed D-cache support
-! [ARCH=sparc64] CONFIG_VIRT_IDX_DCACHE (y/n)
-
-# Support for userspace debuggers
-! CONFIG_UDEBUG (n/y)
-
-## Debugging configuration directives
-
-# General debugging and assert checking
-! CONFIG_DEBUG (y/n)
-
-# Kernel console support
-! CONFIG_KCONSOLE (y/n)
-
-# Detailed kernel logging
-! CONFIG_LOG (n/y)
-
-# Deadlock detection support for spinlocks
-! [CONFIG_DEBUG=y&CONFIG_SMP=y] CONFIG_DEBUG_SPINLOCK (y/n)
-
-# Watchpoint on rewriting AS with zero
-! [CONFIG_DEBUG=y&(ARCH=amd64|ARCH=ia32|ARCH=ia32xen)] CONFIG_DEBUG_AS_WATCHPOINT (y/n)
-
-# Save all interrupt registers
-! [CONFIG_DEBUG=y&(ARCH=amd64|ARCH=mips32|ARCH=ia32|ARCH=ia32xen)] CONFIG_DEBUG_ALLREGS (y/n)
-
-
-## Run-time configuration directives
-
-# Compile kernel tests
-! CONFIG_TEST (y/n)
Index: tools/config.py
===================================================================
--- tools/config.py	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ tools/config.py	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -2,4 +2,5 @@
 #
 # Copyright (c) 2006 Ondrej Palkovsky
+# Copyright (c) 2009 Martin Decky
 # All rights reserved.
 #
@@ -28,5 +29,5 @@
 #
 """
-HelenOS configuration script
+HelenOS configuration system
 """
 import sys
@@ -34,505 +35,319 @@
 import re
 import commands
+import snack
 
 INPUT = sys.argv[1]
 OUTPUT = 'Makefile.config'
-TMPOUTPUT = 'Makefile.config.tmp'
-
-class DefaultDialog:
-    "Wrapper dialog that tries to return default values"
-    def __init__(self, dlg):
-        self.dlg = dlg
-
-    def set_title(self,text):
-        self.dlg.set_title(text)
-        
-    def yesno(self, text, default=None):
-        if default is not None:
-            return default
-        return self.dlg.yesno(text, default)
-    def noyes(self, text, default=None):
-        if default is not None:
-            return default
-        return self.dlg.noyes(text, default)
-    
-    def choice(self, text, choices, defopt=None):
-        if defopt is not None:
-            return choices[defopt][0]
-        return self.dlg.choice(text, choices, defopt)
-
-class NoDialog:
-    def __init__(self):
-        self.printed = None
-        self.title = 'HelenOS Configuration'
-
-    def print_title(self):
-        if not self.printed:
-            sys.stdout.write("\n*** %s ***\n" % self.title)
-            self.printed = True
-
-    def set_title(self, text):
-        self.title = text
-        self.printed = False
-    
-    def noyes(self, text, default=None):
-        if not default:
-            default = 'n'
-        return self.yesno(text, default)
-    
-    def yesno(self, text, default=None):
-        self.print_title()
-        
-        if default != 'n':
-            default = 'y'
-        while 1:
-            sys.stdout.write("%s (y/n)[%s]: " % (text,default))
-            inp = sys.stdin.readline()
-            if not inp:
-                raise EOFError
-            inp = inp.strip().lower()
-            if not inp:
-                return default
-            if inp == 'y':
-                return 'y'
-            elif inp == 'n':
-                return 'n'
-
-    def _print_choice(self, text, choices, defopt):
-        sys.stdout.write('%s:\n' % text)
-        for i,(text,descr) in enumerate(choices):
-            if descr is '':
-                sys.stdout.write('\t%2d. %s\n' % (i, text))
-            else:
-                sys.stdout.write('\t%2d. %s\n' % (i, descr))
-        if defopt is not None:
-            sys.stdout.write('Enter choice number[%d]: ' % defopt)
-        else:
-            sys.stdout.write('Enter choice number: ')
-
-    def menu(self, text, choices, button, defopt=None):
-        self.title = 'Main menu'
-        menu = []
-        for key, descr in choices:
-            txt = key + (45-len(key))*' ' + ': ' + descr
-            menu.append((key, txt))
-            
-        return self.choice(text, [button] + menu)
-        
-    def choice(self, text, choices, defopt=None):
-        self.print_title()
-        while 1:
-            self._print_choice(text, choices, defopt)
-            inp = sys.stdin.readline()
-            if not inp:
-                raise EOFError
-            if not inp.strip():
-                if defopt is not None:
-                    return choices[defopt][0]
-                continue
-            try:
-                number = int(inp.strip())
-            except ValueError:
-                continue
-            if number < 0 or number >= len(choices):
-                continue
-            return choices[number][0]
-
-
-def eof_checker(fnc):
-    def wrapper(self, *args, **kw):
-        try:
-            return fnc(self, *args, **kw)
-        except EOFError:
-            return getattr(self.bckdialog,fnc.func_name)(*args, **kw)
-    return wrapper
-
-class Dialog(NoDialog):
-    def __init__(self):
-        NoDialog.__init__(self)
-        self.dlgcmd = os.environ.get('DIALOG','dialog')
-        self.title = ''
-        self.backtitle = 'HelenOS Configuration'
-        
-        if os.system('%s --print-maxsize >/dev/null 2>&1' % self.dlgcmd) != 0:
-            raise NotImplementedError
-        
-        self.bckdialog = NoDialog()
-
-    def set_title(self,text):
-        self.title = text
-        self.bckdialog.set_title(text)
-        
-    def calldlg(self,*args,**kw):
-        "Wrapper for calling 'dialog' program"
-        indesc, outdesc = os.pipe()
-        pid = os.fork()
-        if not pid:
-            os.close(2)
-            os.dup(outdesc)
-            os.close(indesc)
-            
-            dlgargs = [self.dlgcmd,'--title',self.title,
-                       '--backtitle', self.backtitle]
-            for key,val in kw.items():
-                dlgargs.append('--'+key)
-                dlgargs.append(val)
-            dlgargs += args            
-            os.execlp(self.dlgcmd,*dlgargs)
-
-        os.close(outdesc)
-        
-        try:
-            errout = os.fdopen(indesc,'r')
-            data = errout.read()
-            errout.close()
-            pid,status = os.wait()
-        except:
-            os.system('reset') # Reset terminal
-            raise
-        
-        if not os.WIFEXITED(status):
-            os.system('reset') # Reset terminal
-            raise EOFError
-        
-        status = os.WEXITSTATUS(status)
-        if status == 255:
-            raise EOFError
-        return status,data
-        
-    def yesno(self, text, default=None):
-        if text[-1] not in ('?',':'):
-            text = text + ':'
-        width = '50'
-        height = '5'
-        if len(text) < 48:
-            text = ' '*int(((48-len(text))/2)) + text
-        else:
-            width = '0'
-            height = '0'
-        if default == 'n':
-            res,data = self.calldlg('--defaultno','--yesno',text,height,width)
-        else:
-            res,data = self.calldlg('--yesno',text,height,width)
-
-        if res == 0:
-            return 'y'
-        return 'n'
-    yesno = eof_checker(yesno)
-
-    def menu(self, text, choices, button, defopt=None):
-        self.title = 'Main menu'
-        text = text + ':'
-        width = '70'
-        height = str(8 + len(choices))
-        args = []
-        for key,val in choices:
-            args.append(key)
-            args.append(val)
-
-        kw = {}
-        if defopt:
-            kw['default-item'] = choices[defopt][0] 
-        res,data = self.calldlg('--ok-label','Change',
-                                '--extra-label',button[1],
-                                '--extra-button',
-                                '--menu',text,height,width,
-                                str(len(choices)),*args,**kw)
-        if res == 3:
-            return button[0]
-        if res == 1: # Cancel
-            sys.exit(1)
-        elif res:
-            print data
-            raise EOFError
-        return data
-    menu = eof_checker(menu)
-    
-    def choice(self, text, choices, defopt=None):
-        text = text + ':'
-        width = '50'
-        height = str(8 + len(choices))
-        args = []
-        for key,val in choices:
-            args.append(key)
-            args.append(val)
-
-        kw = {}
-        if defopt:
-            kw['default-item'] = choices[defopt][0] 
-        res,data = self.calldlg('--nocancel','--menu',text,height,width,
-                                str(len(choices)),*args, **kw)
-        if res:
-            print data
-            raise EOFError
-        return data
-    choice = eof_checker(choice)
-    
-def read_defaults(fname,defaults):
-    "Read saved values from last configuration run"
-    f = file(fname,'r')
-    for line in f:
-        res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
-        if res:
-            defaults[res.group(1)] = res.group(2)
-    f.close()
-
-def check_condition(text, defaults, asked_names):
-    seen_vars = [ x[0] for x in asked_names ]
-    ctype = 'cnf'
-    if ')|' in text or '|(' in text:
-        ctype = 'dnf'
-    
-    if ctype == 'cnf':
-        conds = text.split('&')
-    else:
-        conds = text.split('|')
-
-    for cond in conds:
-        if cond.startswith('(') and cond.endswith(')'):
-            cond = cond[1:-1]
-            
-        inside = check_inside(cond, defaults, ctype, seen_vars)
-        
-        if ctype == 'cnf' and not inside:
-            return False
-        if ctype == 'dnf' and inside:
-            return True
-
-    if ctype == 'cnf':
-        return True
-    return False
-
-def check_inside(text, defaults, ctype, seen_vars):
-    """
-    Check that the condition specified on input line is True
-
-    only CNF is supported
-    """
-    if ctype == 'cnf':
-        conds = text.split('|')
-    else:
-        conds = text.split('&')
-    for cond in conds:
-        res = re.match(r'^(.*?)(!?=)(.*)$', cond)
-        if not res:
-            raise RuntimeError("Invalid condition: %s" % cond)
-        condname = res.group(1)
-        oper = res.group(2)
-        condval = res.group(3)
-        if condname not in seen_vars:
-            varval = ''
-##             raise RuntimeError("Variable %s not defined before being asked." %\
-##                                condname)
-        elif not defaults.has_key(condname):
-            raise RuntimeError("Condition var %s does not exist: %s" % \
-                               (condname,text))
-        else:
-            varval = defaults[condname]
-        if ctype == 'cnf':
-            if oper == '=' and  condval == varval:
-                return True
-            if oper == '!=' and condval != varval:
-                return True
-        else:
-            if oper== '=' and condval != varval:
-                return False
-            if oper== '!=' and condval == varval:
-                return False
-    if ctype=='cnf':
-        return False
-    return True
-
-def parse_config(input, output, dlg, defaults={}, askonly=None):
-    "Parse configuration file and create Makefile.config on the fly"
-    def ask_the_question(dialog):
-        "Ask question based on the type of variables to ask"
-        # This is quite a hack, this thingy is written just to
-        # have access to local variables..
-        if vartype == 'y/n':
-            return dialog.yesno(comment, default)
-        elif vartype == 'n/y':
-            return dialog.noyes(comment, default)
-        elif vartype == 'choice':
-            defopt = None
-            if default is not None:
-                for i,(key,val) in enumerate(choices):
-                    if key == default:
-                        defopt = i
-                        break
-            return dialog.choice(comment, choices, defopt)
-        else:
-            raise RuntimeError("Bad method: %s" % vartype)
-
-    
-    f = file(input, 'r')
-    outf = file(output, 'w')
-
-    outf.write('#########################################\n')
-    outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
-    outf.write('#########################################\n\n')
-
-    asked_names = []
-
-    comment = ''
-    default = None
-    choices = []
-    for line in f:
-        if line.startswith('%'):
-            res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line)
-            if not res:
-                raise RuntimeError('Invalid command: %s' % line)
-            if res.group(1):
-                if not check_condition(res.group(1), defaults,
-                                       asked_names):
-                    continue
-            args = res.group(2).strip().split(' ')
-            cmd = args[0].lower()
-            args = args[1:]
-            if cmd == 'saveas':
-                outf.write('%s = %s\n' % (args[1],defaults[args[0]]))
-            elif cmd == 'shellcmd':
-                varname = args[0]
-                args = args[1:]
-                for i,arg in enumerate(args):
-                    if arg.startswith('$'):
-                        args[i] = defaults[arg[1:]]
-                data,status = commands.getstatusoutput(' '.join(args))
-                if status:
-                    raise RuntimeError('Error running: %s' % ' '.join(args))
-                outf.write('%s = %s\n' % (varname,data.strip()))
-            continue
-            
-        if line.startswith('!'):
-            # Ask a question
-            res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line)
-            if not res:
-                raise RuntimeError("Weird line: %s" % line)
-            varname = res.group(2)
-            vartype = res.group(3)
-
-            default = defaults.get(varname,None)
-            
-            if res.group(1):
-                if not check_condition(res.group(1), defaults,
-                                       asked_names):
-                    if default is not None:
-                        outf.write('#!# %s = %s\n' % (varname, default))
-                    # Clear cumulated values
-                    comment = ''
-                    default = None
-                    choices = []
-                    continue
-                
-            asked_names.append((varname,comment))
-
-            if default is None or not askonly or askonly == varname:
-                default = ask_the_question(dlg)
-            else:
-                default = ask_the_question(DefaultDialog(dlg))
-
-            outf.write('%s = %s\n' % (varname, default))
-            # Remeber the selected value
-            defaults[varname] = default
-            # Clear cumulated values
-            comment = ''
-            default = None
-            choices = []
-            continue
-        
-        if line.startswith('@'):
-            # Add new line into the 'choice array' 
-            res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
-            if not res:
-                raise RuntimeError("Bad line: %s" % line)
-            if res.group(1):
-                if not check_condition(res.group(1),defaults,
-                                       asked_names):
-                    continue
-            choices.append((res.group(2), res.group(3)))
-            continue
-
-        # All other things print to output file
-        outf.write(line)
-        if re.match(r'^#[^#]', line):
-            # Last comment before question will be displayed to the user
-            comment = line[1:].strip()
-        elif line.startswith('## '):
-            # Set title of the dialog window
-            dlg.set_title(line[2:].strip())
-
-    outf.write('\n')
-    outf.write('REVISION = %s\n' % commands.getoutput('svnversion . 2> /dev/null'))
-    outf.write('TIMESTAMP = %s\n' % commands.getoutput('date "+%Y-%m-%d %H:%M:%S"'))
-    outf.close()
-    f.close()
-    return asked_names
+
+def read_defaults(fname, defaults):
+	"Read saved values from last configuration run"
+	
+	inf = file(fname,'r')
+	
+	for line in inf:
+		res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
+		if (res):
+			defaults[res.group(1)] = res.group(2)
+	
+	inf.close()
+
+def check_condition(text, defaults, ask_names):
+	"Check for condition"
+	
+	ctype = 'cnf'
+	
+	if ((')|' in text) or ('|(' in text)):
+		ctype = 'dnf'
+	
+	if (ctype == 'cnf'):
+		conds = text.split('&')
+	else:
+		conds = text.split('|')
+	
+	for cond in conds:
+		if (cond.startswith('(')) and (cond.endswith(')')):
+			cond = cond[1:-1]
+		
+		inside = check_inside(cond, defaults, ctype)
+		
+		if (ctype == 'cnf') and (not inside):
+			return False
+		
+		if (ctype == 'dnf') and (inside):
+			return True
+	
+	if (ctype == 'cnf'):
+		return True
+	return False
+
+def check_inside(text, defaults, ctype):
+	"Check that the condition specified on input line is True (only CNF is supported)"
+	
+	if (ctype == 'cnf'):
+		conds = text.split('|')
+	else:
+		conds = text.split('&')
+	
+	for cond in conds:
+		res = re.match(r'^(.*?)(!?=)(.*)$', cond)
+		if (not res):
+			raise RuntimeError("Invalid condition: %s" % cond)
+		
+		condname = res.group(1)
+		oper = res.group(2)
+		condval = res.group(3)
+		
+		if (not defaults.has_key(condname)):
+			varval = ''
+		else:
+			varval = defaults[condname]
+		
+		if (ctype == 'cnf'):
+			if (oper == '=') and (condval == varval):
+				return True
+		
+			if (oper == '!=') and (condval != varval):
+				return True
+		else:
+			if (oper == '=') and (condval != varval):
+				return False
+			
+			if (oper == '!=') and (condval == varval):
+				return False
+	
+	if (ctype == 'cnf'):
+		return False
+	
+	return True
+
+def parse_config(fname, ask_names):
+	"Parse configuration file"
+	
+	inf = file(fname, 'r')
+	
+	name = ''
+	choices = []
+	
+	for line in inf:
+		
+		if (line.startswith('!')):
+			# Ask a question
+			res = re.search(r'!\s*(?:\[(.*?)\])?\s*([^\s]+)\s*\((.*)\)\s*$', line)
+			
+			if (not res):
+				raise RuntimeError("Weird line: %s" % line)
+			
+			cond = res.group(1)
+			varname = res.group(2)
+			vartype = res.group(3)
+			
+			ask_names.append((varname, vartype, name, choices, cond))
+			name = ''
+			choices = []
+			continue
+		
+		if (line.startswith('@')):
+			# Add new line into the 'choices' array
+			res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
+			
+			if not res:
+				raise RuntimeError("Bad line: %s" % line)
+			
+			choices.append((res.group(2), res.group(3)))
+			continue
+		
+		if (line.startswith('%')):
+			# Name of the option
+			name = line[1:].strip()
+			continue
+		
+		if ((line.startswith('#')) or (line == '\n')):
+			# Comment or empty line
+			continue
+		
+		
+		raise RuntimeError("Unknown syntax: %s" % line)
+	
+	inf.close()
+
+def yes_no(default):
+	"Return '*' if yes, ' ' if no"
+	
+	if (default == 'y'):
+		return '*'
+	
+	return ' '
+
+def subchoice(screen, name, choices):
+	"Return choice of choices"
+	
+	maxlen = 0
+	for choice in choices:
+		length = len(choice[0])
+		if (length > maxlen):
+			maxlen = length
+	
+	options = []
+	for choice in choices:
+		options.append(" %-*s  %s " % (maxlen, choice[0], choice[1]))
+	
+	retval = snack.ListboxChoiceWindow(screen, name, 'Choose value', options)
+	
+	if (retval[0] == 'cancel'):
+		return None
+	
+	return choices[retval[1]][0]
+
+def check_choices(defaults, ask_names):
+	"Check whether all accessible variables have a default"
+	
+	for row in ask_names:
+		varname = row[0]
+		cond = row[4]
+		
+		if ((cond) and (not check_condition(cond, defaults, ask_names))):
+			continue
+		
+		if (not defaults.has_key(varname)):
+			return False
+	
+	return True
+
+def create_output(fname, defaults, ask_names):
+	"Create output configuration"
+	
+	outf = file(fname, 'w')
+	
+	outf.write('#########################################\n')
+	outf.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
+	outf.write('#########################################\n\n')
+	
+	for row in ask_names:
+		varname = row[0]
+		name = row[2]
+		cond = row[4]
+		
+		if ((cond) and (not check_condition(cond, defaults, ask_names))):
+			continue
+		
+		if (not defaults.has_key(varname)):
+			default = ''
+		else:
+			default = defaults[varname]
+		
+		outf.write('# %s\n%s = %s\n\n' % (name, varname, default))
+	
+	outf.write('REVISION = %s\n' % commands.getoutput('svnversion . 2> /dev/null'))
+	outf.write('TIMESTAMP = %s\n' % commands.getoutput('date "+%Y-%m-%d %H:%M:%S"'))
+	outf.close()
 
 def main():
-    defaults = {}
-    try:
-        dlg = Dialog()
-    except NotImplementedError:
-        dlg = NoDialog()
-
-    if len(sys.argv) >= 3 and sys.argv[2]=='default':
-        defmode = True
-    else:
-        defmode = False
-
-    # Default run will update the configuration file
-    # with newest options
-    if os.path.exists(OUTPUT):
-        read_defaults(OUTPUT, defaults)
-
-	# Get ARCH from command line if specified
-    if len(sys.argv) >= 4:
-        defaults['ARCH'] = sys.argv[3]
-        defaults['PLATFORM'] = sys.argv[3]
-	
-	# Get COMPILER from command line if specified
-    if len(sys.argv) >= 5:
-        defaults['COMPILER'] = sys.argv[4]
-	
-	# Get CONFIG_DEBUG from command line if specified
-    if len(sys.argv) >= 6:
-        defaults['CONFIG_DEBUG'] = sys.argv[5]
-	
-	# Get MACHINE/IMAGE from command line if specified
-    if len(sys.argv) >= 7:
-        defaults['MACHINE'] = sys.argv[6]
-        defaults['IMAGE'] = sys.argv[6]
-
-    # Dry run only with defaults
-    varnames = parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
-    # If not in default mode, present selection of all possibilities
-    if not defmode:
-        defopt = 0
-        while 1:
-            # varnames contains variable names that were in the
-            # last question set
-            choices = [ (x[1],defaults[x[0]]) for x in varnames ]
-            res = dlg.menu('Configuration',choices,('save','Save'),defopt)
-            if res == 'save':
-                parse_config(INPUT, TMPOUTPUT, DefaultDialog(dlg), defaults)
-                break
-            # transfer description back to varname
-            for i,(vname,descr) in enumerate(varnames):
-                if res == descr:
-                    defopt = i
-                    break
-            # Ask the user a simple question, produce output
-            # as if the user answered all the other questions
-            # with default answer
-            varnames = parse_config(INPUT, TMPOUTPUT, dlg, defaults,
-                                    askonly=varnames[i][0])
-        
-    
-    if os.path.exists(OUTPUT):
-        os.unlink(OUTPUT)
-    os.rename(TMPOUTPUT, OUTPUT)
-    
-    if not defmode and dlg.yesno('Rebuild everything?') == 'y':
-        os.execlp('make','make','clean','build')
+	defaults = {}
+	ask_names = []
+	
+	# Parse configuration file
+	parse_config(INPUT, ask_names)
+	
+	# Read defaults from previous run
+	if os.path.exists(OUTPUT):
+		read_defaults(OUTPUT, defaults)
+	
+	# Default mode: only check defaults and regenerate configuration
+	if ((len(sys.argv) >= 3) and (sys.argv[2] == 'default')):
+		if (check_choices(defaults, ask_names)):
+			create_output(OUTPUT, defaults, ask_names)
+			return 0
+	
+	screen = snack.SnackScreen()
+	try:
+		selname = None
+		while True:
+			
+			options = []
+			opt2row = {}
+			position = None
+			cnt = 0
+			for row in ask_names:
+				
+				varname = row[0]
+				vartype = row[1]
+				name = row[2]
+				choices = row[3]
+				cond = row[4]
+				
+				if ((cond) and (not check_condition(cond, defaults, ask_names))):
+					continue
+				
+				if (varname == selname):
+					position = cnt
+				
+				if (not defaults.has_key(varname)):
+					default = None
+				else:
+					default = defaults[varname]
+				
+				if (vartype == 'choice'):
+					# Check if the default is an acceptable value
+					if ((default) and (not default in [choice[0] for choice in choices])):
+						default = None
+						defaults.pop(varname)
+					
+					# If there is just one option, use it
+					if (len(choices) == 1):
+						default = choices[0][0]
+						defaults[varname] = default
+					
+					options.append("     %s [%s] --> " % (name, default))
+				elif (vartype == 'y/n'):
+					if (default == None):
+						default = 'y'
+						defaults[varname] = default
+					options.append(" <%s> %s " % (yes_no(default), name))
+				elif (vartype == 'n/y'):
+					if (default == None):
+						default = 'n'
+						defaults[varname] = default
+					options.append(" <%s> %s " % (yes_no(default), name))
+				else:
+					raise RuntimeError("Unknown variable type: %s" % vartype)
+				
+				opt2row[cnt] = row
+				
+				cnt += 1
+			
+			retval = snack.ListboxChoiceWindow(screen, 'HelenOS configuration', 'Choose configuration option', options, default = position)
+			
+			if (retval[0] == 'cancel'):
+				return 'Configuration canceled'
+			
+			row = opt2row[retval[1]]
+			if (row == None):
+				raise RuntimeError("Error selecting value: %s" % retval[1])
+			
+			selname = row[0]
+			seltype = row[1]
+			name = row[2]
+			choices = row[3]
+			
+			if (retval[0] == 'ok'):
+				if (check_choices(defaults, ask_names)):
+					break
+				else:
+					snack.ButtonChoiceWindow(screen, 'Error', 'Some options have still undefined values.', ['Ok']);
+					continue
+			
+			if (seltype == 'choice'):
+				defaults[selname] = subchoice(screen, name, choices)
+			elif ((seltype == 'y/n') or (seltype == 'n/y')):
+				if (defaults[selname] == 'y'):
+					defaults[selname] = 'n'
+				else:
+					defaults[selname] = 'y'
+	finally:
+		screen.finish()
+	
+	create_output(OUTPUT, defaults, ask_names)
+	return 0
 
 if __name__ == '__main__':
-    main()
+    exit(main())
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
--include Makefile.config
+-include ../Makefile.config
 
 DIRS = \
@@ -74,19 +74,9 @@
 CLEANS := $(addsuffix .clean,$(DIRS))
 
-.PHONY: all config build $(BUILDS) $(CLEANS) clean distclean
+.PHONY: all $(BUILDS) $(CLEANS) clean
 
-all:
-	../tools/config.py uspace.config default $(ARCH) $(COMPILER) $(CONFIG_DEBUG)
-	$(MAKE) -C . build
-
-config:
-	../tools/config.py uspace.config
-
-build: $(BUILDS)
+all: ../Makefile.config $(BUILDS)
 
 clean: $(CLEANS)
-
-distclean: clean
-	-rm Makefile.config
 
 $(CLEANS):
Index: uspace/app/bdsh/Makefile
===================================================================
--- uspace/app/bdsh/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/app/bdsh/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -31,5 +31,5 @@
 
 include ../../../version
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/app/init/Makefile
===================================================================
--- uspace/app/init/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/app/init/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -28,5 +28,5 @@
 
 include ../../../version
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 ## Setup toolchain
Index: uspace/app/klog/Makefile
===================================================================
--- uspace/app/klog/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/app/klog/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/app/tester/Makefile
===================================================================
--- uspace/app/tester/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/app/tester/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/app/tetris/Makefile
===================================================================
--- uspace/app/tetris/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/app/tetris/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -1,3 +1,3 @@
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/app/trace/Makefile
===================================================================
--- uspace/app/trace/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/app/trace/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/lib/libblock/Makefile
===================================================================
--- uspace/lib/libblock/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/lib/libblock/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -31,5 +31,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../libc
Index: uspace/lib/libc/Makefile
===================================================================
--- uspace/lib/libc/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/lib/libc/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = $(shell pwd)
Index: uspace/lib/libc/Makefile.toolchain
===================================================================
--- uspace/lib/libc/Makefile.toolchain	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/lib/libc/Makefile.toolchain	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -31,10 +31,9 @@
 LFLAGS = -M -N $(SOFTINT_PREFIX)/libsoftint.a
 AFLAGS =
-#-Werror
 
 ## Setup platform configuration
 #
 
-include $(LIBC_PREFIX)/arch/$(ARCH)/Makefile.inc
+-include $(LIBC_PREFIX)/arch/$(ARCH)/Makefile.inc
 
 ## Simple detection of the host system
Index: uspace/lib/libc/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/mips32/Makefile.inc	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/lib/libc/arch/mips32/Makefile.inc	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -38,5 +38,5 @@
 CFLAGS += -mips3
 
--include ../../Makefile.config
+-include ../../../Makefile.config
 ifeq ($(CONFIG_MIPS_FPU),y)
 	CFLAGS += -DCONFIG_MIPS_FPU
Index: uspace/lib/libfs/Makefile
===================================================================
--- uspace/lib/libfs/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/lib/libfs/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -31,5 +31,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../libc
Index: uspace/lib/softfloat/Makefile
===================================================================
--- uspace/lib/softfloat/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/lib/softfloat/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../libc
Index: uspace/lib/softint/Makefile
===================================================================
--- uspace/lib/softint/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/lib/softint/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../libc
Index: uspace/srv/console/Makefile
===================================================================
--- uspace/srv/console/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/console/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/srv/devmap/Makefile
===================================================================
--- uspace/srv/devmap/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/devmap/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/srv/fb/Makefile
===================================================================
--- uspace/srv/fb/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/fb/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/srv/fs/fat/Makefile
===================================================================
--- uspace/srv/fs/fat/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/fs/fat/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../../Makefile.config
+-include ../../../../Makefile.config
 
 LIBC_PREFIX = ../../../lib/libc
Index: uspace/srv/fs/tmpfs/Makefile
===================================================================
--- uspace/srv/fs/tmpfs/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/fs/tmpfs/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../../Makefile.config
+-include ../../../../Makefile.config
 
 LIBC_PREFIX = ../../../lib/libc
Index: uspace/srv/kbd/Makefile
===================================================================
--- uspace/srv/kbd/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/kbd/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,10 +30,9 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
 SOFTINT_PREFIX = ../../lib/softint
-include $(LIBC_PREFIX)/Makefile.toolchain 
-include ../../../Makefile.config
+include $(LIBC_PREFIX)/Makefile.toolchain
 
 CFLAGS += -Iinclude -I../libadt/include
Index: uspace/srv/loader/Makefile
===================================================================
--- uspace/srv/loader/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/loader/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -28,5 +28,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 ## Setup toolchain
Index: uspace/srv/ns/Makefile
===================================================================
--- uspace/srv/ns/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/ns/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/srv/pci/Makefile
===================================================================
--- uspace/srv/pci/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/pci/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/srv/pci/libpci/Makefile
===================================================================
--- uspace/srv/pci/libpci/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/pci/libpci/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -4,5 +4,5 @@
 # Modified and ported to HelenOS by Jakub Jermar
 
-include ../../../Makefile.config
+-include ../../../../Makefile.config
 
 LIBC_PREFIX=$(shell cd ../../../lib/libc; pwd)
Index: uspace/srv/rd/Makefile
===================================================================
--- uspace/srv/rd/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/rd/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -30,5 +30,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: uspace/srv/vfs/Makefile
===================================================================
--- uspace/srv/vfs/Makefile	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ uspace/srv/vfs/Makefile	(revision 9a0367fa3b9a9c76101f2153a0f10900ea972c2b)
@@ -31,5 +31,5 @@
 #
 
-include ../../Makefile.config
+-include ../../../Makefile.config
 
 LIBC_PREFIX = ../../lib/libc
Index: pace/uspace.config
===================================================================
--- uspace/uspace.config	(revision b1747a566f73b656e2bbf679b8136ecb0a61b9b4)
+++ 	(revision )
@@ -1,68 +1,0 @@
-#
-# Copyright (c) 2006 Ondrej Palkovsky 
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-## General configuration directives
-
-# Architecture
-@ "amd64" AMD64/Intel EM64T
-@ "arm32" ARM 32-bit
-@ "ia32" Intel IA-32
-@ "ia64" Intel IA-64
-@ "mips32" MIPS 32-bit Little Endian
-@ "mips32eb" MIPS 32-bit Big Endian
-@ "ppc32" PowerPC 32-bit
-@ "ppc64" PowerPC 64-bit
-@ "sparc64" Sun UltraSPARC 64-bit
-! ARCH (choice)
-
-# Compiler                                                                                                        
-@ "gcc_cross" GCC Cross-compiler                                                                                  
-@ "gcc_native" GCC Native                                                                                         
-@ "icc_native" ICC Native                                                                                         
-@ "suncc_native" Sun Studio C Compiler                                                                             
-! [ARCH=amd64|ARCH=ia32] COMPILER (choice)                                               
-                                                                                                                  
-# Compiler                                                                                                        
-@ "gcc_cross" GCC Cross-compiler                                                                                  
-@ "gcc_native" GCC Native                                                                                         
-@ "icc_native" ICC Native                                                                                         
-! [ARCH=ia64] COMPILER (choice)                                                                               
-                                                                                                                  
-# Compiler                                                                                                        
-@ "gcc_cross" GCC Cross-compiler                                                                                  
-@ "gcc_native" GCC Native                                                                                         
-@ "suncc_native" Sun Studio C Compiler                                                                             
-! [ARCH=sparc64] COMPILER (choice)                                                                            
-                                                                                                                  
-# Compiler                                                                                                        
-@ "gcc_cross" GCC Cross-compiler                                                                                  
-@ "gcc_native" GCC Native                                                                                         
-! [ARCH=arm32|ARCH=mips32|ARCH=mips32eb|ARCH=ppc32|ARCH=ppc64] COMPILER (choice)
-
-# General debuging and assert checking
-! CONFIG_DEBUG (y/n)
