diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index c11d2a3..7ab5484 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -178,6 +178,8 @@ d_init_options (unsigned int, cl_decoded_option *decoded_options) // extra D-specific options flag_emit_templates = TEnormal; + flag_pragma_lib_filename = 0; + flag_pragma_lib_file_created = 0; } /* Initialize options structure OPTS. */ @@ -529,6 +531,13 @@ d_handle_option (size_t scode, const char *arg, int value, global.params.useUnitTests = value; break; + case OPT_fwrite_pragma_libs_: { + // ah, let it leak! + char *tmp = new char[strlen(arg)+1]; + strcpy(tmp, arg); + flag_pragma_lib_filename = tmp; + } break; + case OPT_fversion_: if (ISDIGIT (arg[0])) { diff --git a/gcc/d/d-objfile.cc b/gcc/d/d-objfile.cc index 0a44a86..2b694ec 100644 --- a/gcc/d/d-objfile.cc +++ b/gcc/d/d-objfile.cc @@ -160,10 +160,32 @@ AttribDeclaration::toObjFile (int) void PragmaDeclaration::toObjFile (int) { + if (ident == Id::lib && flag_pragma_lib_filename) { + Expression *e = (*args)[0]; + StringExp *se = e->toString(); + if (se->len > 0) { + char *name = new char[se->len + 1]; + memcpy(name, se->string, se->len); + name[se->len] = 0; + if (flag_pragma_lib_filename && flag_pragma_lib_file_created >= 0) { + FILE *fo = fopen(flag_pragma_lib_filename, (flag_pragma_lib_file_created ? "a" : "w")); + if (fo) { + flag_pragma_lib_file_created = 1; // file successfully created + fprintf(fo, "-l\"%s\"\n", name); + fclose(fo); + } else { + flag_pragma_lib_file_created = -1; // error occured, don't try to do this anymore + warning (loc, "can't write pragma(lib) file '%s'", flag_pragma_lib_filename); + } + } + delete [] name; + } + } + if (!global.params.ignoreUnsupportedPragmas) { - if (ident == Id::lib) - warning (loc, "pragma(lib) not implemented"); + if (ident == Id::lib && !flag_pragma_lib_filename) + warning (loc, "pragma(lib) not implemented (you can use -fwrite-pragma-libs= to write it to )"); else if (ident == Id::startaddress) warning (loc, "pragma(startaddress) not implemented"); } diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt index 5df6e80..4d51d22 100644 --- a/gcc/d/lang.opt +++ b/gcc/d/lang.opt @@ -23,6 +23,12 @@ D Variable int flag_emit_templates +Variable +char *flag_pragma_lib_filename + +Variable +int flag_pragma_lib_file_created + debuglib= Driver Joined @@ -156,6 +162,10 @@ fversion= D Joined RejectNegative -fversion= Compile in version code >= or identified by +fwrite-pragma-libs= +D Joined RejectNegative +-fwrite-pragma-libs= write all libraries from pragma(lib) to + fXf= D Joined RejectNegative -fXf= Write JSON file to