more precise OER and PER code bundling
diff --git a/libasn1compiler/asn1c_compat.c b/libasn1compiler/asn1c_compat.c
index ae0f475..f55032c 100644
--- a/libasn1compiler/asn1c_compat.c
+++ b/libasn1compiler/asn1c_compat.c
@@ -1,10 +1,6 @@
 #include "asn1c_internal.h"
 #include "asn1c_compat.h"
 
-#ifndef	PATH_MAX
-#define	PATH_MAX    1024
-#endif
-
 /* Normally file permissions are (DEFFILEMODE & ~umask(2)) */
 #ifndef	DEFFILEMODE	/* Normally in <sys/stat.h> */
 
diff --git a/libasn1compiler/asn1c_fdeps.c b/libasn1compiler/asn1c_fdeps.c
index 18dd637..ed8af9b 100644
--- a/libasn1compiler/asn1c_fdeps.c
+++ b/libasn1compiler/asn1c_fdeps.c
@@ -1,82 +1,84 @@
 #include "asn1c_internal.h"
 #include "asn1c_fdeps.h"
 
-#ifndef PATH_MAX
-#define PATH_MAX    1024
-#endif
+static asn1c_dep_filename *asn1c_new_dep_filename(const char *filename);
+static void asn1c_dep_add(asn1c_dep_chain *dlist, const char *filename,
+                         int lineno, int column);
+static asn1c_dep_chain *asn1c_new_dep_chain();
 
