head	1.2;
access;
symbols
	start:1.1.1.1 webdox:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2003.03.17.01.07.20;	author redpain;	state Exp;
branches;
next	1.1;

1.1
date	2003.03.15.00.57.44;	author redpain;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2003.03.15.00.57.44;	author redpain;	state Exp;
branches;
next	;


desc
@@


1.2
log
@in clean, rm hd.img
@
text
@# Unix/Windows makefile for GeekOS
# Copyright (c) 2001, David H. Hovemeyer <daveho@@cs.umd.edu>
# $Revision: 1.1.1.1 $

# This is free software.  You are permitted to use,
# redistribute, and modify it as specified in the file "COPYING".

# This makefile works (well, is intended to work) on both
# Unix (including Linux) and Windows platforms.  On Windows,
# you need a recent version of the cygwin toolkit, available
# at
#   http://sources.redhat.com/cygwin/

# On any platform, you need gcc/binutils with an i386 target
# (http://gcc.gnu.org/), Nasm (http://www.web-sites.co.uk/nasm/),
# and perl (http://www.perl.com/).

# GNU make is required for this makefile.

# ----------------------------------------------------------------------
# Configuration stuff
# ----------------------------------------------------------------------

# Try to figure out if we're compiling on Unix or Windows.
# You may want to override this.  OS should be set to
# "Windows_NT" for *any* version of Windows.
ifneq ($(OS),Windows_NT)
OS := Unix
endif

# Uncomment this if you're using the i386-elf cross compiler and
# binutils.
#CC_PREFIX := i386-elf-

# In theory, you should not need to modify anything beyond this point...

# ----------------------------------------------------------------------
# Tools and definitions
# ----------------------------------------------------------------------

# The C compiler used to compile the kernel.
CC := $(CC_PREFIX)gcc

# Compiler flags.
ifeq ($(OS),Windows_NT)
EXTRA_CFLAGS := -DNEED_UNDERSCORE -DGNU_WIN32
endif
CFLAGS := -O -Wall -Werror -DGEEKOS $(EXTRA_CFLAGS)

# GNU linker and GNU objcopy.  These are provided with the
# cygwin tools.
LD := $(CC_PREFIX)ld
OBJCOPY := $(CC_PREFIX)objcopy

# Objcopy flags.
# On Unix/ELF we get rid of some unnecessary sections.
ifeq ($(OS),Unix)
OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
endif

# Nasm.  I'm using version 0.98
ifeq ($(OS),Windows_NT)
NASM := nasmw
NASMFLAGS := -f win32 -DNEED_UNDERSCORE
else
NASM := nasm
NASMFLAGS := -f elf
endif

# Kernel source and object files.
C_SRCS := screen.c idt.c int.c irq.c io.c keyboard.c mem.c string.c \
	gdt.c kthread.c thrqueue.c timer.c segment.c tss.c bget.c malloc.c \
	user.c trap.c syscall.c synch.c main.c
ASM_SRCS := lowlevel.asm
OBJS := $(C_SRCS:.c=.o) $(ASM_SRCS:.asm=.o)

# Perl (needs to be version 5 or later).
PERL = perl

# Utility scripts
PAD := $(PERL) pad
NUMSECS := $(PERL) numsecs
ZEROFILE := $(PERL) zerofile
CAT := $(PERL) pcat
RM :=  rm -f

# Kernel entry point.
ifeq ($(OS),Windows_NT)
ENTRY := _Main
else
ENTRY = Main
endif

# ----------------------------------------------------------------------
# Compilation rules
# ----------------------------------------------------------------------

.SUFFIXES:
.SUFFIXES: .c .asm .o

.c.o:
	$(CC) $(CFLAGS) -c $<

.asm.o:
	$(NASM) $(NASMFLAGS) -o $*.o $<


# ----------------------------------------------------------------------
# Targets
# ----------------------------------------------------------------------

# Default target.
# Create floppy and hard drive image files needed to
# start bochs.
all : fd.img hd.img

# Create the boot floppy, consisting of the boot sector followed by
# the setup code and binary kernel image.
fd.img : bootsect.bin setup.bin kernel.bin
	$(CAT) bootsect.bin setup.bin kernel.bin > $@@

# Create a nice 10MB hard disk for bochs to use.
hd.img :
	$(ZEROFILE) $@@ 20808

# Setup code (16 bit real mode), loaded by the bootsector.
# Its purpose is to set up the hardware sufficiently such that
# the kernel can start running.  Note that the kernel storage map
# is a prerequisite, since the setup code needs to know the address
# of the kernel entry point.
setup.bin : setup.asm defs.asm util.asm storage.txt
	$(NASM) -DENTRY_POINT=`perl findaddr storage.txt Main` \
		-f bin -o $@@ setup.asm
	$(PAD) $@@ 512

# Create a binary image of the kernel code and data.
# The file produced can be loaded into memory as-is and executed.
# The -S option stips out the symbol table.
kernel.bin: kernel.exe
	$(OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary kernel.exe kernel.bin
	$(PAD) $@@ 512

# Link the kernel.  Put the .text section (which is the first
# section in the executable) at address 0x10000 (64K).
kernel.exe storage.txt : $(OBJS) uprogs.o
	$(LD) -M -o kernel.exe -Ttext 0x00010000 -e $(ENTRY) $(OBJS) uprogs.o \
		> storage.txt

# Assemble the boot sector.
# Note that we need to build the setup code and kernel first,
# since their sizes are referenced.
bootsect.bin : setup.bin kernel.bin bootsect.asm defs.asm util.asm
	$(NASM) -DNUM_SETUP_SECTORS=`$(NUMSECS) setup.bin` \
		-DNUM_KERN_SECTORS=`$(NUMSECS) kernel.bin` \
		-f bin -o $@@ bootsect.asm

# Rules for generating user programs which live in the "test" directory.

uprogs.o : uprogs.c

uprogs.c : dummy
	cd test && $(MAKE) OS="$(OS)"

dummy :

# Delete generated files.
clean :
	$(RM) fd.img hd.img kernel.exe kernel.bin bootsect.bin setup.bin *.o \
		uprogs.c storage.txt bochs.out
	cd test && $(MAKE) clean

realclean : clean
	$(RM) hd.img depend.mak

# Generate header file dependencies.
depend : uprogs.c
	$(CC) $(CFLAGS) -M $(C_SRCS) uprogs.c > depend.mak

depend.mak :
	echo dummy: > $@@

include depend.mak
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
# $Revision: 1.44 $
d168 1
a168 1
	$(RM) fd.img kernel.exe kernel.bin bootsect.bin setup.bin *.o \
@


1.1.1.1
log
@Project Start
@
text
@@
