Add -gen-autotools option generates example configure.ac and Makefile.am
diff --git a/asn1c/asn1c.c b/asn1c/asn1c.c
index a7011ce..3c4e552 100644
--- a/asn1c/asn1c.c
+++ b/asn1c/asn1c.c
@@ -127,6 +127,8 @@
asn1_compiler_flags |= A1C_GEN_OER;
} else if(strcmp(optarg, "en-example") == 0) {
asn1_compiler_flags |= A1C_GEN_EXAMPLE;
+ } else if(strcmp(optarg, "en-autotools") == 0) {
+ asn1_compiler_flags |= A1C_GEN_AUTOTOOLS_EXAMPLE;
} else {
fprintf(stderr, "-g%s: Invalid argument\n", optarg);
exit(EX_USAGE);
@@ -141,6 +143,8 @@
asn1_compiler_flags &= ~A1C_GEN_OER;
} else if(strcmp(optarg, "o-gen-example") == 0) {
asn1_compiler_flags &= ~A1C_GEN_EXAMPLE;
+ } else if(strcmp(optarg, "o-gen-autotools") == 0) {
+ asn1_compiler_flags &= ~A1C_GEN_AUTOTOOLS_EXAMPLE;
} else {
fprintf(stderr, "-n%s: Invalid argument\n", optarg);
exit(EX_USAGE);
@@ -533,6 +537,7 @@
" -no-gen-OER Do not generate the OER (X.696) support code\n"
" -no-gen-PER Do not generate the PER (X.691) support code\n"
" -no-gen-example Do not generate the ASN.1 format converter example\n"
+" -gen-autotools Generate example top-level configure.ac and Makefile.am\n"
" -pdu={all|auto|Type} Generate PDU table (discover PDUs automatically)\n"
"\n"
diff --git a/libasn1compiler/asn1c_save.c b/libasn1compiler/asn1c_save.c
index 0f7acde..291fc44 100644
--- a/libasn1compiler/asn1c_save.c
+++ b/libasn1compiler/asn1c_save.c
@@ -294,6 +294,58 @@
return 0;
}
+static int
+asn1c__save_autotools_example(const char *destdir,
+ const char *program_makefile_name) {
+ FILE *fd;
+ const char* confac = "configure.ac";
+ const char* makeam = "Makefile.am";
+
+ if ((access(confac, F_OK) != -1)
+ || (access(makeam, F_OK) != -1))
+ {
+ safe_fprintf(stderr, "Refusing to overwrite existing '%s' or '%s'\n", confac, makeam);
+ return -1;
+ }
+
+ fd = asn1c_open_file("", confac, "", 0);
+ if(fd == NULL) {
+ perror(confac);
+ return -1;
+ }
+
+ safe_fprintf(fd,
+ "AC_INIT([asn1convert],[0.1])\n"
+ "AM_INIT_AUTOMAKE([-Werror foreign subdir-objects])\n"
+ "AC_PREREQ([2.62])\n"
+ "AC_PROG_CC\n"
+ "LT_INIT\n"
+ "AM_SILENT_RULES([yes])\n"
+ "AC_CONFIG_FILES([Makefile])\n"
+ "AC_OUTPUT\n");
+ fclose(fd);
+ safe_fprintf(stderr, "Generated minimal example %s\n", confac);
+
+ fd = asn1c_open_file("", makeam, "", 0);
+ if(fd == NULL) {
+ perror(makeam);
+ return -1;
+ }
+
+ safe_fprintf(fd,
+ "bin_PROGRAMS =\n"
+ "lib_LTLIBRARIES =\n"
+ "include %s%s\n\n",
+ destdir, program_makefile_name);
+
+ fclose(fd);
+ safe_fprintf(stderr, "Generated minimal example %s\n", makeam);
+ safe_fprintf(stderr, "\nRun the following to generate a configure script:\n");
+ safe_fprintf(stderr, "$ autoreconf --force --install\n");
+ return 0;
+}
+
+static int
can_generate_pdu_collection(arg_t *arg) {
abuf *buf = generate_pdu_collection(arg);
if(!buf) {
@@ -362,6 +414,11 @@
example_am_makefile,
library_makefile, argc, argv);
if(ret) break;
+
+ if(arg->flags & A1C_GEN_AUTOTOOLS_EXAMPLE) {
+ ret = asn1c__save_autotools_example(destdir, example_am_makefile);
+ if(ret) break;
+ }
}
} while(0);
diff --git a/libasn1compiler/asn1compiler.h b/libasn1compiler/asn1compiler.h
index d05f122..b4af009 100644
--- a/libasn1compiler/asn1compiler.h
+++ b/libasn1compiler/asn1compiler.h
@@ -87,7 +87,11 @@
/*
* Generate converter-example.c and converter-example.mk
*/
- A1C_GEN_EXAMPLE = 0x100000,
+ A1C_GEN_EXAMPLE = 0x100000,
+ /*
+ * Generate top-level configure.ac and Makefile.am
+ */
+ A1C_GEN_AUTOTOOLS_EXAMPLE = 0x200000,
};
/*