###############################################################################
# wmakefile - makefile for os2ahci driver using WATCOM compiler
#
# Copyright (c) 2010 Christian Mueller, Markus Thielen.
# Parts copied from/inspired by the Linux AHCI driver; 
# those parts are (c) Linux AHCI/ATA maintainers
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


###############################################################################
# Environment

# main path to OS/2 DDK; this needs to be set before this makefile will work
!ifndef DDK
DDK          = i:\ddk
!endif

# main path to WATCOM installation
!ifndef WATCOM
WATCOM       = i:\watcom
!endif

CC_INCLUDE   = -I..\include \
               -I$(DDK)\base\h \
               -I$(DDK)\base\ibmh \
	       -I$(DDK)\base\src\dev\dasd\diskh \
               -I$(WATCOM)\h

AS_INCLUDE   = -I:$(DDK)\base\inc \
               -I:$(DDK)\base\src\dev\dasd\diskinc

LIB_DIRS     = $(DDK)\base\lib\ \
	       $(DDK)\base\src\dev\dasd\devhlp\ \


###############################################################################
# Tool Chain
#
# This makefile uses the Watcom 16bit compiler. 
# Linker and assembler are link.exe and alp.exe that ship with the OS/2 DDK
#

AS         = $(DDK)\tools\alp.exe
CC         = wcc
LD         = $(DDK)\base\tools\link.exe
BLDLEVEL   = ..\..\tools\bldlvl.cmd

AFLAGS        = -Mb
CFLAGS        = -d3 -hc -bt=os2 -ms -zu -5 -w2 -wcd=138 -zp1 -q -s -zgp -zfp -oi
CFLAGS_DEBUG  = -d3 -hc
LFLAGS        = /noe /nod /packd /a:16 /batch /map /line 

###############################################################################
# Main dependencies

TARGET   = os2ahci.add

LIBS     = addcalls doscalls rmcalls # dhcalls not needed, see local devhelp.h

SRCS     = init.asm math.asm libc.c os2ahci.c pci.c ahci.c ata.c atapi.c \
	   ctxhook.c

OBJS     = init.obj libc.obj os2ahci.obj pci.obj ahci.obj ata.obj atapi.obj \
           ctxhook.obj

INCS     = os2ahci.h ahci.h version.h


all: $(TARGET)

clean:
	rm -f $(OBJS) $(TARGET)

###############################################################################
# Object/source dependencies

init.obj:     init.asm   wmakefile

libc.obj:     libc.c     wmakefile $(INCS)

os2ahci.obj:  os2ahci.c  wmakefile $(INCS)

pci.obj:      pci.c      wmakefile $(INCS)

ahci.obj:     ahci.c     wmakefile $(INCS) ata.h atapi.h

ata.obj:      ata.c      wmakefile $(INCS) ata.h

atapi.obj:    atapi.c    wmakefile $(INCS) ata.h atapi.h

ctxhook.obj:  ctxhook.c  wmakefile $(INCS) ata.h atapi.h

###############################################################################
# Action definitions (compile/link commands)

.asm.obj:
	$(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm

.c.obj:
	$(CC) $(CFLAGS) $(CC_INCLUDE) $*.c
	wdis -l $*.obj

$(TARGET): $(OBJS) os2ahci.def wmakefile
	$(BLDLEVEL) os2ahci.def version.h
	$(LD) $(LFLAGS) $(OBJS),$(TARGET),$*.map,$(LIB_DIRS) $(LIBS),$*.def
	mapsym os2ahci


