diff --git a/src/dxe/dxe3gen.c b/src/dxe/dxe3gen.c index a61d1a1e..a4f9b2a2 100644 --- a/src/dxe/dxe3gen.c +++ b/src/dxe/dxe3gen.c @@ -170,15 +170,9 @@ #ifndef DXE_CC #define DXE_CC "gcc" #endif -#ifndef DXE_AS -#define DXE_AS "as" -#endif #ifndef DXE_AR #define DXE_AR "ar" #endif -#ifndef DXE_LD -#define DXE_LD "ld" -#endif #ifndef DXE_SC #define DXE_SC "dxe.ld" #endif @@ -204,7 +198,7 @@ #define IS_SLASH(path) (((path) == '/') || ((path) == '\\')) #define IS_DIR_SEPARATOR(path) (IS_SLASH(path) || ((path) == ':')) -#define NUMBER_OF_LINKER_ARGS 10 +#define NUMBER_OF_LINKER_ARGS 5 #define NUMBER_OF_ADDITIONAL_LOADED_LIBS 0 #define IS_VALID_CIE(id) ((id) == 0) @@ -311,34 +305,15 @@ static struct }; -static char *libdir; /* build tools */ static char *dxe_cc; /* default: "gcc" */ -static char *dxe_as; /* default: "as" */ static char *dxe_ar; /* default: "ar" */ -static char *dxe_ld; /* default: "ld" */ /* linker script */ static char *dxe_sc; /* default: "dxe.ld" */ - -/* Desc: replaces backslash with slash in a path - * - * In : path string - * Out : path string - * - * Note: - - */ -static void canonicalize_path(char *path) -{ - if (path) - { - char *scan; - - for (scan = path; *scan; scan++) - if (*scan == '\\') - *scan = '/'; - } -} +/* linker-specific arguments. dxe_sc is appended to this */ +#define DEFAULT_LD_ARGS "-Wl,-X,-S,-r,-T," +static char ld_args[sizeof(DEFAULT_LD_ARGS) + FILENAME_MAX]; @@ -353,6 +328,7 @@ static void exit_cleanup(void) { remove(TEMP_O_FILE); remove(TEMP_S_FILE); + remove(TEMP_BASE".exe"); /* produced by stubify */ } @@ -445,23 +421,8 @@ static void process_env(void) const char *e; dxe_cc = (e = getenv("DXE_CC")) ? strdup(e) : strdup(DXE_CC); - dxe_as = (e = getenv("DXE_AS")) ? strdup(e) : strdup(DXE_AS); dxe_ar = (e = getenv("DXE_AR")) ? strdup(e) : strdup(DXE_AR); - dxe_ld = (e = getenv("DXE_LD")) ? strdup(e) : strdup(DXE_LD); dxe_sc = (e = getenv("DXE_SC")) ? strdup(e) : strdup(DXE_SC); - - if ((e = getenv("DXE_LD_LIBRARY_PATH"))) - libdir = strdup(e); - else if ((e = getenv("DJDIR"))) - { - size_t sz = strlen(e) + 5U; - libdir = malloc(sz); - strcpy(libdir, e); - strcat(libdir, "/lib"); - canonicalize_path(libdir); - } - else - libdir = NULL; } @@ -476,22 +437,13 @@ static void process_args(int argc, char *argv[], const char *new_argv[]) { int i, new_argc = NUMBER_OF_LINKER_ARGS; - if (!libdir) - { - fprintf(stderr, "Error: neither DXE_LD_LIBRARY_PATH nor DJDIR are set in environment\n"); - exit(1); - } + sprintf(ld_args, DEFAULT_LD_ARGS"%s", dxe_sc); - new_argv[0] = dxe_ld; - new_argv[1] = "-X"; - new_argv[2] = "-S"; - new_argv[3] = "-r"; - new_argv[4] = "-o"; - new_argv[5] = TEMP_O_FILE; - new_argv[6] = "-L"; - new_argv[7] = libdir; - new_argv[8] = "-T"; - new_argv[9] = dxe_sc; + new_argv[0] = dxe_cc; + new_argv[1] = "-nostdlib"; + new_argv[2] = ld_args; + new_argv[3] = "-o"; + new_argv[4] = TEMP_O_FILE; if (!strcmp(base_name(argv[0]), "dxegen")) /* invoked as `dxegen' */ @@ -588,13 +540,19 @@ static void process_args(int argc, char *argv[], const char *new_argv[]) else { char *dot = strrchr(argv[i], '.'); - new_argv[new_argc++] = argv[i]; if (dot) { if (!strcasecmp(dot, ".o") || !strcasecmp(dot, ".a")) opt.objcount++; else if (!strcasecmp(dot, ".dxe") || !strcasecmp(dot, ".so")) opt.dxefile = argv[i]; + new_argv[new_argc++] = argv[i]; + } + else + { + char *arg = (char *)malloc(strlen(argv[i]) + 5U); + sprintf(arg, "-Wl,%s", argv[i]); + new_argv[new_argc++] = arg; } } } @@ -1476,7 +1434,7 @@ static int make_implib(void) atexit(exit_cleanup); /* Allright, now run the assembler on the resulting file */ - sprintf(cmdbuf, "%s -o %s %s", dxe_as, TEMP_O_FILE, TEMP_S_FILE); + sprintf(cmdbuf, "%s -c -o %s %s", dxe_cc, TEMP_O_FILE, TEMP_S_FILE); if ((rv = system(cmdbuf)) != 0) { if (rv == -1) diff --git a/src/dxe/dxegen.txi b/src/dxe/dxegen.txi index 26d9de8d..41fa6f5b 100644 --- a/src/dxe/dxegen.txi +++ b/src/dxe/dxegen.txi @@ -60,15 +60,12 @@ Usage: @kbd{dxe3gen [-o output.dxe] [options] [object-files] [ld-options]} dxe3gen responds to the following environment variables: DXE_CC: C compiler name. If not set, defaults to gcc for native build -environments, and i586-pc-msdosdjgpp-gcc for cross-build environmlents. -DXE_AS: Assembler name. If not set, defaults to as for native build -environments, and i586-pc-msdosdjgpp-as for cross-build environmlents. +environments, and i586-pc-msdosdjgpp-gcc for cross-build environments. +This is used to invoke the linker and assembler. DXE_AR: Archiver name. If not set, defaults to ar for native build -environments, and i586-pc-msdosdjgpp-ar for cross-build environmlents. -DXE_LD: Linker name. If not set, defaults to ld for native build -environments, and i586-pc-msdosdjgpp-ld for cross-build environmlents. +environments, and i586-pc-msdosdjgpp-ar for cross-build environments. DXE_SC: Path to linker script name. If not set, defaults to dxe.ld. -Passed internally to ld, like 'ld -T dxe.ld' +Passed internally to the linker, like 'gcc -Wl,-T,dxe.ld' @end example @command{dxe3gen} is a utility which allows you to create files which contain diff --git a/src/dxe/makefile b/src/dxe/makefile index cf715867..6bdff8ba 100644 --- a/src/dxe/makefile +++ b/src/dxe/makefile @@ -34,7 +34,7 @@ $(BIN)/dxe3res.exe : $(C) dxe3res.o $(L) CROSS_CC = $(word 1,$(CROSS_GCC)) $(HOSTBIN)/dxegen.exe : dxe3gen.c init1.h init2.h init3.h init4.h init5.h fini1.h fini2.h fini3.h fini4.h fini5.h - $(GCC) -DDXE_LD=\"$(CROSS_LD)\" -DDXE_CC=\"$(CROSS_CC)\" -DDXE_AR=\"$(CROSS_AR)\" -DDXE_AS=\"$(CROSS_AS)\" dxe3gen.c -o $@ + $(GCC) -DDXE_CC=\"$(CROSS_CC)\" -DDXE_AR=\"$(CROSS_AR)\" dxe3gen.c -o $@ clean :: @-$(MISC) rm *.o *.h $(HOSTBIN)/dxegen.exe diff --git a/src/dxe/makefile.dxe b/src/dxe/makefile.dxe index f52323e1..f3676985 100644 --- a/src/dxe/makefile.dxe +++ b/src/dxe/makefile.dxe @@ -2,7 +2,7 @@ # Standalone makefile for building dxe3gen and dxe3res for unixish hosts -CROSS_PREFIX= i586-pc-msdosdjgpp- +CROSS_PREFIX ?= i586-pc-msdosdjgpp- CROSS_CC = $(CROSS_PREFIX)gcc CROSS_AR = $(CROSS_PREFIX)ar CROSS_AS = $(CROSS_PREFIX)as @@ -32,7 +32,7 @@ fini4.h: fini4.o bin2h.exe fini5.h: fini5.o bin2h.exe dxe3gen: dxe3gen.c init1.h init2.h init3.h init4.h init5.h fini1.h fini2.h fini3.h fini4.h fini5.h - $(CC) -O2 -Wall -DDXE_LD=\"$(CROSS_LD)\" -DDXE_CC=\"$(CROSS_CC)\" -DDXE_AR=\"$(CROSS_AR)\" -DDXE_AS=\"$(CROSS_AS)\" dxe3gen.c -o $@ + $(CC) -O2 -Wall -DDXE_CC=\"$(CROSS_CC)\" -DDXE_AR=\"$(CROSS_AR)\" dxe3gen.c -o $@ dxegen: dxe3gen ln -s dxe3gen dxegen