Factor and simplify Makefile's and mpconfig, part 2.
diff --git a/py/asmx64.c b/py/asmx64.c
index 226d4ef..d315817 100644
--- a/py/asmx64.c
+++ b/py/asmx64.c
@@ -1,16 +1,18 @@
 #include <stdio.h>
 #include <assert.h>
-#include <sys/types.h>
-#include <sys/mman.h>
 #include <string.h>
 
 #include "misc.h"
-#include "asmx64.h"
 #include "mpconfig.h"
 
 // wrapper around everything in this file
 #if MICROPY_EMIT_X64
 
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include "asmx64.h"
+
 #if defined(__OpenBSD__) || defined(__MACH__)
 #define MAP_ANONYMOUS MAP_ANON
 #endif
diff --git a/py/gc.c b/py/gc.c
index 7d4cac6..054a3cc 100644
--- a/py/gc.c
+++ b/py/gc.c
@@ -6,6 +6,8 @@
 #include "mpconfig.h"
 #include "gc.h"
 
+#if MICROPY_ENABLE_GC
+
 // a machine word is big enough to hold a pointer
 /*
 #define BYTES_PER_WORD (8)
@@ -380,3 +382,5 @@
     gc_dump_at();
 }
 */
+
+#endif // MICROPY_ENABLE_GC
diff --git a/py/lexerunix.c b/py/lexerunix.c
index 14c28c1..5336610 100644
--- a/py/lexerunix.c
+++ b/py/lexerunix.c
@@ -4,8 +4,11 @@
 #include <fcntl.h>
 
 #include "misc.h"
+#include "mpconfig.h"
 #include "lexer.h"
 
+#if MICROPY_ENABLE_LEXER_UNIX
+
 typedef struct _str_buf_t {
     bool free;                  // free src_beg when done
     const char *src_beg;        // beginning of source
@@ -78,3 +81,5 @@
     vstr_printf(vstr, "%s.py", qstr_str(mod_name));
     return mp_lexer_new_from_file(vstr_str(vstr)); // TODO does lexer need to copy the string? can we free it here?
 }
+
+#endif // MICROPY_ENABLE_LEXER_UNIX
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 8ce432a..2017ba3 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -39,14 +39,29 @@
 #define MICROPY_MEM_STATS (0)
 #endif
 
+// Whether to build code to show byte code
+#ifndef MICROPY_SHOW_BC
+#define MICROPY_SHOW_BC (0)
+#endif
+
 /*****************************************************************************/
 /* Fine control over Python features                                         */
 
+// Whether to include the garbage collector
+#ifndef MICROPY_ENABLE_GC
+#define MICROPY_ENABLE_GC (0)
+#endif
+
 // Whether to include REPL helper function
 #ifndef MICROPY_ENABLE_REPL_HELPERS
 #define MICROPY_ENABLE_REPL_HELPERS (0)
 #endif
 
+// Whether to include lexer helper function for unix
+#ifndef MICROPY_ENABLE_LEXER_UNIX
+#define MICROPY_ENABLE_LEXER_UNIX (0)
+#endif
+
 // Whether to support float and complex types
 #ifndef MICROPY_ENABLE_FLOAT
 #define MICROPY_ENABLE_FLOAT (0)
diff --git a/py/py.mk b/py/py.mk
index e673c71..3ed8a3e 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -24,6 +24,7 @@
 	nlrx64.o \
 	nlrthumb.o \
 	malloc.o \
+	gc.o \
 	qstr.o \
 	vstr.o \
 	unicode.o \
@@ -88,6 +89,10 @@
 $(PY_BUILD)%.o: $(PY_SRC)/%.c mpconfigport.h
 	$(CC) $(CFLAGS) -c -o $@ $<
 
+# optimising gc for speed; 5ms down to 4ms on pybv2
+$(PY_BUILD)gc.o: $(PY_SRC)/gc.c
+	$(CC) $(CFLAGS) -O3 -c -o $@ $<
+
 # optimising vm for speed, adds only a small amount to code size but makes a huge difference to speed (20% faster)
 $(PY_BUILD)vm.o: $(PY_SRC)/vm.c
 	$(CC) $(CFLAGS) -O3 -c -o $@ $<
diff --git a/py/showbc.c b/py/showbc.c
index eb7d41b..aea0aff 100644
--- a/py/showbc.c
+++ b/py/showbc.c
@@ -8,6 +8,8 @@
 #include "mpconfig.h"
 #include "bc0.h"
 
+#if MICROPY_SHOW_BC
+
 #define DECODE_UINT do { unum = *ip++; if (unum > 127) { unum = ((unum & 0x3f) << 8) | (*ip++); } } while (0)
 #define DECODE_ULABEL do { unum = (ip[0] | (ip[1] << 8)); ip += 2; } while (0)
 #define DECODE_SLABEL do { unum = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2; } while (0)
@@ -363,3 +365,5 @@
         printf("\n");
     }
 }
+
+#endif // MICROPY_SHOW_BC