gen_makefile: allow combining several .opts files
diff --git a/README b/README
index 9efce66..a94522b 100644
--- a/README
+++ b/README
@@ -8,13 +8,13 @@
 Run ./gen_makefile.py with a choice of projects (2G only or also 3G?)
 and a choice of configure options, for example:
 
-  ./gen_makefile.py 3G+2G.deps all_enabled.opts
+  ./gen_makefile.py 3G+2G.deps default.opts iu.opts
 
 This generates a new dir containing a Makefile. When you run make in it, this
 will clone the source trees (if not present yet) and build all of them in the
 right order:
 
-  cd make-3G+2G.deps-all_enabled.opts/
+  cd make-3G+2G-default+iu
   make
 
 If you make modifications in one of the source trees, this Makefile will pick
diff --git a/all_enabled.opts b/all_enabled.opts
deleted file mode 100644
index ad7fa6a..0000000
--- a/all_enabled.opts
+++ /dev/null
@@ -1,4 +0,0 @@
-osmo-mgw --enable-mgcp-transcoding
-osmo-msc --enable-smpp --enable-iu --enable-mgcp-transcoding --enable-external-tests
-osmo-bsc --enable-osmo-bsc --enable-nat --enable-mgcp-transcoding --enable-external-tests
-osmo-sgsn --enable-iu --enable-external-tests
diff --git a/default.opts b/default.opts
new file mode 100644
index 0000000..e79879f
--- /dev/null
+++ b/default.opts
@@ -0,0 +1,2 @@
+osmo-msc --enable-smpp
+osmo-bsc --enable-osmo-bsc --enable-nat
diff --git a/external-tests.opts b/external-tests.opts
new file mode 100644
index 0000000..02b69f8
--- /dev/null
+++ b/external-tests.opts
@@ -0,0 +1,3 @@
+osmo-msc --enable-external-tests
+osmo-bsc --enable-external-tests
+osmo-sgsn --enable-external-tests
diff --git a/gen_makefile.py b/gen_makefile.py
index 908d221..05af4c8 100755
--- a/gen_makefile.py
+++ b/gen_makefile.py
@@ -2,7 +2,7 @@
 '''
 Generate a top-level makefile that builds the Osmocom 2G + 3G network components.
 
-  ./gen_makefile.py projects.deps [configuration.opts] [-o Makefile.output]
+  ./gen_makefile.py projects.deps [configure.opts [more.opts]] [-o Makefile.output]
 
 Configured by text files:
 
@@ -37,10 +37,10 @@
   help='''Config file containing projects to build and
 dependencies between those''')
 
-parser.add_argument('configure_opts_file',
+parser.add_argument('configure_opts_files',
   help='''Config file containing project name and
 ./configure options''',
-  default=None, nargs='?')
+  nargs='*')
 
 parser.add_argument('-m', '--make-dir', dest='make_dir',
   help='''Place Makefile in this dir (default: create
@@ -69,6 +69,27 @@
 
 args = parser.parse_args()
 
+class listdict(dict):
+  'a dict of lists { "a": [1, 2, 3],  "b": [1, 2] }'
+
+  def add(self, name, item):
+    l = self.get(name)
+    if not l:
+      l = []
+      self[name] = l
+    l.append(item)
+
+  def extend(self, name, l):
+    for v in l:
+      self.add(name, v)
+
+  def add_dict(self, d):
+    for k,v in d.items():
+      self.add(k, v)
+
+  def extend_dict(self, d):
+    for k,v in d.items():
+      l = self.extend(k, v)
 
 def read_projects_deps(path):
   'Read deps config and return tuples of (project_name, which-other-to-build-first).'
@@ -156,11 +177,17 @@
 
 
 projects_deps = read_projects_deps(args.projects_and_deps_file)
-configure_opts = read_configure_opts(args.configure_opts_file)
+configure_opts = listdict()
+configure_opts_files = sorted(args.configure_opts_files or [])
+for configure_opts_file in configure_opts_files:
+  r = read_configure_opts(configure_opts_file)
+  configure_opts.extend_dict(read_configure_opts(configure_opts_file))
 
 make_dir = args.make_dir
 if not make_dir:
-  make_dir = 'make-%s-%s' % (args.projects_and_deps_file, args.configure_opts_file)
+  deps_name = args.projects_and_deps_file.replace('.deps', '')
+  opts_names = '+'.join([f.replace('.opts', '') for f in configure_opts_files])
+  make_dir = 'make-%s-%s' % (deps_name, opts_names)
 
 if not os.path.isdir(make_dir):
   os.makedirs(make_dir)
@@ -187,7 +214,7 @@
 '''.format(
     script=os.path.relpath(sys.argv[0], make_dir),
     projects_and_deps=os.path.relpath(args.projects_and_deps_file, make_dir),
-    configure_opts=os.path.relpath(args.configure_opts_file, make_dir),
+    configure_opts=' '.join([os.path.relpath(f, make_dir) for f in configure_opts_files]),
     make_dir='.',
     makefile=args.output,
     src_dir=os.path.relpath(args.src_dir, make_dir),
diff --git a/iu.opts b/iu.opts
new file mode 100644
index 0000000..a96a1bc
--- /dev/null
+++ b/iu.opts
@@ -0,0 +1,2 @@
+osmo-msc --enable-iu
+osmo-sgsn --enable-iu
diff --git a/transcoding.opts b/transcoding.opts
new file mode 100644
index 0000000..7147b5e
--- /dev/null
+++ b/transcoding.opts
@@ -0,0 +1,2 @@
+osmo-mgw --enable-mgcp-transcoding
+osmo-msc --enable-mgcp-transcoding