Skip to content

Instantly share code, notes, and snippets.

@lpproj
Created June 18, 2020 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpproj/85f333d4602dc3bde0a677700e17efe0 to your computer and use it in GitHub Desktop.
Save lpproj/85f333d4602dc3bde0a677700e17efe0 to your computer and use it in GitHub Desktop.
to build djgpp (djgpp-cvs) on msys2 with cross-gcc (i586-pc-msdosdjgpp-gcc for Windows):
$ MAKE=mingw32-make mingw32-make CROSS_BUILD=1 CROSS_PREFIX=/djgpp/bin/i586-pc-msdosdjgpp-
note:
* use mingw32-make (instead of msys2-version of `make.exe')
* need to specify CROSS_BUILD=1 manualy
* may need standalone version of djgpp-mingw-gcc
diff --git a/src/djasm/djasm.y b/src/djasm/djasm.y
index 5657b990..ecc0bee6 100644
--- a/src/djasm/djasm.y
+++ b/src/djasm/djasm.y
@@ -21,6 +21,11 @@
#ifndef O_BINARY
#define O_BINARY 0
#endif
+#ifdef __MINGW32__
+# define FOPEN_MODE_WT "wb"
+#else
+# define FOPEN_MODE_WT "w"
+#endif
#undef _POSIX_SOURCE
#include "../../include/coff.h"
@@ -1520,7 +1525,7 @@ int main(int argc, char **argv)
case OUT_h:
case OUT_inc:
case OUT_s:
- outfile = fopen(outfilename, "w");
+ outfile = fopen(outfilename, FOPEN_MODE_WT);
break;
}
if (outfile == 0)
@@ -1616,7 +1621,7 @@ int main(int argc, char **argv)
if (argc > 3)
{
- FILE *mapfile = fopen(argv[3], "w");
+ FILE *mapfile = fopen(argv[3], FOPEN_MODE_WT);
lineaddr_s *laddr;
fprintf(mapfile, "%#x bytes generated, %#x bytes in file, %#x bytes total, %d symbols\n",
generated_bytes, bsspc, pc, symcount);
diff --git a/src/dxe/dxe3gen.c b/src/dxe/dxe3gen.c
index a61d1a1e..b11850e3 100644
--- a/src/dxe/dxe3gen.c
+++ b/src/dxe/dxe3gen.c
@@ -24,6 +24,11 @@
#include <stdlib.h>
#include <string.h>
+#ifdef __MINGW32__
+# define FOPEN_MODE_NOTBIN "b"
+#else
+# define FOPEN_MODE_NOTBIN
+#endif
#if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
# define __gnuc_extension__ __extension__
@@ -1406,10 +1411,10 @@ static int make_implib(void)
* resolution table resides in the very same source with the wrappers,
* otherwise the linker might get smart... and get rid of it!
*/
- omode = "a";
+ omode = "a" FOPEN_MODE_NOTBIN;
}
else
- omode = "w";
+ omode = "w" FOPEN_MODE_NOTBIN;
/* `omode' holds the fopen mode */
if ((implib = fopen(TEMP_S_FILE, omode)) == NULL)
diff --git a/src/dxe/dxe3res.c b/src/dxe/dxe3res.c
index daf69059..fccabda8 100644
--- a/src/dxe/dxe3res.c
+++ b/src/dxe/dxe3res.c
@@ -30,6 +30,11 @@
#define ACCESS(f) (access(f, R_OK) == 0)
#endif
+#ifdef __MINGW32__
+# define FOPEN_MODE_WT "wb"
+#else
+# define FOPEN_MODE_WT "w"
+#endif
typedef struct {
@@ -469,7 +474,7 @@ static int resolve(int argc, char **argv)
if (opt.outfile == NULL)
f = stdout;
- else if ((f = fopen(opt.outfile, "w")) == NULL)
+ else if ((f = fopen(opt.outfile, FOPEN_MODE_WT)) == NULL)
{
perror(opt.outfile);
CLEANUP(4);
diff --git a/src/libc/stubs/mkstubs.c b/src/libc/stubs/mkstubs.c
index 8741e19e..b8475426 100644
--- a/src/libc/stubs/mkstubs.c
+++ b/src/libc/stubs/mkstubs.c
@@ -8,6 +8,12 @@
#include <stdlib.h>
#include <unistd.h>
+#ifdef __MINGW32__
+# define FOPEN_MODE_WT "wb"
+#else
+# define FOPEN_MODE_WT "w"
+#endif
+
int
main(int argc, char **argv)
{
@@ -25,8 +31,8 @@ main(int argc, char **argv)
break;
remove(fn);
}
- mk = fopen("makefil2", "w");
- oh = fopen("makefile.oh", "w");
+ mk = fopen("makefil2", FOPEN_MODE_WT);
+ oh = fopen("makefile.oh", FOPEN_MODE_WT);
fprintf(mk, "TOP=..\n\n");
stubs = fopen(argv[1], "r");
@@ -40,7 +46,7 @@ main(int argc, char **argv)
continue;
sprintf(fn, "stub%04d.S", i);
- as = fopen(fn, "w");
+ as = fopen(fn, FOPEN_MODE_WT);
/* Blank line at start of output file is added to work around
* gcc-3.0 preprocessor bug. See:
*
diff --git a/src/makefile.cfg b/src/makefile.cfg
index 11bb06db..31e4e47f 100644
--- a/src/makefile.cfg
+++ b/src/makefile.cfg
@@ -5,7 +5,7 @@ include makefile.def
GCC_MAJOR := $(word 3, $(shell ./misc.exe | $(CROSS_GCC) -E -dD -x c - | egrep 'define\ *__GNUC__'))
GCC_MINOR := $(word 3, $(shell ./misc.exe | $(CROSS_GCC) -E -dD -x c - | egrep 'define\ *__GNUC_MINOR__'))
-MTUNE := -mcpu=i586
+MTUNE := -mcpu=i386
IQUOTE := -I. -I-
ifeq ($(GCC_MAJOR),)
@@ -16,13 +16,13 @@ endif
ifeq ($(filter 2 3,$(GCC_MAJOR)),)
# we have gcc >= 4.x
-MTUNE := -mtune=i586
+MTUNE := -mtune=generic
IQUOTE := -iquote .
endif
ifeq ($(GCC_MAJOR),3)
ifeq ($(GCC_MINOR),4)
-MTUNE := -mtune=i586
+MTUNE := -mtune=generic
endif
endif
diff --git a/src/makemake.c b/src/makemake.c
index a1ed2111..dcc7b2d6 100644
--- a/src/makemake.c
+++ b/src/makemake.c
@@ -1,6 +1,10 @@
/* Copyright (C) 2015 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+#ifdef __MINGW32__
+# include <windows.h>
+# include <direct.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -15,6 +19,29 @@ char top_dir[2000];
char path[2000];
int do_oh_files = 0;
+#ifdef __MINGW32__
+static char *getcwd_without_driveletter(char *buf, size_t buflen)
+{
+ char *r_s = _getcwd(buf, buflen);
+ if (r_s) {
+ char *s = r_s;
+ size_t n = strlen(s);
+ if (n > 2 && r_s[1] == ':') {
+ memmove(s, s+2, n - 2 + 1); /* strip drive prefix */
+ }
+ while(*s) {
+ if (*s == '\\') *s = '/';
+ s = (char *)CharNextA(s);
+ }
+ }
+ return r_s;
+}
+# define getcwd getcwd_without_driveletter
+# define FOPEN_MODE_WT "wb"
+#else
+# define FOPEN_MODE_WT "w"
+#endif
+
void
process_makefile(char *path_end)
{
@@ -195,11 +222,11 @@ main(int argc, char **argv)
printf("makemake: scanning %s for makefiles\n", notepwd);
if (!do_oh_files)
- mf = fopen("makefile.sub", "w");
+ mf = fopen("makefile.sub", FOPEN_MODE_WT);
else
{
- oi = fopen("makefile.oi", "w");
- rf = fopen("makefile.rf2", "w");
+ oi = fopen("makefile.oi", FOPEN_MODE_WT);
+ rf = fopen("makefile.rf2", FOPEN_MODE_WT);
}
if (!do_oh_files)
diff --git a/src/misc.c b/src/misc.c
index 19738679..5acb4ff1 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -9,6 +9,14 @@
/* Miscellaneous things that are hard to do the same
between Unix and MS-DOS */
+#ifdef __MINGW32__
+# include <direct.h>
+# define FOPEN_MODE_WT "wb"
+# define mkdir(path,mode) _mkdir(path)
+#else
+# define FOPEN_MODE_WT "w"
+#endif
+
int
main(int argc, char **argv)
{
@@ -26,7 +34,7 @@ main(int argc, char **argv)
f = stdout;
else
{
- f = fopen(argv[2], "w");
+ f = fopen(argv[2], FOPEN_MODE_WT);
if (f == 0)
{
perror(argv[2]);
diff --git a/src/mkdoc/mkdoc.cc b/src/mkdoc/mkdoc.cc
index a5c4bf3e..63904fd3 100644
--- a/src/mkdoc/mkdoc.cc
+++ b/src/mkdoc/mkdoc.cc
@@ -17,6 +17,12 @@
#include <string>
+#ifdef __MINGW32__
+# define FOPEN_MODE_WT "wb"
+#else
+# define FOPEN_MODE_WT "w"
+#endif
+
static char *dj_strlwr(char *s)
{
char *p = s;
@@ -918,7 +924,7 @@ int main (int argc, char **argv)
scan_directory(argv[1]);
- co = fopen(argv[2], "w");
+ co = fopen(argv[2], FOPEN_MODE_WT);
// Functional Categories
fputs("@c -----------------------------------------------------------------------------\n"
diff --git a/src/stub/stub2inc.c b/src/stub/stub2inc.c
index 91cfeafd..30206051 100644
--- a/src/stub/stub2inc.c
+++ b/src/stub/stub2inc.c
@@ -5,6 +5,12 @@
#include <string.h>
#include <ctype.h>
+#ifdef __MINGW32__
+# define FOPEN_MODE_WT "wb"
+#else
+# define FOPEN_MODE_WT "w"
+#endif
+
static FILE *
sfopen(const char *c, const char *m)
{
@@ -25,7 +31,7 @@ main(int argc, char **argv)
int addr, tag=0;
FILE *inf = sfopen(argv[1], "r");
FILE *sf = sfopen(argv[2], "r");
- FILE *outf = sfopen(argv[3], "w");
+ FILE *outf = sfopen(argv[3], FOPEN_MODE_WT);
fprintf(outf, "/* Generated by stub2inf - DO NOT EDIT */\n");
fprintf(outf, "#ifndef __dj_include_stub_h__\n#define __dj_include_stub_h__\n\n");
while (1)
diff --git a/src/utils/bin2h.c b/src/utils/bin2h.c
index 65b80cea..04d8b73f 100644
--- a/src/utils/bin2h.c
+++ b/src/utils/bin2h.c
@@ -15,6 +15,12 @@
#define O_BINARY 0
#endif
+#ifdef __MINGW32__
+# define FOPEN_MODE_WT "w"
+#else
+# define FOPEN_MODE_WT "wb"
+#endif
+
int
main(int argc, char **argv)
{
@@ -36,7 +42,7 @@ main(int argc, char **argv)
exit(1);
}
- of = fopen(argv[3], "w");
+ of = fopen(argv[3], FOPEN_MODE_WT);
if (of == NULL)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment