###############################################################################
# Makefile - makefile for os2ahci driver, c600 tool chain
#
# Copyright (c) 2011 thi.guten Software Development
# Copyright (c) 2011 Mensys B.V.
#
# Authors: Christian Mueller, Markus Thielen
#
#  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
#

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

AS         = $(DDK)\tools\alp.exe
CC         = cl
LD         = $(DDK)\base\tools\link.exe
MAPSYM     = $(DDK)\base\tools\mapsym.exe
BLDLEVEL   = cmd.exe /c ..\..\tools\bldlvl.cmd
BLDDATE    = cmd.exe /c ..\..\tools\blddate.cmd

AFLAGS     = -Mb
CFLAGS     = -c -nologo -Asnw -W2 -G2ms -Zlpd -Fc -Zi -DECS_BUILD
LFLAGS     = /noe /nod /packd /a:16 /batch /map /line

###############################################################################
# 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 16 bit C compiler
!ifndef CC16
CC16         = i:\c600
!endif

CC_INCLUDE   = -I$(DDK)\base\h \
               -I$(DDK)\base\ibmh \
	       -I$(DDK)\base\src\dev\dasd\diskh \
               -I$(DDK)\base\src\dev\thinkpad\dockii\apmcalls \
               -I$(CC16)\include

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

LIB_DIRS     = $(DDK)\base\lib\ \
	       $(DDK)\base\src\dev\dasd\devhlp\ \
               $(DDK)\base\src\dev\thinkpad\dockii\apmcalls\ \
               $(CC16)\lib\ \


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

TARGET   = os2ahci.add

LIBS     = addcalls dhcalls doscalls slibcep rmcalls apmcalls

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

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

INCS     = os2ahci.h ahci.h version.h


all: $(TARGET)

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


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

init.obj:     init.asm   Makefile

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

os2ahci.obj:  os2ahci.c  Makefile $(INCS) bldday.h ioctl.h

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

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

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

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

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

apm.obj:      apm.c      Makefile $(INCS)

ioctl.obj:    ioctl.c    Makefile $(INCS) atapi.h ioctl.h

os2ahci.def:  version.h os2ahci.def.template

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

# emacs TAGS file creation
# NOTE: OS/2 emacs etags.exe expects an empty file named c:\dev\null...
tags:	$(SRCS) $(INCS)
	etags.exe $(SRCS) $(INCS)

bldday.h:
	$(BLDDATE) > bldday.h

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

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

os2ahci.def:
	$(BLDLEVEL) os2ahci.def.template os2ahci.def version.h


$(TARGET): $(OBJS) os2ahci.def Makefile
	$(LD) $(LFLAGS) $(OBJS),$(TARGET),$*.map,$(LIB_DIRS) $(LIBS),$*.def
	$(MAPSYM) os2ahci


