Upgraded ccdv-win32.c and the Makefiles so that they are fully functional under MSYS.

SVN r286 (trunk)
This commit is contained in:
Randy Heit 2006-08-11 03:07:32 +00:00
parent b8312a9bd8
commit 55e299e4b3
14 changed files with 331 additions and 119 deletions

View file

@ -7,6 +7,15 @@
# Copyright (C) 1995-2003 Jean-loup Gailly.
# For conditions of distribution and use, see copyright notice in zlib.h
ifeq (Windows_NT,$(OS))
WIN=1
WINCMD=1
endif
ifeq (msys,$(OSTYPE))
WIN=1
WINCMD=0
endif
STATICLIB = libflac.a
#LOC = -DASMV
@ -44,8 +53,13 @@ $(STATICLIB): $(OBJS)
.PHONY: clean
clean:
ifeq (1,$(WINCMD))
-del /q /f $(STATICLIB) 2>nul
-del /q /f *.o 2>nul
else
rm -f $(STATICLIB)
rm -f *.o
endif
cpu_asm.o: ia32/cpu_asm.nasm
$(CCDV) $(NASM) -o $@ $(NASMFLAGS) $<

View file

@ -1,4 +1,11 @@
ifeq (Windows_NT,$(OS))
WIN=1
endif
ifeq (msys,$(OSTYPE))
WIN=1
endif
ifeq (1,$(WIN))
include Makefile.mgw
else
include Makefile.linux

View file

@ -25,23 +25,27 @@ basetools: ccdv.exe
$(MAKE) -C tools/makewad
$(MAKE) -C tools/dehsupp
$(MAKE) -C tools/xlatcc
$(MAKE) -C wadsrc
$(MAKE) -C wadsrc -f Makefile.mgw
$(MAKE) -C flac -f Makefile.mgw
cleanexe:
@$(MAKE) -C . -f Makefile.mingw clean
clean:
@$(MAKE) -C tools/lemon -f Makefile clean
@$(MAKE) -C tools/re2c -f Makefile clean
@$(MAKE) -C tools/dehsupp -f Makefile clean
@$(MAKE) -C tools/makewad -f Makefile clean
@$(MAKE) -C tools/xlatcc -f Makefile clean
@$(MAKE) -C tools/lemon clean
@$(MAKE) -C tools/re2c clean
@$(MAKE) -C tools/dehsupp clean
@$(MAKE) -C tools/makewad clean
@$(MAKE) -C tools/xlatcc clean
@$(MAKE) -C wadsrc -f Makefile.mgw clean
@$(MAKE) -C . -f Makefile.mingw clean
@$(MAKE) -C zlib -f Makefile.mgw clean
@$(MAKE) -C flac -f Makefile.mgw clean
ifeq (msys,$(OSTYPE))
rm -f ccdv.exe
else
del /q /f ccdv.exe 2>nul
endif
ccdv.exe: ccdv-win32.c
@gcc -Os -s -nostdlib -fomit-frame-pointer -o ccdv.exe ccdv-win32.c -lkernel32 -luser32

View file

@ -4,6 +4,12 @@
# Where did you install the FMOD API to? Change this line so that the build process can find it.
FMODDIR = "c:/program files/fmodapi375win"
ifeq (msys,$(OSTYPE))
WINCMD=0
else
WINCMD=1
endif
CC ?= gcc
CXX ?= g++
@ -93,6 +99,7 @@ $(OBJDIR)/%.o : %.rc
$(TARGET): testobjdir updaterev $(OBJS)
$(CCDV) $(CXX) -o $@ $(OBJS) $(LDFLAGS)
ifeq (1,$(WINCMD))
clean:
-del /q /f $(RELEASETARGET) 2>nul
-del /q /f $(DEBUGTARGET) 2>nul
@ -102,9 +109,24 @@ clean:
cleandep:
-del /q /f $(DEBUGOBJDIR)\*.d 2>nul
-del /q /f $(RELEASEOBJDIR)\*.d 2>nul
else
clean:
rm -f $(RELEASETARGET)
rm -f $(DEBUGTARGET)
rm -fr $(DEBUGOBJDIR)
rm -fr $(RELEASEOBJDIR)
cleandep:
rm -f $(DEBUGOBJDIR)\*.d
rm -f $(RELEASEOBJDIR)\*.d
endif
testobjdir:
ifeq (1,$(WINCMD))
-@if not exist $(OBJDIR) mkdir $(OBJDIR)
else
-@if [ ! -e $(OBJDIR) ]; then mkdir $(OBJDIR); fi
endif
updaterev: tools/updaterevision/updaterevision.exe
@tools/updaterevision/updaterevision . src/svnrevision.h

