--- ./build/aot/aotcompile.py.orig	2010-04-08 13:38:27.621086079 +0000
+++ ./build/aot/aotcompile.py	2010-04-08 14:22:55.102335973 +0000
@@ -31,12 +31,25 @@
          "dbtool": "/usr/lib/gcc-snapshot/bin/gcj-dbtool"}
 
 MAKEFLAGS = []
-GCJFLAGS = ["-fPIC", "-findirect-dispatch", "-fjni"]
+GCJFLAGS = ["-O2 -fPIC", "-findirect-dispatch", "-fjni"]
 LDFLAGS = ["-Wl,-Bsymbolic"]
 
 MAX_CLASSES_PER_JAR = 1024
 MAX_BYTES_PER_JAR = 1048576
 
+try:
+    for line in file('/proc/meminfo'):
+        if line.startswith('MemTotal:'):
+            memtotal = int(line.split()[1])
+        if memtotal < 270000:
+            MAX_CLASSES_PER_JAR = 512
+            MAX_BYTES_PER_JAR = 524288
+        if memtotal < 140000:
+            MAX_CLASSES_PER_JAR = 256
+            MAX_BYTES_PER_JAR = 262144
+except:
+    pass
+
 MAKEFILE = "Makefile"
 
 MAKEFILE_HEADER = '''\
@@ -49,7 +62,7 @@
 	$(GCJ) -c $(GCJFLAGS) $< -o $@
 
 TARGETS = \\
-%(targets)s
+javac ecj1
 
 all: $(TARGETS)'''
 
@@ -63,6 +76,12 @@
 %(dso)s: $(%(base)s_OBJECTS)
 	$(GCJ) -shared $(GCJFLAGS) $(LDFLAGS) $^ -o $@
 
+javac: $(%(base)s_OBJECTS) resources.o
+	$(GCJ) $(GCJFLAGS) $(RPATH) -Wl,-O1 --main=org.eclipse.jdt.internal.compiler.batch.Main $^ -o $@
+
+ecj1: $(%(base)s_OBJECTS) resources.o
+	$(GCJ) $(GCJFLAGS) $(RPATH) -Wl,-O1 --main=org.eclipse.jdt.internal.compiler.batch.GCCMain $^ -o $@
+
 %(db)s: $(%(base)s_SOURCES)
 	$(DBTOOL) -n $@ 64
 	for jar in $^; do \\
