bjh 01/04/02 08:00:52 Modified: build aplibtool.c Log: Add ability to generate .def files on the fly for dlls that export all symbols available in the supplied object files using the --export-all option. It will NOT export symbols from linked in libraries though. Revision Changes Path 1.2 +91 -7 apr/build/aplibtool.c Index: aplibtool.c =================================================================== RCS file: /home/cvs/apr/build/aplibtool.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- aplibtool.c 2001/03/29 15:45:26 1.1 +++ aplibtool.c 2001/04/02 15:00:51 1.2 @@ -59,18 +59,20 @@ #include #include -char silent = 0; -char shared = 0; -enum mode_t { mCompile, mLink }; -enum output_type_t { otGeneral, otObject, otProgram, otStaticLibrary, otDynamicLibrary }; - typedef char bool; #define false 0 #define true (!false) +bool silent = false; +bool shared = false; +bool export_all = false; +enum mode_t { mCompile, mLink }; +enum output_type_t { otGeneral, otObject, otProgram, otStaticLibrary, otDynamicLibrary }; + #ifdef __EMX__ # define SHELL_CMD "sh" # define CC "gcc" +# define GEN_EXPORTS "emxexp" # define SHARE_SW "-Zdll -Zmtd" # define USE_OMF true # define TRUNCATE_DLL_NAME @@ -96,9 +98,12 @@ int num_args; enum mode_t mode; enum output_type_t output_type; + char *output_name; char *stub_name; char *tmp_dirs[1024]; int num_tmp_dirs; + char *obj_files[1024]; + int num_obj_files; } cmd_data_t; void parse_args(int argc, char *argv[], cmd_data_t *cmd_data); @@ -111,6 +116,8 @@ int execute_command(cmd_data_t *cmd_data); char *shell_esc(const char *str); void cleanup_tmp_dirs(cmd_data_t *cmd_data); +void generate_def_file(cmd_data_t *cmd_data); +char *nameof(char *fullpath); int main(int argc, char *argv[]) @@ -195,6 +202,8 @@ } } else if (strcmp(var, "shared") == 0) { shared = true; + } else if (strcmp(var, "export-all") == 0) { + export_all = true; } else { return false; } @@ -259,6 +268,7 @@ strcpy(newarg, arg); strcpy(newarg + (ext - arg), OBJECT_EXT); cmd_data->arglist[cmd_data->num_args++] = newarg; + cmd_data->obj_files[cmd_data->num_obj_files++] = newarg; return true; } @@ -283,7 +293,7 @@ if (cmd_data->stub_name == NULL) { cmd_data->stub_name = (char *)malloc(strlen(arg) + 4); strcpy(cmd_data->stub_name, arg); - strcpy(strrchr(cmd_data->stub_name, '.') + 1, shared ? "slo" : "lo"); + strcpy(strrchr(cmd_data->stub_name, '.') + 1, "lo"); } } @@ -324,6 +334,7 @@ strcpy(newarg, arg); strcat(newarg, EXE_EXT); cmd_data->arglist[cmd_data->num_args++] = newarg; + cmd_data->output_name = newarg; return true; } @@ -363,6 +374,7 @@ } #endif + cmd_data->output_name = newarg; return true; } @@ -374,6 +386,7 @@ ext = strrchr(newarg, '.') + 1; strcpy(ext, OBJECT_EXT); cmd_data->arglist[cmd_data->num_args++] = newarg; + cmd_data->output_name = newarg; return true; } @@ -430,7 +443,7 @@ if (ext) { if (strcmp(ext, "h") == 0 || strcmp(ext, "c") == 0) { - /* ignore source files, they don't belong in a library */ + /* ignore source files, they don't belong in a library */ cmd_data->arglist[a] = NULL; } @@ -454,6 +467,10 @@ } } } + + if (export_all) { + generate_def_file(cmd_data); + } } #if USE_OMF @@ -617,4 +634,71 @@ for (d=0; d < cmd_data->num_tmp_dirs; d++) { cleanup_tmp_dir(cmd_data->tmp_dirs[d]); } +} + + + +void generate_def_file(cmd_data_t *cmd_data) +{ + char def_file[1024]; + FILE *hDef; + char *export_args[1024]; + int num_export_args = 0; + char *cmd; + int cmd_size = 0; + int a; + + if (cmd_data->output_name) { + strcpy(def_file, cmd_data->output_name); + strcat(def_file, ".def"); + hDef = fopen(def_file, "w"); + + if (hDef != NULL) { + fprintf(hDef, "LIBRARY %s INITINSTANCE\n", nameof(cmd_data->output_name)); + fprintf(hDef, "EXPORTS\n"); + fclose(hDef); + + for (a=0; a < cmd_data->num_obj_files; a++) { + cmd_size += strlen(cmd_data->obj_files[a]) + 1; + } + + cmd_size += strlen(GEN_EXPORTS) + strlen(def_file) + 3; + cmd = (char *)malloc(cmd_size); + strcpy(cmd, GEN_EXPORTS); + + for (a=0; a < cmd_data->num_obj_files; a++) { + strcat(cmd, " "); + strcat(cmd, cmd_data->obj_files[a] ); + } + + strcat(cmd, ">>"); + strcat(cmd, def_file); + puts(cmd); + export_args[num_export_args++] = SHELL_CMD; + export_args[num_export_args++] = "-c"; + export_args[num_export_args++] = cmd; + export_args[num_export_args++] = NULL; + spawnvp(P_WAIT, export_args[0], export_args); + cmd_data->arglist[cmd_data->num_args++] = strdup(def_file); + } + } +} + + + +char *nameof(char *fullpath) +{ + char *name = strrchr(fullpath, '/'); + + if (name == NULL) { + name = strrchr(fullpath, '\\'); + } + + if (name == NULL) { + name = fullpath; + } else { + name++; + } + + return name; }