View file

@ -22,6 +22,16 @@
#define COLOR_FAILURE (FOREGROUND_RED|FOREGROUND_INTENSITY) /* red */
#define COLOR_WARNING (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY) /* yellow */
#define COLOR_COMMAND (FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY) /* cyan */
#define COLOR_ERROROUTPUT (FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY) /* magenta */
#define COLOR_WARNINGOUTPUT (FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY) /* white */
#define SETCOLOR_SUCCESS "\033[1;32m" /* green */
#define SETCOLOR_FAILURE "\033[1;31m" /* red */
#define SETCOLOR_WARNING "\033[0;33m" /* dark yellow */
#define SETCOLOR_COMMAND "\033[1;35m" /* magenta */
#define SETCOLOR_ERROROUTPUT "\033[1;31m" /* red */
#define SETCOLOR_WARNINGOUTPUT "\033[1;39m" /* bold */
#define SETCOLOR_NORMAL "\033[0;39m" /* normal */
#define TEXT_BLOCK_SIZE 8192
#define INDENT 2
@ -36,6 +46,7 @@ char *gArLibraryTarget;
BOOL gDumpCmdArgs;
char *gArgsStr;
int gColumns;
BOOL gRxvt;
int gExitStatus;
HANDLE gHeap;
@ -50,25 +61,47 @@ HANDLE gStdOut, gStdErr;
void REGPARM(1) perror(const char *string)
{
char *buffer;
char errcode[9];
DWORD error = GetLastError();
DWORD len = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, error, 0, (LPTSTR)&buffer, 0, NULL);
DWORD wrote;
WriteFile (gStdErr, string, lstrlen(string), &wrote, NULL);
if(len == 0)
{
char errcode[9];
wsprintf(errcode, "%08x", error);
WriteFile (gStdErr, ": Error ", 8, &wrote, NULL);
WriteFile (gStdErr, ": Error 0x", 10, &wrote, NULL);
WriteFile (gStdErr, errcode, 8, &wrote, NULL);
}
else
if(len != 0)
{
WriteFile (gStdErr, ": ", 2, &wrote, NULL);
WriteFile (gStdErr, "\n", 1, &wrote, NULL);
WriteFile (gStdErr, buffer, len, &wrote, NULL);
LocalFree(buffer);
}
WriteFile (gStdErr, "\n", 1, &wrote, NULL);
gColumns = 0;
}
static int REGPARM(1) str2int(const char *string)
{
int out = 0;
while (*string >= '0' && *string <= '9')
{
out = out * 10 + *string++ - '0';
}
return out;
}
static void Writef(HANDLE hFile, const char *fmt, ...)
{
char buf[1024];
int buflen;
va_list arglist;
DWORD wrote;
va_start(arglist, fmt);
buflen = wvsprintf(buf, fmt, arglist);
va_end(arglist);
WriteFile(hFile, buf, buflen, &wrote, NULL);
}
static void DumpFormattedOutput()
@ -82,19 +115,43 @@ static void DumpFormattedOutput()
int curcol;
int i;
if(!GetConsoleScreenBufferInfo(gStdOut, &info))
{
WriteFile(gStdOut, gBuf, lstrlen(gBuf), &out, NULL);
WriteFile(gStdOut, "\n", 1, &out, NULL);
return;
}
for(i = 0; i < 8; ++i)
{
spaces[i] = ' ';
}
spaces[i] = '\0';
if(gRxvt)
{
curcol = 0;
saved = NULL;
if(gDumpCmdArgs)
{
Writef(gStdOut, SETCOLOR_COMMAND "%s" SETCOLOR_NORMAL "\n", gArgsStr);
for(i = gColumns; i > 0; i -= 7)
{
WriteFile(gStdOut, "=======", i > 7 ? 7 : i, &out, NULL);
}
WriteFile(gStdOut, SETCOLOR_ERROROUTPUT, sizeof(SETCOLOR_ERROROUTPUT), &out, NULL);
}
else
{
WriteFile(gStdOut, SETCOLOR_WARNINGOUTPUT, sizeof(SETCOLOR_WARNINGOUTPUT), &out, NULL);
}
WriteFile(gStdOut, gBuf + lstrlen(gArgsStr), lstrlen(gBuf + lstrlen(gArgsStr)), &out, NULL);
WriteFile(gStdOut, SETCOLOR_NORMAL, sizeof(SETCOLOR_NORMAL), &out, NULL);
HeapFree(gHeap, 0, gBuf);
return;
}
if(!GetConsoleScreenBufferInfo(gStdOut, &info))
{
WriteFile(gStdOut, gBuf, lstrlen(gBuf), &out, NULL);
WriteFile(gStdOut, "\n", 1, &out, NULL);
HeapFree(gHeap, 0, gBuf);
return;
}
color = info.wAttributes & ~(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
curcol = 0;
saved = NULL;
@ -103,41 +160,19 @@ static void DumpFormattedOutput()
SetConsoleTextAttribute(gStdOut, color | COLOR_COMMAND);
WriteConsole(gStdOut, gBuf, lstrlen(gArgsStr)+1, &out, NULL);
SetConsoleTextAttribute(gStdOut, info.wAttributes);
for(i = gColumns; i > 0; i -= 7)
{
WriteConsole(gStdOut, "=======", i > 7 ? 7 : i, &out, NULL);
}
for(cp = gBuf + lstrlen(gArgsStr) + 1;; cp++)
{
if(*cp == '\0')
{
if(saved != NULL)
{
cp = saved;
saved = NULL;
color |= COLOR_ERROROUTPUT;
}
else
break;
}
if(*cp == '\r')
continue;
if(*cp == '\t')
{
saved = cp + 1;
cp = spaces + 8 - (8 - ((curcol - INDENT - 1) % 8));
}
if(curcol == 0)
{
for(i = INDENT; --i >= 0;)
WriteConsole(gStdOut, " " ,1, &out, NULL);
curcol = INDENT;
}
WriteConsole(gStdOut, cp, 1, &out, NULL);
if(++curcol == (gColumns - 1))
{
WriteConsole(gStdOut, "\n", 1, &out, NULL);
curcol = 0;
}
else if(*cp == '\n')
curcol = 0;
color |= COLOR_WARNINGOUTPUT;
}
SetConsoleTextAttribute(gStdOut, color);
WriteConsole(gStdOut, gBuf + lstrlen(gArgsStr) + 1, lstrlen(gBuf + lstrlen(gArgsStr) + 1), &out, NULL);
SetConsoleTextAttribute(gStdOut, info.wAttributes);
HeapFree(gHeap, 0, gBuf);
} /* DumpFormattedOutput */
@ -225,9 +260,12 @@ static int REGPARM(2) Slurp(HANDLE fd, HANDLE hStdOut)
}
if(hStdOut != NULL)
{
if(!gRxvt)
{
GetConsoleScreenBufferInfo(hStdOut, &info);
info.dwCursorPosition.X = info.dwSize.X - 9;
}
if(GetConsoleCursorInfo(hStdOut, &cursorInfo))
{
cursorInfo.bVisible = FALSE;
@ -247,9 +285,16 @@ static int REGPARM(2) Slurp(HANDLE fd, HANDLE hStdOut)
{
case WAIT_TIMEOUT:
if(hStdOut != NULL)
{
if(!gRxvt)
{
SetConsoleCursorPosition(hStdOut, info.dwCursorPosition);
WriteConsoleA(hStdOut, trailcp, 1, &out, NULL);
}
else
{
Writef(hStdOut, "\033[999C\033[9D%c", *trailcp);
}
if(*++trailcp == '\0')
trailcp = trail;
}
@ -284,6 +329,8 @@ static int REGPARM(2) Slurp(HANDLE fd, HANDLE hStdOut)
}
}
if(hStdOut != NULL)
{
if(!gRxvt)
{
info.dwCursorPosition.X = 0;
SetConsoleCursorPosition(hStdOut, info.dwCursorPosition);
@ -319,6 +366,24 @@ static int REGPARM(2) Slurp(HANDLE fd, HANDLE hStdOut)
WriteConsole(hStdOut, "\n", 1, &out, NULL);
}
else
{
WriteFile(hStdOut, "\033[255D", 6, &out, NULL);
WriteAction(hStdOut, ": ");
if(gExitStatus == 0)
{
Writef(hStdOut, "\033[999C\033[10D[%sOK%s]",
((gNBufUsed - strlen(gArgsStr)) <
4) ? SETCOLOR_SUCCESS : SETCOLOR_WARNING, SETCOLOR_NORMAL);
}
else
{
Writef(hStdOut, "\033[999C\033[10D[%sERROR%s]\n",
SETCOLOR_FAILURE, SETCOLOR_NORMAL);
gDumpCmdArgs = 1; /* print cmd when there are errors */
}
}
}
else
{
gDumpCmdArgs = (gExitStatus != 0); /* print cmd when there are errors */
}
@ -457,6 +522,38 @@ void mainCRTStartup(void)
Usage();
}
if(GetConsoleScreenBufferInfo(gStdOut, &bufferInfo))
{
gColumns = bufferInfo.dwSize.X;
}
else
{
char envbuf[16];
DWORD envlen;
// Check for MSYS by checking for an rxvt COLORTERM.
envlen = GetEnvironmentVariable("COLORTERM", envbuf, sizeof(envbuf));
if(envlen > 0 && envlen < sizeof(envbuf) - 1)
{
if(lstrcmp(envbuf, "rxvt") == 0)
{
gRxvt = TRUE;
// We're in an rxvt, so check the number of columns.
// Unfortunately, COLUMNS is not exported by default by MSYS.
envlen = GetEnvironmentVariable("COLUMNS", envbuf, sizeof(envbuf));
if(envlen > 0 && envlen < sizeof(envbuf) - 1)
{
gColumns = str2int(envbuf);
}
else
{
gColumns = 80;
}
}
}
}
// "Running *argv[1]*"
ext = Basename(arg, arglen);
extlen = arglen - (ext - arg);
@ -620,15 +717,14 @@ void mainCRTStartup(void)
}
CloseHandle(gCCP.hThread);
if(GetConsoleScreenBufferInfo(gStdOut, &bufferInfo))
if(!gRxvt)
{
gColumns = bufferInfo.dwSize.X;
if(Slurp(pipeRdDup, gStdOut) < 0)
goto panic;
}
else
{
if(Slurp(pipeRdDup, NULL) < 0)
if(Slurp(pipeRdDup, gStdOut) < 0)
goto panic;
}
DumpFormattedOutput();

