###############################################################################
#
# wmakefile - Watcom makefile for os2ahci driver
#
# NOTE: This is a wmake file! See here:
# http://www.openwatcom.org/index.php/Using_wmake
#

#
# Copyright (c) 2010 Markus Thielen, Christian Mueller. 
# 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

###############################################################################
# wmake options

# disable prompt to delete out of date files on compile errors
.ERASE   


###############################################################################
# Tool Chain

AS            = wasm    # Watcom assembler  
CC            = wcc     # Watcom 16bit compiler
LD            = wlink   # Watcom linker


###############################################################################
# Environment
#
# we need the following set before this makefile is called:
#
# WATCOM - to the base WATCOM installation directory
# DDK    - to the base dir of the OS/2 DDK to use
# PS     - the path separator (/ or \)
#

DDK          = $(%DDK)
WATCOM       = $(%WATCOM)
!ifndef %PS
PS           = \
!else
PS           = $(%PS)
!endif

CC_INCLUDE   = -I$(DDK)$(PS)BASE$(PS)H &
               -I$(DDK)$(PS)BASE$(PS)IBMH &
               -I$(DDK)$(PS)BASE$(PS)SRC$(PS)DEV$(PS)DASD$(PS)DISKH &
               -I$(WATCOM)$(PS)h &

AS_INCLUDE   = -I$(DDK)$(PS)BASE$(PS)INC &
               -I$(DDK)$(PS)BASE$(PS)SRC$(PS)DEV$(PS)DASD$(PS)DISKINC

LIB_DIRS     = $(DDK)$(PS)BASE$(PS)LIB$;$(DDK)$(PS)BASE$(PS)SRC$(PS)DEV$(PS)DASD$(PS)DEVHLP;$(WATCOM)$(PS)LIB;


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

TARGET   = os2ahci.add

LIBS     = os2,addcalls,dhcalls,doscalls,rmcalls

SRCS     = init.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

#          the Watcom linker needs commas between object files
LDOBJS   = init.obj,libc.obj,os2ahci.obj,pci.obj,ahci.obj,ata.obj,atapi.obj,&
           ctxhook.obj

INCS     = os2ahci.h ahci.h


all: $(TARGET)

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


###############################################################################
# compiler/linker flags

AFLAGS        = -2 -bt=os2 -w3 -zq -ms -zcm
CFLAGS        = -bt=os2 -ms -s -zdp -zff -zgf -zu -zl -2 -w2 -wcd=138 -zp=1 -q
CFLAGS_DEBUG  = -d3 -hc
LFLAGS        = name $(TARGET) sys os2 dll initglobal option map option quiet &
                option nodefaultlibs libpath $(LIB_DIRS) file $(LDOBJS) &
		library $(LIBS) 
LFLAGS_DEBUG  = DEBUG CODEVIEW option cvpack

!IFDEF DEBUG
CFLAGS = $(CFLAGS) $(CFLAGS_DEBUG)
LFLAGS = $(LFLAGS) $(LFLAGS_DEBUG)
!ENDIF

###############################################################################
# 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)

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

.asm.obj:
	$(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm -fo=$*.obj

.c.obj:
	$(CC) $(CFLAGS) $(CC_INCLUDE) $*.c

$(TARGET): $(OBJS) os2ahci.def wmakefile
	$(LD) $(LFLAGS) 


