Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[6model/c] start Configure.bat and MSVC support - incomplete
  • Loading branch information
mberends committed Jul 10, 2011
1 parent 9e81523 commit e849201
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions c/.gitignore
@@ -0,0 +1 @@
Makefile
71 changes: 71 additions & 0 deletions c/Configure.bat
@@ -0,0 +1,71 @@
:: Configure.bat

:: Currently this script assumes Microsoft Visual C++ Express 2010.
:: The TODO comments below describe several future alternatives.

:: !!! FUD WARNING !!!
:: Microsoft thinks that C programmers should rewrite every call to,
:: for example, strcpy, replacing it with their more "secure"
:: replacement called strcpy_s, which takes additional paramaters to
:: avoid buffer overruns. Microsoft's C compilers emit many loud
:: warnings containing weasel words such as "fopen ... may be unsafe".
:: http://msdn.microsoft.com/en-us/library/8ef0s5kh%28v=VS.100%29.aspx
:: Talk about a brazen lock-in attempt! Since other target platforms
:: are not blessed with strcpy_s and so on, this project opts to
:: continue using the "older, less secure functions" and disable the
:: warnings with -D_CRT_SECURE_NO_WARNINGS

set opts=-Wall -D_CRT_SECURE_NO_WARNINGS

@echo off
:: echo Compiling tools/build/Configure.c to Configure.exe
cl %opts% -Fotools\build\Configure.obj -Fetools\build\Configure.exe tools\build\Configure.c
:: echo Starting tools\build\Configure.exe
del tools\build\Configure.obj
tools\build\Configure.exe tools\build\Makefile.in Makefile

:: Notes

:: Configure.bat or Configure.cmd?
:: There is almost no difference between the two file types (just something
:: subtle about errorlevel), and in 6model/c they work the same. So on user
:: friendliness grounds, .bat reassures the reader that the script will do
:: only "simple" things.
:: You could argue it the other way - we use cmd.exe, not command.com, so we
:: should use the extension that command.com cannot handle. Dunno...

:: TODO

:: Evaluate potential Win32 C compilers and development environments
:: http://www.thefreecountry.com/compilers/cpp.shtml
:: Most of them alias cc to their own filenames.

:: msysGit
:: The full install is a 39MB download instead of the 13MB Git install, but it expands to 1.3GB instead of
:: about 200MB, and includes MinGW, which includes GCC.

:: MinGW
:: http://www.mingw.org/
:: Also bundled with the Git full install. It includes bash, so use Configure.sh rather than Configure.bat
:: The libraries do not include dlopen.

:: lcc-win32
:: http://www.cs.virginia.edu/~lcc-win32/

:: Microsoft Visual C++ Express Edition 1-2GB RAM, 3GB disk
:: Downloads a 3.2MB web installer.
:: http://www.microsoft.com/express/vc/ do not need optional SQL express.
:: Does install Windows Installer 4.5, .NET Framework 4, SQL Server Compact 3.5, Help Viewer 1.0
:: (download 146MB, disk space 2.3GB)

:: Borland
:: Registration required

:: Tiny C Compiler
:: http://bellard.org/tcc/

:: OpenWatCom
:: http://www.openwatcom.org/index.php/Download

:: Digital Mars
:: http://www.digitalmars.com/download/freecompiler.html
16 changes: 15 additions & 1 deletion c/tools/build/Configure.c
Expand Up @@ -2,7 +2,7 @@
/* Compiled and run by 6model/c/Configure.(sh|bat) */

#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h> /* getenv */
#include <string.h>

#define LINEBUFFERSIZE 128
Expand Down Expand Up @@ -104,9 +104,23 @@ int
main(int argc, char * argv[])
{
char * makefiletext;
enum { GCC, MSVC } c_compiler;
if (argc < 2) {
fprintf(stderr, "Usage: %s path/to/Makefile.in path/to/Makefile\n");
exit(1);
}
printf("%s is converting %s to %s\n", argv[0], argv[1], argv[2]);

/* Quick and dirty OS check to decide which compiler to use */
c_compiler = getenv("HOME") ? GCC : MSVC;
makefiletext = slurp(argv[1]);
subst(&makefiletext, "# Makefile.in", "# Makefile");
subst(&makefiletext, "This is the file", "This is NOT the file");
subst(&makefiletext, "@cc@", c_compiler == GCC ? "cc" : "cl" );
subst(&makefiletext, "@exe@", c_compiler == GCC ? "" : ".exe" );
subst(&makefiletext, "@ldl@", c_compiler == GCC ? "-ldl" : "-DWIN" );
subst(&makefiletext, "@o@", c_compiler == GCC ? "-o" : "-Fo" );
subst(&makefiletext, "@win@", c_compiler == GCC ? "" : "-DWIN" );
squirt(makefiletext, argv[2]);
free(makefiletext);
return 0;
Expand Down
13 changes: 10 additions & 3 deletions c/tools/build/Makefile.in
Expand Up @@ -6,16 +6,23 @@

# Targets that do not produce files (tells make not to waste time
# checking that such files exist).

.PHONY: clean test test01 test02

CC = @cc@
EXE = @exe@
LDL = @ldl@
O = @o@
WIN = @win@

t/01-toolchain/01a-cc.exe: t/01-toolchain/01a-cc.c
cc -ldl -o t/01-toolchain/01a-cc.exe t/01-toolchain/01a-cc.c
$(CC) $(WIN) $(LDL) $(O)t/01-toolchain/01a-cc.exe t/01-toolchain/01a-cc.c

t/01-toolchain/01b-icu.exe: t/01-toolchain/01b-icu.c
cc -ldl -o t/01-toolchain/01b-icu.exe t/01-toolchain/01b-icu.c
$(CC) $(WIN) $(LDL) $(O)t/01-toolchain/01b-icu.exe t/01-toolchain/01b-icu.c

t/02-components/02a-hashtable.exe: t/02-components/02a-hashtable.c
cc -o t/02-components/02a-hashtable.exe t/02-components/02a-hashtable.c
$(CC) $(WIN) $(O)t/02-components/02a-hashtable.exe t/02-components/02a-hashtable.c

test01: t/01-toolchain/01a-cc.exe t/01-toolchain/01b-icu.exe
prove -e '' --ext '.exe' t/01-toolchain
Expand Down

0 comments on commit e849201

Please sign in to comment.