View file

@ -1,13 +1,21 @@
ifeq (Windows_NT,$(OS))
WIN=1
WINCMD=1
endif
ifeq (msys,$(OSTYPE))
WIN=1
WINCMD=0
endif
ifeq (1,$(WIN))
EXE = dehsupp.exe
CCDV = @../../ccdv
CFLAGS = $(LOC) -Os -Wall -fomit-frame-pointer
else
EXE = dehsupp
CCDV = @../../ccdv
CFLAGS = -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -Os -Wall -fomit-frame-pointer
endif
CCDV = @../../ccdv
CC = gcc
LDFLAGS = -s
@ -26,7 +34,7 @@ $(EXE): $(OBJS)
.PHONY: clean
clean:
ifeq (Windows_NT,$(OS))
ifeq (1,$(WINCMD))
-del /q /f $(EXE) 2>nul
-del /q /f *.o 2>nul
else

View file

@ -1,13 +1,21 @@
ifeq (Windows_NT,$(OS))
WIN=1
WINCMD=1
endif
ifeq (msys,$(OSTYPE))
WIN=1
WINCMD=0
endif
ifeq (1,$(WIN))
EXE = lemon.exe
CCDV = @../../ccdv
CFLAGS = $(LOC) -D_WIN32 -Os -Wall -Wno-implicit -fomit-frame-pointer
else
EXE = lemon
CCDV = @../../ccdv
CFLAGS = -Os -Wall -Wno-implicit -fomit-frame-pointer
endif
CCDV = @../../ccdv
CC = gcc
LDFLAGS = -s
@ -24,7 +32,7 @@ $(EXE): $(OBJS)
.PHONY: clean
clean:
ifeq (Windows_NT,$(OS))
ifeq (1,$(WINCMD))
-del /q /f $(EXE) 2>nul
-del /q /f *.o 2>nul
else

