#! gmake

## AbiSource Setup Kit
## Copyright (C) 2001 AbiSource, Inc.
##
## 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.

ABI_ROOT:=$(shell pwd)/../abi
ABI_PEER:=/nsis

include $(ABI_ROOT)/src/config/abi_defs.mk

DIRS=zlib exehead

CSRCS=			crc32.c

CPPSRCS=		build.cpp exedata.cpp makenssi.cpp script.cpp \
                tokens.cpp util.cpp

RCSRCS=			script1.rc

PROGRAM=		$(BINDIR)/makensis$(EXE_SUFFIX)

ABI_LDFLAGS=	/nologo /subsystem:console /incremental:no /machine:$(LINK_ARCH) /profile 

ABI_OTHLIBS=		
OS_LIBS=		kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib \
				shell32.lib uuid.lib comctl32.lib ole32.lib oleaut32.lib odbc32.lib odbccp32.lib version.lib 
EXTRA_LIBS=     $(LIBDIR)/libNSIS_zlib_s.lib 

CFLAGS+= 		-Izlib

GARBAGE=		makenisis.map makenisis.pdb
TARGETS=		$(PROGRAM)

include $(ABI_ROOT)/src/config/abi_rules.mk

##################################################################
## everything below here must *FOLLOW* abi_rules
##################################################################

$(PROGRAM): buildheaders $(OBJS)
	@$(MAKE_OBJDIR)
	@echo Linking $(PROGRAM)....
	@$(CC) $(shell echo $(OBJS) | $(TRANSFORM_TO_DOS_PATH))		\
		-Fe$(shell echo $@ | $(TRANSFORM_TO_DOS_PATH))		\
		-link $(LDFLAGS) $(OS_LIBS) $(ABI_LDFLAGS) \
              $(shell echo $(EXTRA_LIBS) | $(TRANSFORM_TO_DOS_PATH)) 


build:: $(TARGETS)
	@echo makensis built

buildheaders: ./exehead/bitmap1.bmp ./exehead/bitmap2.bmp ./exehead/nsis.ico \
              ./exehead/uninst.ico  $(OBJDIR)/exehead/exehead$(EXE_SUFFIX) \
			  $(BINDIR)/cdump$(EXE_SUFFIX)
	@rm -f ./exehead/bitmap1.h ./exehead/bitmap2.h ./exehead/icon.h \
          ./exehead/unicon.h  ./exehead/exehead.h ./exehead/exehead$(EXE_SUFFIX)
	@cp $(OBJDIR)/exehead/exehead$(EXE_SUFFIX) ./exehead/exehead$(EXE_SUFFIX)
	@$(BINDIR)/cdump$(EXE_SUFFIX) ./exehead/bitmap1.bmp bitmap1_data > ./exehead/bitmap1.h
	@$(BINDIR)/cdump$(EXE_SUFFIX) ./exehead/bitmap2.bmp bitmap2_data > ./exehead/bitmap2.h
	@$(BINDIR)/cdump$(EXE_SUFFIX) ./exehead/nsis.ico icon_data > ./exehead/icon.h
	@$(BINDIR)/cdump$(EXE_SUFFIX) ./exehead/uninst.ico unicon_data > ./exehead/unicon.h
	@$(BINDIR)/cdump$(EXE_SUFFIX) ./exehead/exehead$(EXE_SUFFIX) header_data > ./exehead/exehead.h

$(BINDIR)/cdump$(EXE_SUFFIX):
	@$(MAKE) -f Makefile -C $(ABI_ROOT)/src/tools/cdump
