Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ kernel/Makefile	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -49,5 +49,4 @@
 
 AUTOGEN = $(ROOT_PATH)/tools/autogen2.sh
-AGDEPEND = Makefile.ag.depend
 RAW = kernel.raw
 BIN = kernel.bin
@@ -134,5 +133,4 @@
 -include arch/$(KARCH)/Makefile.inc
 -include genarch/Makefile.inc
--include $(AGDEPEND)
 
 ## The at-sign
Index: ols/autogen.py
===================================================================
--- tools/autogen.py	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ 	(revision )
@@ -1,184 +1,0 @@
-#!/usr/bin/env python
-#
-# Copyright (c) 2014 Jakub Jermar
-# 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.
-#
-
-import sys
-import yaml
-import re
-
-def usage():
-	print("%s - Automated structure and offsets generator" % sys.argv[0])
-	print("%s file.ag depend|probe|generate struct.ag" % sys.argv[0])
-	sys.exit()
-
-def depend(struct):
-	deps = ""
-	for include in struct['includes']:
-		if 'depends' in include.keys():
-			deps = deps + include['depends'] + "\n"
-	return deps.strip()
-
-def generate_includes(struct):
-	code = ""
-	for include in struct['includes']:
-		if 'guard' in include.keys():
-			code = code + "#ifdef %s\n" % include['guard']
-		if 'negative-guard' in include.keys():
-			code = code + "#ifndef %s\n" % include['negative-guard']
-		code = code + "#include %s\n" % include['include']
-		if 'guard' in include.keys():
-			code = code + "#endif\n"
-		if 'negative-guard' in include.keys():
-			code = code + "#endif\n"
-	return code.strip()
-
-def generate_struct(struct):
-	packed = ""
-	if ('packed' in struct.keys() and struct['packed']):
-		packed = "__attribute__ ((packed)) "
-	code = "typedef struct %s {\n" % struct['name']
-	for i in range(len(struct['members'])):
-		member = struct['members'][i]
-		if 'elements' in member.keys():
-			code = code + "\t%s %s[%d];\n" % (member['type'], member['name'], member['elements'])
-		else:
-			code = code + "\t%s %s;\n" % (member['type'], member['name'])
-	code = code + "} %s%s_t;" % (packed, struct['name'])
-	return code
-
-def generate_probes(struct):
-	code = ""
-	for i in range(len(struct['members'])):
-		member = struct['members'][i]
-		code = code + ("\temit_constant(%s_OFFSET_%s, offsetof(%s_t, %s));\n" %
-		    (struct['name'].upper(), member['name'].upper(), struct['name'],
-		    member['name']))
-		code = code + ("\temit_constant(%s_SIZE_%s, sizeof(((%s_t *) 0)->%s));\n" %
-		    (struct['name'].upper(), member['name'].upper(), struct['name'],
-		    member['name']))
-		if 'elements' in member.keys():
-			code = code + ("\temit_constant(%s_%s_ITEM_SIZE, sizeof(%s));\n" %
-			    (struct['name'].upper(), member['name'].upper(), member['type']))
-
-	return code
-
-def probe(struct):
-	name = struct['name']
-	typename = struct['name'] + "_t"
-
-	code = """
-%s
-
-#define str(s) #s
-#define emit_constant(n, v) \
-    asm volatile ("EMITTED_CONSTANT " str(n) \" = %%0\" :: \"i\" (v))
-#undef offsetof
-#define offsetof(t, m) ((size_t) &(((t *) 0)->m))
-
-%s
-
-extern int main(int, char *[]);
-
-int main(int argc, char *argv[])
-{
-%s
-	emit_constant(%s_SIZE, sizeof(%s));
-	return 0;
-}
-	""" % (generate_includes(struct), generate_struct(struct),
-	    generate_probes(struct), name.upper(), typename)
-
-	return code
-
-def generate_defines(pairs):
-	code = ""
-	for pair in pairs:
-		code = code + "#define %s %s\n" % (pair[0], pair[1])
-	return code.strip()
-
-def generate(struct, lines):
-	code = """
-/*****************************************************************************
- * AUTO-GENERATED FILE, DO NOT EDIT!!!
- * Generated by: tools/autogen.py
- * Generated from: %s
- *****************************************************************************/
-
-#ifndef AUTOGEN_%s_H
-#define AUTOGEN_%s_H
-
-#ifndef __ASM__
-%s
-#endif
-
-%s
-
-#ifndef __ASM__
-%s
-#endif
-
-#endif
-	""" % (sys.argv[2], struct['name'].upper(), struct['name'].upper(),
-	    generate_includes(struct), generate_defines(lines),
-	    generate_struct(struct))
-
-	return code
-
-def filter_pairs(lines):
-	pattern = re.compile("^\tEMITTED_CONSTANT ([A-Z_][A-Z0-9_]*) = (\$|#)?([0-9]+)$");
-	pairs = []
-	for line in lines:
-		res = pattern.match(line)
-		if res == None:
-			continue
-		pairs = pairs + [res.group(1, 3)]
-	return pairs
-
-
-def run():
-	if len(sys.argv) != 3:
-		usage()
-
-	with open(sys.argv[2], "rb") as fp:
-		struct = yaml.load(fp)
-
-	if sys.argv[1] == "depend":
-		deps = depend(struct)
-		print(deps)
-	elif sys.argv[1] == "probe":
-		code = probe(struct)
-		print(code)
-	elif sys.argv[1] == "generate":
-		lines = sys.stdin.readlines()
-		pairs = filter_pairs(lines)
-		code = generate(struct, pairs)
-		print(code)
-	else:
-		usage()
-
-run()
Index: tools/autogen2.sh
===================================================================
--- tools/autogen2.sh	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ tools/autogen2.sh	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -5,6 +5,4 @@
 # array subscript. Error handling is mostly omitted for simplicity, so any input that does not follow these rules will result
 # in cryptic errors.