View file

@ -1,17 +1,25 @@
ifeq (Windows_NT,$(OS))
WIN=1
WINCMD=1
endif
ifeq (msys,$(OSTYPE))
WIN=1
WINCMD=0
endif
ifeq (1,$(WIN))
EXE = makewad.exe
CCDV = @../../ccdv
CFLAGS = -Os -Wall -fomit-frame-pointer
LDFLAGS = -s -L../../zlib/ -lz
ZLIB = ../../zlib/libz.a
else
EXE = makewad
CCDV = @../../ccdv
CFLAGS = -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -Os -Wall -fomit-frame-pointer
LDFLAGS = -s -lz
ZLIB =
endif
CCDV = @../../ccdv
CC = gcc
OBJS = makewad.o ioapi.o zip.o
@ -24,7 +32,7 @@ all: $(EXE)
$(EXE): $(OBJS) $(ZLIB)
$(CCDV) $(CC) -o $(EXE) $(OBJS) $(LDFLAGS)
ifeq (Windows_NT,$(OS))
ifeq (1,$(WIN))
$(ZLIB):
make -C ../../zlib -f Makefile.mgw
endif
@ -32,7 +40,7 @@ endif
.PHONY: clean
clean:
ifeq (Windows_NT,$(OS))
ifeq (1,$(WINCMD))
-del /q /f $(EXE) 2>nul
-del /q /f *.o 2>nul
else

