Makefile replacement for windoze
Posted: Fri Jun 19, 2009 5:13 am
Hi!
I just made these set of batch files to compile my kernel (ViSE). The advantage of this is that you don't have to specify a list of object files like you do in a makefile. You just have to set the directories where .c/.s files should be searched. It also allows for usual configuration like CC, CFLAGS, AS, ASFLAGS etc.. This configuration is in the buildall.bat file.
buildall.bat
compile.bat
procc.bat
procs.bat
genout.bat
outfiles.bat
In order to allow for a large list of object files, I use the @ofiles.txt format for linker which allows the list to be in a file (in this case, ofiles.txt).
To build, you just run the buildall.bat file and it does the necessary compilation/assembly. In order to check for the file modification time, it requires a program mcmp.exe that i wrote which stats each file and compares.
mcmp.c
All the above in a zipped file is attached. The set of files should be placed in the top level directory of source code. All other configurations can be done in buildall.bat.
I hope this is useful.
I just made these set of batch files to compile my kernel (ViSE). The advantage of this is that you don't have to specify a list of object files like you do in a makefile. You just have to set the directories where .c/.s files should be searched. It also allows for usual configuration like CC, CFLAGS, AS, ASFLAGS etc.. This configuration is in the buildall.bat file.
buildall.bat
Code: Select all
echo off
REM CONFIGURATION
REM Directories to find C and s files to compile/assemble
set DIRS=arch . class drivers stdlib
REM Compile parameters
set CC=gcc
set CFLAGS=-fno-builtin -O0 -I include -nostdinc
REM Assemble parameters
set AS=NASM
set ASFLAGS=-f aout
REM Linker parameters
set LINKER=ld
set OBJECT_LIST_FILE=ofiles.txt
set OUTPUT_FILE=kernel.bin
set LINKER_PARAMS=-T link.txt
REM Perform compilation/assembly
for %%D in (%DIRS%) do call compile.bat %%D
REM Generate a list of output files (.o)
call genout.bat > ofiles.txt
echo Linking...
%LINKER% %LINKER_PARAMS% -o %OUTPUT_FILE% @%OBJECT_LIST_FILE%
pause
Code: Select all
echo Checking Directory %1
REM Compile all .c
for %%X in (%1/*.c) do (call procc.bat %1/%%X)
REM Assemble all .s
for %%X in (%1/*.s) do (call procs.bat %1/%%X)
Code: Select all
set rawstr=%1
set str=%rawstr:.c=%
if exist %str%.o goto compare_mtime
goto do_compile
goto end
:compare_mtime
REM mcmp is a C program that will compare modification times.
REM If output file mtime is older than input file mtime then compilation is required
REM mcmp returns 2 when above condition is satisfied.
mcmp %str%.o %1
if %ERRORLEVEL%==2 goto do_compile
goto end
:do_compile
echo Compiling file %1
%CC% %CFLAGS% -c -o %str%.o %1
:end
Code: Select all
REM Remove .s from the filename
set rawstr=%1
set str=%rawstr:.s=%
if exist %str%.o goto compare_mtime
goto do_assemble
goto end
:compare_mtime
mcmp %str%.o %1
if %ERRORLEVEL%==2 goto do_assemble
goto end
:do_assemble
echo Assembling %1
%AS% %ASFLAGS% -o %str%.o %1
:end
Code: Select all
for %%D in (%DIRS%) do call outfiles.bat %%D
Code: Select all
for %%X in (%1/*.o) do echo %1/%%X
In order to allow for a large list of object files, I use the @ofiles.txt format for linker which allows the list to be in a file (in this case, ofiles.txt).
To build, you just run the buildall.bat file and it does the necessary compilation/assembly. In order to check for the file modification time, it requires a program mcmp.exe that i wrote which stats each file and compares.
mcmp.c
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
/*A utility to compare modification times of files*/
int main(int nr, char *argv[])
{
struct stat buf1, buf2;
if(nr < 3) {
printf("Invalid number of arguments\nUsage: %s <file1> <file2>", argv[0]);
return 3;
}
stat(argv[1], &buf1);
stat(argv[2], &buf2);
if(buf1.st_mtime > buf2.st_mtime)
return 1;
else
return 2;
}
All the above in a zipped file is attached. The set of files should be placed in the top level directory of source code. All other configurations can be done in buildall.bat.
I hope this is useful.