-static asn1c_fdeps_t *asn1c_new_dep(const char *filename);
-static int asn1c_dep_add(asn1c_fdeps_t *deps, asn1c_fdeps_t *d);
+static asn1c_dep_chain *
+asn1c_dep_chains_add_new(asn1c_dep_chainset *deps,
+                         enum asn1c_dep_section section, int active) {
+    asn1c_dep_chain *dc = asn1c_new_dep_chain();
+    asn1c_tagged_dep_chain *tc = calloc(1, sizeof(*tc));
+    tc->chain = dc;
+    tc->section = section;
+    tc->activated.active = active;
 
-int
-asn1c_activate_dependency(asn1c_fdeps_t *deps, asn1c_fdeps_t *cur, const char *data) {
-	char fname_scratch[PATH_MAX];
-	const char *fname;
-	int i;
+    deps->chains = realloc(deps->chains,
+                           sizeof(deps->chains[0]) * (deps->chains_count + 1));
+    assert(deps->chains);
+    deps->chains[deps->chains_count] = tc;
+    deps->chains_count++;
 
-	if(!deps || !data || !*data)
-		return 0;
-	if(!cur) cur = deps;
-
-	if(cur->usage > FDEP_NOTUSED)
-		return 1;	/* Already activated */
-
-	fname = data;
-	if(*data == '#') {
-		const char *start = data;
-		const char *end = 0;
-
-		start = strchr(data, '<');
-		if(start) {
-			start++;
-			end = strchr(start, '>');
-		} else if((start = strchr(data, '\"'))) {
-			start++;
-			end = strchr(start, '\"');
-		}
-		if(end) {
-			assert((end-start) + 1 < (ssize_t)sizeof(fname_scratch));
-			memcpy(fname_scratch, start, end - start);
-			fname_scratch[end-start] = '\0';
-			fname = fname_scratch;
-		} else {
-			return 0;
-		}
-	}
-
-	if(cur->filename && strcmp(cur->filename, fname) == 0) {
-		cur->usage = FDEP_REFERRED;
-
-		/* Activate subdependencies */
-		for(i = 0; i < cur->el_count; i++) {
-			asn1c_activate_dependency(deps,
-				cur->elements[i],
-				cur->elements[i]->filename);
-		}
-
-		/*
-		 * This might be a link to someplace else.
-		 */
-		return asn1c_activate_dependency(deps, NULL, fname);
-	} else {
-		for(i = 0; i < cur->el_count; i++) {
-			asn1c_activate_dependency(deps,
-				cur->elements[i], fname);
-		}
-	}
-
-	return 0;
+    return dc;
 }
 
-asn1c_fdeps_t *
+void
+asn1c_activate_dependency(asn1c_dep_chainset *deps, const char *data,
+                          const char *by) {
+    char fname_scratch[PATH_MAX];
+
+    if(!deps || !data || !*data) {
+        return;
+    }
+
+    assert(deps->chains_count);
+
+    const char *fname = data;
+    if(*data == '#') {
+        const char *start = data;
+        const char *end = 0;
+
+        start = strchr(data, '<');
+        if(start) {
+            start++;
+            end = strchr(start, '>');
+        } else if((start = strchr(data, '\"'))) {
+            start++;
+            end = strchr(start, '\"');
+        }
+        if(end) {
+            assert((end-start) + 1 < (ssize_t)sizeof(fname_scratch));
+            memcpy(fname_scratch, start, end - start);
+            fname_scratch[end-start] = '\0';
+            fname = fname_scratch;
+        } else {
+            return;
+        }
+    }
+
+    for(size_t i = 0; i < deps->chains_count; i++) {
+        asn1c_tagged_dep_chain *ch = deps->chains[i];
+        if(!ch->activated.active && ch->chain->deps_count > 0
+           && strcmp(ch->chain->deps[0]->filename, fname) == 0) {
+            ch->activated.by = strdup(by);
+            ch->activated.active = 1;
+
+            for(size_t j = 0; j < ch->chain->deps_count; j++) {
+                asn1c_activate_dependency(deps, ch->chain->deps[j]->filename,
+                                          by);
+            }
+        }
+    }
+}
+
+asn1c_dep_chainset *
 asn1c_read_file_dependencies(arg_t *arg, const char *datadir) {
 	char buf[4096];
-	asn1c_fdeps_t *deps;
-	asn1c_fdeps_t *cur;
+	asn1c_dep_chainset *deps;
 	FILE *f;
-	enum fdep_usage special_section = FDEP_NOTUSED;
-
-	(void)arg;
+    int lineno = 0;
 
 	if(!datadir || strlen(datadir) > sizeof(buf) / 2) {
 		errno = EINVAL;
@@ -88,146 +90,162 @@
 	f = fopen(buf, "r");
 	if(!f) return NULL;
 
-	deps = asn1c_new_dep(0);
+	deps = calloc(1, sizeof(*deps));
 	assert(deps);
+    enum asn1c_dep_section section = FDEP_COMMON_FILES;
+    int activate = 0;
 
-	while(fgets(buf, sizeof(buf), f)) {
+    while(fgets(buf, sizeof(buf), f)) {
 		char *p = strchr(buf, '#');
 		if(p) *p = '\0';	/* Remove comments */
 
-		cur = deps;
-		for(p = strtok(buf, " \t\r\n"); p;
+        lineno++;
+
+        asn1c_dep_chain *dc = asn1c_dep_chains_add_new(deps, section, activate);
+
+        for(p = strtok(buf, " \t\r\n"); p;
 				p = strtok(NULL, " \t\r\n")) {
-			asn1c_fdeps_t *d;
 
 			/*
 			 * Special "prefix" section.
 			 */
 			if(strchr(p, ':')) {
-				special_section = FDEP_IGNORE;
 				if(strcmp(p, "COMMON-FILES:") == 0) {
-					special_section = FDEP_COMMON_FILES;
+					section = FDEP_COMMON_FILES;
+                    activate = 1;
 				} else if(strcmp(p, "CONVERTER:") == 0) {
-					special_section = FDEP_CONVERTER;
+                    activate = 1;
+					section = FDEP_CONVERTER;
 				} else if((arg->flags & A1C_GEN_OER)
 					  && strcmp(p, "CODEC-OER:") == 0) {
-					special_section = FDEP_CODEC_OER;
+                    activate = 0;
+					section = FDEP_CODEC_OER;
 				} else if((arg->flags & A1C_GEN_PER)
 					  && strcmp(p, "CODEC-PER:") == 0) {
-					special_section = FDEP_CODEC_PER;
-				}
-				break;
+                    activate = 0;
+					section = FDEP_CODEC_PER;
+				} else {
+					section = FDEP_IGNORE;
+                    activate = 0;
+                }
+                break;
 			}
 
-			if(special_section == FDEP_IGNORE)
-				continue;
-
-			d = asn1c_new_dep(p);
-			d->usage = special_section;
-
-			if(asn1c_dep_add(cur, d) == 1)
-				cur = d;
-		}
+            asn1c_dep_add(dc, p, lineno, p - buf);
+        }
 	}
 
 	fclose(f);
 
+    /* A single filename by itself means that we should include that */
+    for(size_t i = 0; i < deps->chains_count; i++) {
+        asn1c_tagged_dep_chain *ch = deps->chains[i];
+        if(!ch->activated.active && ch->chain->deps_count == 1) {
+            asn1c_activate_dependency(deps, ch->chain->deps[0]->filename,
+                                      "implicit");
+        }
+    }
+
 	return deps;
 }
 
-static asn1c_fdeps_t *
-asn1c_new_dep(const char *filename) {
-	asn1c_fdeps_t *d;
+static asn1c_dep_filename *
+asn1c_new_dep_filename(const char *filename) {
+    asn1c_dep_filename *d;
 
-	d = calloc(1, sizeof(*d));
-	if(filename) {
-		d->filename = strdup(filename);
-		if(!d->filename) return NULL;
-	}
+    assert(filename);
+
+    d = calloc(1, sizeof(*d));
+    assert(d);
+    d->filename = strdup(filename);
+    assert(d->filename);
 
 	return d;
 }
 
-static void
-asn1c_free_dep(asn1c_fdeps_t *d) {
+static asn1c_dep_chain *
+asn1c_new_dep_chain() {
+    return calloc(1, sizeof(asn1c_dep_chain));
+}
 
-	if(d) {
-		if(d->filename) free(d->filename);
-		d->filename = 0;
-		free(d);
-	}
+static void
+asn1c_dep_add(asn1c_dep_chain *dlist, const char *filename, int lineno, int column) {
+    asn1c_dep_filename *df = asn1c_new_dep_filename(filename);
+    df->lineno = lineno;
+    df->column = column;
+
+    dlist->deps =
+        realloc(dlist->deps, (dlist->deps_count + 1) * sizeof(dlist->deps[0]));
+    assert(dlist->deps);
+    dlist->deps[dlist->deps_count] = df;
+    dlist->deps_count += 1;
 }
 
 static int
-asn1c_dep_add(asn1c_fdeps_t *deps, asn1c_fdeps_t *d) {
-	int n;
-
-	/* Check for duplicates */
-	for(n = 0; n < deps->el_count; n++) {
-		if(strcmp(deps->elements[n]->filename, d->filename) == 0)
-			return 0;
-	}
-
-	if(deps->el_count == deps->el_size) {
-		void *p;
-		n = deps->el_size?deps->el_size << 2:16;
-		p = realloc(deps->elements,
-			n * sizeof(deps->elements[0]));
-		assert(p);
-		deps->elements = p;
-		deps->el_size = n;
-	}
-
-	deps->elements[deps->el_count++] = d;
-	return 1;
+asn1c_dep_has_filename(const asn1c_dep_chain *dlist, const char *filename) {
+    for(size_t i = 0; i < dlist->deps_count; i++) {
+        if(strcmp(dlist->deps[i]->filename, filename) == 0) {
+            return 1;
+        }
+    }
+    return 0;
 }
 
-asn1c_fdeps_t *
-asn1c_deps_flatten(const asn1c_fdeps_t *deps) {
-	asn1c_fdeps_t *dlist;
-	asn1c_fdeps_t *d;
+asn1c_dep_chain *
+asn1c_deps_flatten(const asn1c_dep_chainset *deps,
+                   enum asn1c_dep_section include_section) {
+    asn1c_dep_chain *dlist;
 
 	if(!deps) {
 		errno = EINVAL;
 		return 0;
 	}
 
-	dlist = asn1c_new_dep(0);
+	dlist = asn1c_new_dep_chain();
 
-	if(deps->filename && deps->usage != FDEP_NOTUSED) {
-		d = asn1c_new_dep(deps->filename);
-		d->usage = deps->usage;
-		if(!asn1c_dep_add(dlist, d)) {
-			asn1c_free_dep(d);
-		}
-	}
+	for(size_t i = 0; i < deps->chains_count; i++) {
+        asn1c_tagged_dep_chain *tc = deps->chains[i];
+        asn1c_dep_chain *dc = tc->chain;
 
-	for(int i = 0; i < deps->el_count; i++) {
-		d = asn1c_deps_flatten(deps->elements[i]);
-		assert(!d->filename);
-		for(int j = 0; j < d->el_count; j++) {
-			if(asn1c_dep_add(dlist, d->elements[j])) {
-				d->elements[j] = 0;
-			}
-		}
-		asn1c_deps_freelist(d);
-	}
+        if(!tc->activated.active) {
+            continue;
+        }
+        if((tc->section & include_section) == 0) {
+            continue;
+        }
+
+        for(size_t j = 0; j < dc->deps_count; j++) {
+            if(!asn1c_dep_has_filename(dlist, dc->deps[j]->filename))  {
+                asn1c_dep_add(dlist, dc->deps[j]->filename, dc->deps[j]->lineno,
+                              dc->deps[j]->column);
+            }
+        }
+    }
 
 	return dlist;
 }
 
 void
-asn1c_deps_freelist(asn1c_fdeps_t *deps) {
+asn1c_dep_chain_free(asn1c_dep_chain *dc) {
+    if(dc) {
+        for(size_t i = 0; i < dc->deps_count; i++) {
+            asn1c_dep_filename *df = dc->deps[i];
+            free(df->filename);
+            free(df);
+        }
+        free(dc->deps);
+    }
+}
+
+void
+asn1c_dep_chainset_free(asn1c_dep_chainset *deps) {
 	if(deps) {
-		int i;
-		if(deps->elements) {
-			for(i = 0; i < deps->el_count; i++) {
-				asn1c_deps_freelist(deps->elements[i]);
-				deps->elements[i] = 0;
-			}
-			free(deps->elements);
-			deps->elements = 0;			
-		}
-		asn1c_free_dep(deps);
-	}
+        for(size_t i = 0; i < deps->chains_count; i++) {
+            asn1c_dep_chain_free(deps->chains[i]->chain);
+            free(deps->chains[i]->activated.by);
+            free(deps->chains[i]);
+        }
+        free(deps->chains);
+        free(deps);
+    }
 }
diff --git a/libasn1compiler/asn1c_fdeps.h b/libasn1compiler/asn1c_fdeps.h
index 3be9e80..7b025ba 100644
--- a/libasn1compiler/asn1c_fdeps.h
+++ b/libasn1compiler/asn1c_fdeps.h
@@ -1,31 +1,61 @@
 #ifndef	ASN1C_FDEPS_H
 #define	ASN1C_FDEPS_H
 
-typedef struct asn1c_fdeps_s {
-	char *filename;		/* Or 0, if root. */
+typedef struct {
+    char *filename;
+    int lineno;
+    int column;
+} asn1c_dep_filename;
 
-	enum fdep_usage {
-	  FDEP_IGNORE       = -1,	/* Ignore contents of the section */
-	  FDEP_NOTUSED      =  0,
-	  FDEP_REFERRED     =  1,	/* Dynamic list of dependencies */
-	  FDEP_CONVERTER    =  2,	/* Name of the int main() file */
-	  FDEP_COMMON_FILES =  3,	/* Section for mandatory dependencies */
-	  FDEP_CODEC_OER    =  4,	/* Use contents only if -gen-OER */
-	  FDEP_CODEC_PER    =  8,	/* Use contents only if -gen-PER */
-	} usage;		/* Some file refers to it */
 
-	struct asn1c_fdeps_s **elements;
-	int el_size;
-	int el_count;
-} asn1c_fdeps_t;
+/*
+ * Format:
+ * <observed-name> [<dependent-name> ...]
+ */
+typedef struct {
+    asn1c_dep_filename **deps;
+    size_t deps_count;
+} asn1c_dep_chain;
 
-asn1c_fdeps_t *asn1c_read_file_dependencies(arg_t *arg, const char *datadir);
+/*
+ * A single dependency chain, marked with the usage tag and activation tag.
+ */
+typedef struct {
+    enum asn1c_dep_section {
+        FDEP_IGNORE = 0,              /* Section is not used */
+        FDEP_DEFAULT = (1 << 1),      /* Default dependency list */
+        FDEP_REFERRED = (1 << 2),     /* Dynamic list of dependencies */
+        FDEP_CONVERTER = (1 << 3),    /* Name of the file with int main() */
+        FDEP_COMMON_FILES = (1 << 4), /* Section for mandatory dependencies */
+        FDEP_CODEC_OER = (1 << 5),    /* Use contents only if -gen-OER */
+        FDEP_CODEC_PER = (1 << 6),    /* Use contents only if -gen-PER */
+    } section;                        /* Some file refers to it */
+
+    /* Whether this chain is alive and has to be present in the output */
+    struct {
+        int active;
+        char *by;
+    } activated;
+
+    asn1c_dep_chain *chain;
+} asn1c_tagged_dep_chain;
+
+typedef struct {
+    asn1c_tagged_dep_chain **chains;
+    size_t chains_count;
+} asn1c_dep_chainset;
+
+asn1c_dep_chainset *asn1c_read_file_dependencies(arg_t *arg,
+                                                 const char *datadir);
 
 /* Data may be a filename or an "#include <>" string. */
-int asn1c_activate_dependency(asn1c_fdeps_t *deps, asn1c_fdeps_t *cur,
-	const char *data);
+void asn1c_activate_dependency(asn1c_dep_chainset *deps, const char *data,
+                               const char *by);
 
-asn1c_fdeps_t *asn1c_deps_flatten(const asn1c_fdeps_t *deps);
-void asn1c_deps_freelist(asn1c_fdeps_t *deps);
+asn1c_dep_chain *asn1c_deps_flatten(const asn1c_dep_chainset *deps,
+                                    enum asn1c_dep_section);
+
+void asn1c_dep_chain_free(asn1c_dep_chain *);
+void asn1c_dep_chainset_free(asn1c_dep_chainset *);
 
 #endif	/* ASN1C_FDEPS_H */
diff --git a/libasn1compiler/asn1c_internal.h b/libasn1compiler/asn1c_internal.h
index e74371c..7a07e35 100644
--- a/libasn1compiler/asn1c_internal.h
+++ b/libasn1compiler/asn1c_internal.h
@@ -10,6 +10,7 @@
 #include <string.h>		/* for strlen(3) and memset(3) */
 #include <ctype.h>		/* for isalnum(3) */
 #include <sys/types.h>		/* for fstat(2) */
+#include <limits.h>		/* for PATH_MAX */
 #include <stdarg.h>
 #include <errno.h>
 #include <assert.h>
@@ -22,6 +23,10 @@
 #include <unistd.h>		/* for unlink(2) */
 #endif
 
+#ifndef PATH_MAX
+#define PATH_MAX    1024
+#endif
+
 #ifdef	_WIN32
 #include <io.h>
 #include <malloc.h>
diff --git a/libasn1compiler/asn1c_save.c b/libasn1compiler/asn1c_save.c
index c734062..2aaee05 100644
--- a/libasn1compiler/asn1c_save.c
+++ b/libasn1compiler/asn1c_save.c
@@ -38,10 +38,10 @@
     TI_INCLUDED_FROM_CMDLINE
 };
 
-static int asn1c_dump_streams(arg_t *arg, asn1c_fdeps_t *, int, char **);
+static int asn1c_dump_streams(arg_t *arg, asn1c_dep_chainset *, int, char **);
 static int asn1c_print_streams(arg_t *arg);
-static int asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *, int, char **);
-static int asn1c_copy_over(arg_t *arg, char *path);
+static int asn1c_save_streams(arg_t *arg, asn1c_dep_chainset *, int, char **);
+static int asn1c_copy_over(arg_t *arg, const char *path, const char *msg);
 static int identical_files(const char *fname1, const char *fname2);
 static int need_to_generate_pdu_collection(arg_t *arg);
 static abuf *generate_pdu_collection(arg_t *arg);
@@ -54,8 +54,8 @@
 static int asn1c__pdu_type_lookup(const char *typename);
 
 static int
-asn1c__save_library_makefile(arg_t *arg, const asn1c_fdeps_t *deps, const char *datadir, const char *makefile_name) {
-	asn1c_fdeps_t *dlist;
+asn1c__save_library_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
+                             const char *datadir, const char *makefile_name) {
 	asn1p_module_t *mod;
     FILE *mkf;
 
@@ -90,49 +90,51 @@
 	/*
 	 * Move necessary skeleton files and add them to Makefile.am.targets.
 	 */
-	dlist = asn1c_deps_flatten(deps);
-	if(dlist) {
-		char buf[8129];
+    asn1c_dep_chain *dlist = asn1c_deps_flatten(deps, ~FDEP_CONVERTER);
+    if(dlist) {
+		char dstpath[PATH_MAX];
 		char *dir_end;
 		size_t dlen = strlen(datadir);
 
-		assert(dlen < (sizeof(buf) / 2 - 2));
-		memcpy(buf, datadir, dlen);
-		dir_end = buf + dlen;
+		assert(dlen < (sizeof(dstpath) / 2 - 2));
+		memcpy(dstpath, datadir, dlen);
+		dir_end = dstpath + dlen;
 		*dir_end++ = '/';
 
-		for(int i = 0; i < dlist->el_count; i++) {
+        for(size_t i = 0; i < dlist->deps_count; i++) {
+            char where[32]; /* Location of the */
 			char *what_kind;	/* HEADERS or SOURCES */
-			char *fname = dlist->elements[i]->filename;
+            const asn1c_dep_filename *dep_file = dlist->deps[i];
+			char *fname = dep_file->filename;
 			char *dotH;
 
-			assert(strlen(fname) < (sizeof(buf) / 2));
+			assert(strlen(fname) < (sizeof(dstpath) / 2));
 			strcpy(dir_end, fname);
 
-            if(dlist->elements[i]->usage == FDEP_CONVERTER
-               && !(arg->flags & A1C_GEN_EXAMPLE))
-                continue;
+            if(arg->flags & A1C_DEBUG) {
+                snprintf(where, sizeof(where), "(line %d col %d)",
+                         dep_file->lineno, dep_file->column);
+            } else {
+                where[0] = '\0';
+            }
 
-            if(asn1c_copy_over(arg, buf) == -1) {
+            if(asn1c_copy_over(arg, dstpath, where) == -1) {
 				safe_fprintf(mkf, ">>>ABORTED<<<");
 				fclose(mkf);
 				return -1;
 			}
 
-			/* no CONVERTER data in Makefile.am.targets */
-			if(dlist->elements[i]->usage != FDEP_CONVERTER) {
-				/* HEADERS versus SOURCES */
-				dotH = strrchr(fname, 'h');
-				if(dotH && fname<dotH && dotH[-1] == '.' && !dotH[1])
-					what_kind = "HEADERS";
-				else
-					what_kind = "SOURCES";
-				safe_fprintf(mkf, "ASN_MODULE_%s+=%s\n",
-					what_kind, fname);
-			}
+            /* HEADERS versus SOURCES */
+            dotH = strrchr(fname, 'h');
+            if(dotH && fname < dotH && dotH[-1] == '.' && !dotH[1]) {
+                what_kind = "HEADERS";
+            } else {
+                what_kind = "SOURCES";
+            }
+            safe_fprintf(mkf, "ASN_MODULE_%s+=%s\n", what_kind, fname);
 		}
 
-		asn1c_deps_freelist(dlist);
+		asn1c_dep_chain_free(dlist);
 	}
 
 	safe_fprintf(
@@ -156,8 +158,8 @@
 }
 
 static int
-asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps,
-                             const char *makefile_name,
+asn1c__save_example_makefile(arg_t *arg, const asn1c_dep_chainset *deps,
+                             const char *datadir, const char *makefile_name,
                              const char *library_makefile_name, int argc,
                              char **argv) {
     FILE *mkf;
@@ -180,15 +182,21 @@
         need_to_generate_pdu_collection(arg) ? "-DASN_PDU_COLLECTION " : "");
 
     if(arg->flags & A1C_GEN_EXAMPLE) {
-        asn1c_fdeps_t *dlist = asn1c_deps_flatten(deps);
+        asn1c_dep_chain *dlist = asn1c_deps_flatten(deps, FDEP_CONVERTER);
         if(dlist) {
-            /* only CONVERTER data in the makefile */
-            for(int i = 0; i < dlist->el_count; i++) {
-                if(dlist->elements[i]->usage == FDEP_CONVERTER) {
-                    safe_fprintf(mkf, "\\\n\t%s", dlist->elements[i]->filename);
+            for(size_t i = 0; i < dlist->deps_count; i++) {
+                char dstpath[PATH_MAX];
+                int ret = snprintf(dstpath, sizeof(dstpath), "%s/%s", datadir,
+                                   dlist->deps[i]->filename);
+                assert(ret > 0 && (size_t)ret < sizeof(dstpath));
+                if(asn1c_copy_over(arg, dstpath, "implicit") == -1) {
+                    safe_fprintf(mkf, ">>>ABORTED<<<");
+                    fclose(mkf);
+                    return -1;
                 }
+                safe_fprintf(mkf, "\\\n\t%s", dlist->deps[i]->filename);
             }
-            asn1c_deps_freelist(dlist);
+            asn1c_dep_chain_free(dlist);
         }
     }
 
@@ -237,7 +245,6 @@
 int
 asn1c_save_compiled_output(arg_t *arg, const char *datadir,
 		int argc, int optc, char **argv) {
-    asn1c_fdeps_t *deps = 0;
     int ret = -1;
 
     /*
@@ -247,6 +254,7 @@
         return -1;
     }
 
+    asn1c_dep_chainset *deps;
     do {
         asn1p_module_t *mod;
 
@@ -281,14 +289,14 @@
         if(ret) break;
 
         if(arg->flags & A1C_GEN_EXAMPLE) {
-            ret = asn1c__save_example_makefile(arg, deps, "Makefile.am.example",
-                                               "Makefile.am.libasncodec", argc,
-                                               argv);
+            ret = asn1c__save_example_makefile(
+                arg, deps, datadir, "Makefile.am.example",
+                "Makefile.am.libasncodec", argc, argv);
             if(ret) break;
         }
     } while(0);
 
-    asn1c_deps_freelist(deps);
+    asn1c_dep_chainset_free(deps);
     asn1c__cleanup_pdu_type();
 
     return ret;
@@ -298,8 +306,9 @@
  * Dump the streams.
  */
 static int
-asn1c_dump_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv)  {
-	if(arg->flags & A1C_PRINT_COMPILED) {
+asn1c_dump_streams(arg_t *arg, asn1c_dep_chainset *deps, int optc,
+                   char **argv) {
+    if(arg->flags & A1C_PRINT_COMPILED) {
 		return asn1c_print_streams(arg);
 	} else {
 		return asn1c_save_streams(arg, deps, optc, argv);
@@ -330,8 +339,9 @@
 }
 
 static int
-asn1c_save_streams(arg_t *arg, asn1c_fdeps_t *deps, int optc, char **argv) {
-	asn1p_expr_t *expr = arg->expr;
+asn1c_save_streams(arg_t *arg, asn1c_dep_chainset *deps, int optc,
+                   char **argv) {
+    asn1p_expr_t *expr = arg->expr;
 	compiler_streams_t *cs = expr->data;
 	out_chunk_t *ot;
 	FILE *fp_c, *fp_h;
@@ -373,7 +383,7 @@
 	if(TQ_FIRST(&(cs->destination[idx].chunks)) && *msg)		\
 		safe_fprintf(fp, "\n/* %s */\n", msg);			\
 	TQ_FOR(ot, &(cs->destination[idx].chunks), next) {		\
-		if(actdep) asn1c_activate_dependency(deps, 0, ot->buf);	\
+		if(actdep) asn1c_activate_dependency(deps, ot->buf, header_id);	\
 		safe_fwrite(ot->buf, ot->len, 1, fp);			\
 	}								\
 } while(0)
@@ -554,7 +564,7 @@
 }
 
 static int
-asn1c_copy_over(arg_t *arg, char *path) {
+asn1c_copy_over(arg_t *arg, const char *path, const char *msg) {
 #ifdef	_WIN32
 	int use_real_copy = 1;
 #else
@@ -595,10 +605,12 @@
 		}
 	}
 
-	safe_fprintf(stderr, "%s %s\t-> %s\n",
-		use_real_copy ? "Copied" : "Symlinked", path, fname);
+    const int has_msg = msg && *msg;
+    safe_fprintf(stderr, "%s %s\t-> %s%s%s\n",
+                 use_real_copy ? "Copied" : "Symlinked", path, fname,
+                 has_msg ? " " : "", has_msg ? msg : "");
 
-	return 1;
+    return 1;
 }
 
 
diff --git a/skeletons/INTEGER.h b/skeletons/INTEGER.h
index 8efd75c..cc760ff 100644
--- a/skeletons/INTEGER.h
+++ b/skeletons/INTEGER.h
@@ -7,7 +7,6 @@
 
 #include <asn_application.h>
 #include <asn_codecs_prim.h>
-#include <NativeInteger.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/skeletons/file-dependencies b/skeletons/file-dependencies
index 012ea6c..76bc301 100644
--- a/skeletons/file-dependencies
+++ b/skeletons/file-dependencies
@@ -69,17 +69,19 @@
 converter-example.c		# A default name for the example transcoder
 
 CODEC-OER:			# THIS IS A SPECIAL SECTION
-oer_decoder.h oer_decoder.c OPEN_TYPE.h # OER decoding support
-oer_encoder.h oer_encoder.c # OER encoding support
-oer_support.h oer_support.c # OER support
+oer_decoder.h
+oer_encoder.h
+oer_support.h
+oer_decoder.h oer_decoder.c OPEN_TYPE.h
+oer_encoder.h oer_encoder.c
+oer_support.h oer_support.c
 OPEN_TYPE.h OPEN_TYPE_oer.c constr_CHOICE.h
-INTEGER_oer.c INTEGER.h
-OCTET_STRING_oer.c
-NativeInteger_oer.c NativeInteger.h
-NativeEnumerated_oer.c NativeEnumerated.h
-constr_SEQUENCE_oer.c constr_SEQUENCE.h
-constr_CHOICE_oer.c
-constr_SET_OF_oer.c constr_SET_OF.h asn_SET_OF.h asn_SET_OF.c
-BIT_STRING_oer.c
+INTEGER.h INTEGER_oer.c
+BIT_STRING.h BIT_STRING_oer.c OCTET_STRING_oer.c
+NativeInteger.h NativeInteger_oer.c
+NativeEnumerated.h NativeEnumerated_oer.c
+constr_CHOICE.h constr_CHOICE_oer.c
+constr_SEQUENCE.h constr_SEQUENCE_oer.c
+constr_SET_OF.h constr_SET_OF_oer.c
 
 CODEC-PER:			# THIS IS A SPECIAL SECTION
diff --git a/tests/tests-asn1c-smoke/check-asn1c-smoke.sh b/tests/tests-asn1c-smoke/check-asn1c-smoke.sh
index d909af2..f374e67 100755
--- a/tests/tests-asn1c-smoke/check-asn1c-smoke.sh
+++ b/tests/tests-asn1c-smoke/check-asn1c-smoke.sh
@@ -30,7 +30,7 @@
 
     cleanup
 
-    asncmd="${top_builddir}/asn1c/asn1c -flink-skeletons -S ${top_srcdir}/skeletons $flags test.asn"
+    asncmd="${top_builddir}/asn1c/asn1c -Wdebug-compiler -flink-skeletons -S ${top_srcdir}/skeletons $flags test.asn"
 
     {
     echo "$asncmd"
@@ -52,9 +52,12 @@
 }
 
 verify_compile_and_link_variants() {
-    for type in INTEGER "ENUMERATED{foo}" NULL BOOLEAN "BIT STRING" \
-                "OBJECT IDENTIFIER" "RELATIVE-OID" "SEQUENCE{f INTEGER}" \
-                "CHOICE{f INTEGER}" "OCTET STRING" IA5String UTF8String \
+    for type in INTEGER "INTEGER(0..1)" "ENUMERATED{foo}" NULL BOOLEAN \
+                "BIT STRING" \
+                "OBJECT IDENTIFIER" "RELATIVE-OID" \
+                "SEQUENCE{f INTEGER}" \
+                "CHOICE{f INTEGER}" \
+                "OCTET STRING" IA5String "IA5String(SIZE(1))" UTF8String \
                 REAL "SET OF INTEGER" "SEQUENCE OF INTEGER"; do
         verify_type_with_variants "$type"
 
@@ -69,6 +72,8 @@
         verify_type_with_variants "$type"
     done
 fi
+set +x
 trap '' EXIT ERR
 
 cleanup
+echo "OK"