View file

@ -194,7 +194,7 @@ int appendtozip (zipFile zipfile, const char * zipname, const char *filename)
// - otherwise, we're writing lumps into a wad/zip
//
*/
int buildwad (FILE *listfile, char *listfilename, char *makecmd, char *makefile)
int buildwad (FILE *listfile, char *listfilename, const char *makecmd, char *makefile)
{
// destination we're writing output into -
// one of these:
@ -442,6 +442,7 @@ int buildwad (FILE *listfile, char *listfilename, char *makecmd, char *makefile)
int __cdecl main (int argc, char **argv)
{
const char *makecmd;
FILE *listfile = NULL;
char *listfilename = NULL;
char *makefile = NULL;
@ -480,7 +481,16 @@ int __cdecl main (int argc, char **argv)
return 1;
}
ret = buildwad (listfile ? listfile : stdin, listfilename, argv[0], makefile);
// Hack for msys
if ((makecmd = getenv("OSTYPE")) != NULL && strcmp (makecmd, "msys") == 0)
{
makecmd = "../tools/makewad/makewad.exe";
}
else
{
makecmd = argv[0];
}
ret = buildwad (listfile ? listfile : stdin, listfilename, makecmd, makefile);
if (listfile != NULL)
{
fclose (listfile);

View file

@ -1,13 +1,21 @@
ifeq (Windows_NT,$(OS))
WIN=1
WINCMD=1
endif
ifeq (msys,$(OSTYPE))
WIN=1
WINCMD=0
endif
ifeq (1,$(WIN))
EXE = re2c.exe
CCDV = @../../ccdv
CXXFLAGS = $(LOC) -D_WIN32 -DNDEBUG -Os -Wall -Wno-unused
else
EXE = re2c
CCDV = @../../ccdv
CXXFLAGS = -DHAVE_CONFIG_H -DNDEBUG -Os -Wall -Wno-unused
endif
CCDV = @../../ccdv
CXX = g++
LDFLAGS= -s
@ -24,7 +32,7 @@ $(EXE): $(OBJS)
.PHONY: clean
clean:
ifeq (Windows_NT,$(OS))
ifeq (1,$(WINCMD))
-del /q /f $(EXE) 2>nul
-del /q /f *.o 2>nul
else

View file

@ -1,16 +1,24 @@
ifeq (Windows_NT,$(OS))
WIN=1
WINCMD=1
endif
ifeq (msys,$(OSTYPE))
WIN=1
WINCMD=0
endif
CC = gcc
CFLAGS = -Os -Wall -fomit-frame-pointer
LDFLAGS = -s
ifeq (Windows_NT,$(OS))
ifeq (1,$(WIN))
EXE = updaterevision.exe
CCDV = @../../ccdv
else
EXE = updaterevision
CCDV = @../../ccdv
CFLAGS = -Os -Wall -fomit-frame-pointer
endif
CCDV = @../../ccdv
OBJS = updaterevision.o
all: $(EXE)
@ -21,7 +29,7 @@ $(EXE): $(OBJS)
.PHONY: clean
clean:
ifeq (Windows_NT,$(OS))
ifeq (1,$(WINCMD))
-del /q /f $(EXE) 2>nul
-del /q /f *.o 2>nul
else

View file

@ -1,13 +1,21 @@
ifeq (Windows_NT,$(OS))
WIN=1
WINCMD=1
endif
ifeq (msys,$(OSTYPE))
WIN=1
WINCMD=0
endif
ifeq (1,$(WIN))
EXE = xlatcc.exe
CCDV = @../../ccdv
CFLAGS = $(LOC) -Os -Wall -fomit-frame-pointer
else
EXE = xlatcc
CCDV = @../../ccdv
CFLAGS = -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp $(LOC) -Os -Wall -fomit-frame-pointer
endif
CCDV = @../../ccdv
CC = gcc
LDFLAGS= -s
@ -24,7 +32,7 @@ $(EXE): $(OBJS)
.PHONY: clean
clean:
ifeq (Windows_NT,$(OS))
ifeq (1,$(WINCMD))
-del /q /f $(EXE) 2>nul
-del /q /f *.o 2>nul
else

View file

@ -10,7 +10,11 @@ wadmake: zdoom.lst $(MAKEWAD).exe $(XLATCC).exe $(DEHSUPP).exe
$(MAKEWAD) -make wadmake zdoom.lst
clean:
ifeq (msys,$(OSTYPE))
rm -f wadmake zdoom.pk3 xlat/*.x dehsupp.lmp
else
del /q /f wadmake zdoom.pk3 xlat\*.x dehsupp.lmp 2>nul
endif
../tools/makewad/makewad.exe:
$(MAKE) -C ../tools/makewad -f Makefile

View file

@ -63,10 +63,17 @@ minigzip: minigzip.o $(STATICLIB)
.PHONY: clean
clean:
ifeq (msys,$(OSTYPE))
rm -f $(STATICLIB)
rm -f *.o
rm -f *.exe
rm -f foo.gz
else
-del /q /f $(STATICLIB) 2>nul
-del /q /f *.o 2>nul
-del /q /f *.exe 2>nul
-del /q /f foo.gz 2>nul
endif
adler32.o: zlib.h zconf.h
compress.o: zlib.h zconf.h