-
-echo $PWD
 
 input="$1"
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/Makefile.common	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -67,4 +67,6 @@
 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
 CONFIG_HEADER = $(ROOT_PATH)/config.h
+
+AUTOGEN = $(ROOT_PATH)/tools/autogen2.sh
 
 -include $(VERSION_DEF)
@@ -352,4 +354,7 @@
 	$(CC_JOB) -c -MD -MP $(DEFS) $(LIB_CFLAGS) $(EXTRA_CFLAGS)
 
+%.ag.h %.ag.s %.ag.c %.ag.d: %.h
+	CC="$(CC)" CFLAGS="$(CFLAGS)" $(AUTOGEN) $< $@
+
 -include $(DEPENDS)
 
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/Makefile	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -48,10 +48,9 @@
 -include arch/$(UARCH)/Makefile.inc
 
-ARCH_AUTOGENS_H := $(addsuffix .h,$(basename $(ARCH_AUTOGENS_AG)))
-ARCH_AUTOGENS_PROBE_C := $(addsuffix .ag.probe.c,$(basename $(ARCH_AUTOGENS_AG)))
-ARCH_AUTOGENS_PROBE_S := $(addsuffix .ag.probe.s,$(basename $(ARCH_AUTOGENS_AG)))
-
-PRE_DEPEND += $(ARCH_AUTOGENS_H)
-EXTRA_CLEAN += $(ARCH_AUTOGENS_H) $(ARCH_AUTOGENS_PROBE_C) $(ARCH_AUTOGENS_PROBE_S)
+ARCH_AUTOGENS_PROBE_C := $(ARCH_AUTOGENS_AG:%.ag.h=.ag.c)
+ARCH_AUTOGENS_PROBE_S := $(ARCH_AUTOGENS_AG:%.ag.h=.ag.s)
+
+PRE_DEPEND += $(ARCH_AUTOGENS_AG)
+EXTRA_CLEAN += $(ARCH_AUTOGENS_AG) $(ARCH_AUTOGENS_PROBE_C) $(ARCH_AUTOGENS_PROBE_S)
 
 GENERIC_SOURCES = \
@@ -194,9 +193,4 @@
 include $(USPACE_PREFIX)/Makefile.common
 
-%.h: %.ag
-	$(AUTOGEN) probe $< >$<.probe.c
-	$(CC_AUTOGEN) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
-	$(AUTOGEN) generate $< <$<.probe.s >$@
-
 $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld: $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld.in
 	$(CC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
Index: uspace/lib/c/arch/arm32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/arm32/Makefile.inc	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/arch/arm32/Makefile.inc	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -39,6 +39,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia32/Makefile.inc	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/arch/ia32/Makefile.inc	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -39,6 +39,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/ia64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ia64/Makefile.inc	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/arch/ia64/Makefile.inc	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -38,6 +38,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/mips32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32/Makefile.inc	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/arch/mips32/Makefile.inc	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -37,6 +37,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/mips32eb/Makefile.inc
===================================================================
--- uspace/lib/c/arch/mips32eb/Makefile.inc	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/arch/mips32eb/Makefile.inc	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -37,6 +37,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/ppc32/Makefile.inc
===================================================================
--- uspace/lib/c/arch/ppc32/Makefile.inc	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/arch/ppc32/Makefile.inc	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -37,6 +37,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/riscv64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/riscv64/Makefile.inc	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/arch/riscv64/Makefile.inc	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -36,6 +36,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/sparc64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/sparc64/Makefile.inc	(revision db3c88347157ed2aeffe98179283d9e4e0243edd)
+++ uspace/lib/c/arch/sparc64/Makefile.inc	(revision 95aed62f997beed657c99c003a81e20a7a71d608)
@@ -36,6 +36,5 @@
 
 ARCH_AUTOGENS_AG = \
-	arch/$(UARCH)/include/libarch/istate_struct.ag \
-	arch/$(UARCH)/include/libarch/fibril_context.ag
+	arch/$(UARCH)/include/libarch/fibril_context.ag.h
 
 EXTRA_OUTPUT += arch/$(UARCH)/src/entry.o
