aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLev Walkin <vlm@lionet.info>2017-09-26 22:54:44 -0700
committerLev Walkin <vlm@lionet.info>2017-09-26 22:54:44 -0700
commit8a85b36d93ab82ccad63629dc8061e2351ab6b1e (patch)
tree7818216f8bc9f6a22948306d04502d9105c89a29
parent478819d6eb3dc3bd74c643ef439778fd3f339e33 (diff)
split Makefile.am.sample into Makefile.am.example and Makefile.am.libasncodecs
-rw-r--r--.gitignore2
-rwxr-xr-xexamples/sample.makefile.regen29
-rw-r--r--libasn1compiler/asn1c_fdeps.c10
-rw-r--r--libasn1compiler/asn1c_fdeps.h2
-rw-r--r--libasn1compiler/asn1c_save.c224
5 files changed, 160 insertions, 107 deletions
diff --git a/.gitignore b/.gitignore
index c8323e5b..0fc92ec9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -60,7 +60,9 @@ doc/docsrc/*.xdv
/examples/*/*.c
/examples/*/*.h
/examples/*/*dump
+/examples/*/lib*.a
/examples/*/.tmp.*
+/examples/*/Makefile.am.libasncodec
!/examples/*/Makefile
!/examples/*/config.h
diff --git a/examples/sample.makefile.regen b/examples/sample.makefile.regen
index 67f282a7..a84132d0 100755
--- a/examples/sample.makefile.regen
+++ b/examples/sample.makefile.regen
@@ -1,14 +1,11 @@
#!/bin/sh
#
# This script attempts to compile the given ASN.1 specification and then
-# transforms the resulting Makefile.am.sample tailored to that specification
+# transforms the resulting Makefile.am.example tailored to that specification
# into a customized Makefile.
#
# The information which is necessary for this script is passed from the
# Makefile which is going to be replaced with an updated Makefile.
-# This is called "boot-strapping" and is frequently the source of inside jokes.
-#
-# $Id$
#
if test -z "$ASN1PDU" \
@@ -33,20 +30,21 @@ else
asn1c ${CMDOPTS} || exit $?
fi
-if test ! -f Makefile.am.sample ; then
- echo "Makefile.am.sample is missing"
+if test ! -f Makefile.am.example ; then
+ echo "Makefile.am.example is missing"
exit 1
fi
-EXTRA_CPPFLAGS="-DJUNKTEST -D_DEFAULT_SOURCE ${CPPFLAGS}"
-test -f config.h && EXTRA_CPPFLAGS="-DHAVE_CONFIG_H ${EXTRA_CPPFLAGS}"
-test -n "$TITLE" && EXTRA_CPPFLAGS="-DASN_CONVERTER_TITLE=\"$TITLE\" ${EXTRA_CPPFLAGS}"
+EXTRA_CFLAGS="-DJUNKTEST -D_DEFAULT_SOURCE"
+test -f config.h && EXTRA_CFLAGS="-DHAVE_CONFIG_H ${EXTRA_CFLAGS}"
+test -n "$TITLE" && EXTRA_CFLAGS="-DASN_CONVERTER_TITLE=\"$TITLE\" ${EXTRA_CFLAGS}"
set -x
-cat Makefile.am.sample \
- | sed -e "s/^CPPFLAGS += /CPPFLAGS += ${EXTRA_CPPFLAGS} /" \
- | sed -e "s/^all: /all: maybe-wip-pause ${ASN1PDU}.c /" \
- | sed -e "s/progname/${PROGNAME}/" \
+cat Makefile.am.example \
+ | sed -e "s/^include /-include /" \
+ | sed -e "s/^TARGET = converter-example/TARGET = ${PROGNAME}/" \
+ | sed -e "s/^CFLAGS += /CFLAGS += ${EXTRA_CFLAGS} /" \
+ | sed -e "s/^all: /all: maybe-wip-pause ${ASN1PDU}.c /" \
> Makefile.$$
set +x
@@ -62,7 +60,6 @@ set +x
echo " ASN1MODULES=\"${ASN1MODULES}\" \\"
echo " ASN1PDU=${ASN1PDU} \\"
echo " PROGNAME=${PROGNAME} \\"
- echo " CPPFLAGS=\"${CPPFLAGS}\" \\"
echo " $0"
echo
echo 'check: ${TARGET} check-ber check-xer check-oer check-per'
@@ -152,12 +149,12 @@ set +x
echo ' rm -f $(ASN_MODULE_SOURCES)'
echo ' rm -f $(ASN_MODULE_HEADERS)'
echo ' rm -f $(ASN_CONVERTER_SOURCES) $(ASN_CONVERTER_HEADERS)'
- echo " rm -f Makefile.am.sample"
+ echo " rm -f Makefile.am.example"
) >> Makefile.$$
set -x
mv Makefile.$$ Makefile || exit $?
-rm Makefile.am.sample || exit $?
+rm Makefile.am.example || exit $?
set +x
echo
diff --git a/libasn1compiler/asn1c_fdeps.c b/libasn1compiler/asn1c_fdeps.c
index c0882bee..de9cd760 100644
--- a/libasn1compiler/asn1c_fdeps.c
+++ b/libasn1compiler/asn1c_fdeps.c
@@ -178,10 +178,9 @@ asn1c_dep_add(asn1c_fdeps_t *deps, asn1c_fdeps_t *d) {
}
asn1c_fdeps_t *
-asn1c_deps_makelist(asn1c_fdeps_t *deps) {
+asn1c_deps_flatten(const asn1c_fdeps_t *deps) {
asn1c_fdeps_t *dlist;
asn1c_fdeps_t *d;
- int i;
if(!deps) {
errno = EINVAL;
@@ -198,11 +197,10 @@ asn1c_deps_makelist(asn1c_fdeps_t *deps) {
}
}
- for(i = 0; i < deps->el_count; i++) {
- int j;
- d = asn1c_deps_makelist(deps->elements[i]);
+ for(int i = 0; i < deps->el_count; i++) {
+ d = asn1c_deps_flatten(deps->elements[i]);
assert(!d->filename);
- for(j = 0; j < d->el_count; j++) {
+ for(int j = 0; j < d->el_count; j++) {
if(asn1c_dep_add(dlist, d->elements[j])) {
d->elements[j] = 0;
}
diff --git a/libasn1compiler/asn1c_fdeps.h b/libasn1compiler/asn1c_fdeps.h
index 8b7c7cd9..3be9e803 100644
--- a/libasn1compiler/asn1c_fdeps.h
+++ b/libasn1compiler/asn1c_fdeps.h
@@ -25,7 +25,7 @@ asn1c_fdeps_t *asn1c_read_file_dependencies(arg_t *arg, const char *datadir);
int asn1c_activate_dependency(asn1c_fdeps_t *deps, asn1c_fdeps_t *cur,
const char *data);
-asn1c_fdeps_t *asn1c_deps_makelist(asn1c_fdeps_t *deps);
+asn1c_fdeps_t *asn1c_deps_flatten(const asn1c_fdeps_t *deps);
void asn1c_deps_freelist(asn1c_fdeps_t *deps);
#endif /* ASN1C_FDEPS_H */
diff --git a/libasn1compiler/asn1c_save.c b/libasn1compiler/asn1c_save.c
index 3ce7d48a..f5074449 100644
--- a/libasn1compiler/asn1c_save.c
+++ b/libasn1compiler/asn1c_save.c
@@ -45,42 +45,15 @@ static void pdu_collection_print_unused_types(arg_t *arg);
static const char *generate_pdu_C_definition(void);
static void asn1c__cleanup_pdu_type(void);
-int
-asn1c_save_compiled_output(arg_t *arg, const char *datadir,
- int argc, int optc, char **argv) {
- asn1c_fdeps_t *deps = 0;
+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;
asn1p_module_t *mod;
- FILE *mkf; /* Makefile.am.sample */
- int i;
-
- deps = asn1c_read_file_dependencies(arg, datadir);
- if(!deps && datadir) {
- WARNING("Cannot read file-dependencies information "
- "from %s\n", datadir);
- }
+ FILE *mkf;
- TQ_FOR(mod, &(arg->asn->modules), mod_next) {
- TQ_FOR(arg->expr, &(mod->members), next) {
- if(asn1_lang_map[arg->expr->meta_type]
- [arg->expr->expr_type].type_cb) {
- if(asn1c_dump_streams(arg, deps, optc, argv))
- return -1;
- }
- }
- }
-
- /*
- * Dump out the Makefile template and the rest of the support code.
- */
- if((arg->flags & A1C_PRINT_COMPILED)
- || (arg->flags & A1C_OMIT_SUPPORT_CODE)) {
- return 0; /* Finished */
- }
-
- mkf = asn1c_open_file("Makefile.am", ".sample", 0);
+ mkf = asn1c_open_file(makefile_name, "", 0);
if(mkf == NULL) {
- perror("Makefile.am.sample");
+ perror(makefile_name);
return -1;
}
@@ -107,9 +80,9 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
safe_fprintf(mkf, "\n\n");
/*
- * Move necessary skeleton files and add them to Makefile.am.sample.
+ * Move necessary skeleton files and add them to Makefile.am.targets.
*/
- dlist = asn1c_deps_makelist(deps);
+ dlist = asn1c_deps_flatten(deps);
if(dlist) {
char buf[8129];
char *dir_end;
@@ -120,8 +93,7 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
dir_end = buf + dlen;
*dir_end++ = '/';
- for(i = 0; i < dlist->el_count; i++) {
- char *what_class; /* MODULE or CONVERTER */
+ for(int i = 0; i < dlist->el_count; i++) {
char *what_kind; /* HEADERS or SOURCES */
char *fname = dlist->elements[i]->filename;
char *dotH;
@@ -135,73 +107,157 @@ asn1c_save_compiled_output(arg_t *arg, const char *datadir,
return -1;
}
- /* MODULE data versus CONVERTER data */
- switch(dlist->elements[i]->usage) {
- case FDEP_CONVERTER: what_class = "CONVERTER"; break;
- default: what_class= "MODULE"; break;
+ /* 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_%s_%s+=%s\n",
- what_class, what_kind, fname);
}
- asn1c_deps_freelist(deps);
asn1c_deps_freelist(dlist);
}
- if(need_to_generate_pdu_collection(arg)) {
- safe_fprintf(mkf, "ASN_CONVERTER_SOURCES+=pdu_collection.c\n");
- if(generate_pdu_collection_file(arg))
- return -1;
- }
+ safe_fprintf(
+ mkf,
+ "\n"
+ "ASN_MODULE_CFLAGS=%s%s",
+ (arg->flags & A1C_GEN_OER) ? "" : "-DASN_DISABLE_OER_SUPPORT ",
+ (arg->flags & A1C_GEN_PER) ? "" : "-DASN_DISABLE_PER_SUPPORT ");
+
+ safe_fprintf(
+ mkf,
+ "\n\n"
+ "lib_LTLIBRARIES=libasncodec.la\n"
+ "libasncodec_la_SOURCES="
+ "$(ASN_MODULE_SOURCES) $(ASN_MODULE_HEADERS)\n"
+ "libasncodec_la_CFLAGS=$(ASN_MODULE_CFLAGS)\n");
+ fclose(mkf);
+ safe_fprintf(stderr, "Generated Makefile.am.targets\n");
+
+ return 0;
+}
+static int
+asn1c__save_example_makefile(arg_t *arg, const asn1c_fdeps_t *deps,
+ const char *makefile_name,
+ const char *library_makefile_name, int argc,
+ char **argv) {
+ asn1c_fdeps_t *dlist;
+ FILE *mkf;
+
+ mkf = asn1c_open_file(makefile_name, "", 0);
+ if(mkf == NULL) {
+ perror(makefile_name);
+ return -1;
+ }
safe_fprintf(
mkf,
- "\n\n"
- "lib_LTLIBRARIES=libsomething.la\n"
- "libsomething_la_SOURCES="
- "$(ASN_MODULE_SOURCES) $(ASN_MODULE_HEADERS)\n"
- "\n"
- "# This file may be used as an input for make(3)\n"
- "# Remove the lines below to convert it into a pure .am file\n"
- "TARGET = progname\n"
+ "include %s\n\n"
+ "TARGET = converter-example\n"
+ "ASN_LIBRARY=libasncodec.a\n"
"LIBS += -lm\n"
- "CPPFLAGS += %s%s%s%s-I.\n"
- "OBJS=${ASN_MODULE_SOURCES:.c=.o}"
- " ${ASN_CONVERTER_SOURCES:.c=.o}\n"
- "\nall: $(TARGET)\n"
- "\n$(TARGET): ${OBJS}"
- "\n\t$(CC) $(CFLAGS) $(CPPFLAGS) -o $(TARGET) ${OBJS} $(LDFLAGS) $(LIBS)\n"
- "\n.SUFFIXES:"
- "\n.SUFFIXES: .c .o\n"
- "\n.c.o:"
- "\n\t$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<\n"
- "\nclean:"
- "\n\trm -f $(TARGET)"
- "\n\trm -f $(OBJS)\n"
- "\nregen: regenerate-from-asn1-source\n"
- "\nregenerate-from-asn1-source:\n\t",
- (arg->flags & A1C_GEN_OER) ? "" : "-DASN_DISABLE_OER_SUPPORT ",
- (arg->flags & A1C_GEN_PER) ? "" : "-DASN_DISABLE_PER_SUPPORT ",
+ "CFLAGS += $(ASN_MODULE_CFLAGS) %s%s-I.\n"
+ "ASN_CONVERTER_SOURCES = ",
+ library_makefile_name,
(arg->flags & A1C_PDU_TYPE) ? generate_pdu_C_definition() : "",
need_to_generate_pdu_collection(arg) ? "-DASN_PDU_COLLECTION " : "");
- for(i = 0; i < argc; i++)
+ dlist = asn1c_deps_flatten(deps);
+ 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);
+ }
+ }
+ asn1c_deps_freelist(dlist);
+ }
+
+ if(need_to_generate_pdu_collection(arg)) {
+ safe_fprintf(mkf, "\\\n\tpdu_collection.c");
+ if(generate_pdu_collection_file(arg))
+ return -1;
+ }
+
+ safe_fprintf(
+ mkf,
+ "\n\nall: $(TARGET)\n"
+ "\n$(TARGET): $(ASN_LIBRARY) $(ASN_CONVERTER_SOURCES:.c=.o)"
+ "\n\t$(CC) $(CFLAGS) $(CPPFLAGS) -o $(TARGET) $(ASN_CONVERTER_SOURCES:.c=.o) $(LDFLAGS) $(ASN_LIBRARY) $(LIBS)\n"
+ "\n$(ASN_LIBRARY): $(ASN_MODULE_SOURCES:.c=.o)"
+ "\n\t$(AR) rcs $@ $^\n"
+ "\n.SUFFIXES:"
+ "\n.SUFFIXES: .c .o\n"
+ "\n.c.o:"
+ "\n\t$(CC) $(CFLAGS) -o $@ -c $<\n"
+ "\nclean:"
+ "\n\trm -f $(TARGET) $(ASN_LIBRARY)"
+ "\n\trm -f $(ASN_MODULE_SOURCES:.c=.o) $(ASN_CONVERTER_SOURCES:.c=.o)\n"
+ "\nregen: regenerate-from-asn1-source\n"
+ "\nregenerate-from-asn1-source:\n\t");
+
+ for(int i = 0; i < argc; i++)
safe_fprintf(mkf, "%s%s", i ? " " : "", argv[i]);
safe_fprintf(mkf, "\n\n");
fclose(mkf);
- safe_fprintf(stderr, "Generated Makefile.am.sample\n");
+ safe_fprintf(stderr, "Generated %s\n", makefile_name);
+ return 0;
+}
- asn1c__cleanup_pdu_type();
+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;
+
+ do {
+ asn1p_module_t *mod;
+
+ deps = asn1c_read_file_dependencies(arg, datadir);
+ if(!deps && datadir) {
+ WARNING(
+ "Cannot read file-dependencies information "
+ "from %s\n",
+ datadir);
+ }
- return 0;
+ TQ_FOR(mod, &(arg->asn->modules), mod_next) {
+ TQ_FOR(arg->expr, &(mod->members), next) {
+ if(asn1_lang_map[arg->expr->meta_type][arg->expr->expr_type]
+ .type_cb) {
+ if(asn1c_dump_streams(arg, deps, optc, argv)) break;
+ }
+ }
+ }
+
+ /*
+ * Dump out the Makefile template and the rest of the support code.
+ */
+ if((arg->flags & A1C_PRINT_COMPILED)
+ || (arg->flags & A1C_OMIT_SUPPORT_CODE)) {
+ ret = 0; /* Success */
+ break;
+ }
+
+ ret = asn1c__save_library_makefile(arg, deps, datadir,
+ "Makefile.am.libasncodec");
+ if(ret) break;
+ ret = asn1c__save_example_makefile(arg, deps, "Makefile.am.example",
+ "Makefile.am.libasncodec", argc, argv);
+ if(ret) break;
+ } while(0);
+
+ asn1c_deps_freelist(deps);
+ asn1c__cleanup_pdu_type();
+
+ return ret;
}
/*