# Makefile -- Copyright (c) 2001-2003 Eberhard Mattes
#
# This file is part of epocemx.
#
# epocemx 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, or (at your option)
# any later version.
#
# epocemx 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 epocemx; see the file COPYING.  If not, write to the
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#


# cf. <emxuid.h>
KEmxDllUidValue=0x101f3dcc
KEmxConsoleUidValue=0x101f3dcd
KEmxBfdUidValue=0x101f3e2e
KEmxToolsUidValue=0x101f3e2f
KEmxDevUidValue=0x101f3e30
KEmxTextUtilsUidValue=0x101f3e31
KEmxGzipUidValue=0x101f3e32
KEmxGrepUidValue=0x101f3e33
KEmxSedUidValue=0x101f3e34
KEmxLessUidValue=0x101f3e35
KEmxUserUidValue=0x101f3e36
KEmxGccBaseUidValue=0x101f4314
KEmxGccCUidValue=0x101f4315
KEmxGccCppUidValue=0x101f4316
KEmxRecodeUidValue=0x101f4317
KEmxFindUidValue=0x101f4318
KEmxDiffUidValue=0x101f4319
KEmxShUtilsUidValue=0x101f431a
KEmxBzip2UidValue=0x101f431b
KEmxGawkUidValue=0x101f431c
KEmxTarUidValue=0x101f431d
KEmxUnzipUidValue=0x101f5c6e
KEmxZipUidValue=0x101f5c6f

default: all

.PHONY: all all-but-gcc all-gcc clean default

.SUFFIXES: .sis .zip

.sis.zip:
	zip -9j $@ $< ../COPYING

all: all-but-gcc all-gcc

all-but-gcc: emxuser.sis emxdev.sis emxbinutils.sis emxdiff.sis emxfind.sis \
	emxless.sis emxsed.sis emxshutils.sis emxtextutils.sis emxgzip.sis \
	emxgrep.sis emxrecode.sis emxbzip2.sis emxgawk.sis emxtar.sis \
	emxunzip.sis emxzip.sis

all-gcc: emxgcc-base.sis emxgcc-c.sis emxgcc-c++.sis

zip: emxuser.zip emxdev.zip emxbinutils.zip emxdiff.zip emxfind.zip \
	emxless.zip emxsed.zip emxshutils.zip emxtextutils.zip emxgzip.zip \
	emxgrep.zip emxrecode.zip emxbzip2.zip emxgawk.zip emxtar.zip \
	emxunzip.zip emxzip.zip \
	emxgcc-base.zip emxgcc-c.zip emxgcc-c++.zip

emxuser.sis: emxuser.pkg ../console/emxconsole.sis ../lib/emxdll.sis \
		../tools/emxshell.sis
	emxsis -D KEmxDllUidValue=$(KEmxDllUidValue) \
		-D KEmxConsoleUidValue=$(KEmxConsoleUidValue) \
		-D KEmxToolsUidValue=$(KEmxToolsUidValue) \
		-D KEmxUserUidValue=$(KEmxUserUidValue) \
		emxuser.pkg emxuser.sis

emxuser.zip: emxuser.sis ../COPYING ../README ../CHANGES
	zip -9j emxuser emxuser.sis ../COPYING ../README ../CHANGES

I=../lib/include
E=$(I)/emx

DEV_LIB_FILES=../lib/libemx.a ../lib/libm.a ../lib/libtermcap.a \
	../lib/emxexe.o ../lib/emxdll.o ../lib/emx.imp \
	$(I)/emx.h $(I)/emxconsole.h $(I)/emxdevices.h \
	$(I)/emxheader.h $(I)/emxuid.h \
	$(I)/getopt.h $(I)/math.h $(I)/process.h $(I)/share.h \
	$(I)/stdio.h $(I)/stdlib.h \
	$(I)/termcap.h $(I)/sys/ioctl.h \
	$(E)/math.h $(E)/stdio.h $(E)/stdlib.h \
	$(E)/sys/ioctl.h

T=../tools
TE=$(T)/epoc
DEV_TOOLS_FILES=../COPYING.EMX $(TE)/emxdev.dll $(TE)/emxdump.exe \
	$(TE)/emximage.exe $(TE)/emxrsc.exe $(TE)/emxaif.exe $(TE)/emxobj.exe \
	$(TE)/emxfixhdr.exe $(TE)/emxsis.exe $(TE)/emxpanic.exe $(TE)/eld.exe \
	$(TE)/make.exe $(T)/emxrsc.rss $(T)/emxrsc.hrh $(T)/epoc.imp

emxdev.sis: emxdev.pkg $(DEV_LIB_FILES) $(DEV_TOOLS_FILES)
	emxsis -D KEmxDevUidValue=$(KEmxDevUidValue) \
		emxdev.pkg emxdev.sis

B=../epoc/bu/binutils

BINUTILS_FILES=FSF ../COPYING ../epoc/bu/libiberty/emxliberty.dll \
	../epoc/bu/bfd/emxbfd.dll \
	../epoc/bu/gas/as-new ../epoc/bu/ld/ld-new $(B)/nm-new \
	$(B)/ar $(B)/dlltool $(B)/objdump $(B)/ranlib $(B)/size $(B)/strings

emxbinutils.sis: emxbinutils.pkg $(BINUTILS_FILES)
	emxsis -D KEmxBfdUidValue=$(KEmxBfdUidValue) \
		emxbinutils.pkg emxbinutils.sis

S=../epoc/su/src

SHUTILS_FILES=FSF ../COPYING \
	$(S)/date $(S)/echo $(S)/env $(S)/expr $(S)/factor \
	$(S)/false $(S)/printf $(S)/seq $(S)/sleep $(S)/tee $(S)/test \
	$(S)/true $(S)/tty

emxshutils.sis: emxshutils.pkg $(SHUTILS_FILES)
	emxsis -D KEmxShUtilsUidValue=$(KEmxShUtilsUidValue) \
		emxshutils.pkg emxshutils.sis

T=../epoc/tu/src

TEXTUTILS_FILES=FSF ../COPYING ../epoc/tu/lib/emxtu.dll \
	$(T)/cat $(T)/cksum $(T)/comm $(T)/csplit $(T)/cut \
	$(T)/expand $(T)/fmt $(T)/fold $(T)/head $(T)/join $(T)/nl $(T)/od \
	$(T)/pr $(T)/ptx $(T)/sort $(T)/split $(T)/sum $(T)/tac \
	$(T)/tail $(T)/tr $(T)/tsort $(T)/unexpand $(T)/uniq $(T)/wc

emxtextutils.sis: emxtextutils.pkg $(TEXTUTILS_FILES)
	emxsis -D KEmxTextUtilsUidValue=$(KEmxTextUtilsUidValue) \
		emxtextutils.pkg emxtextutils.sis

LESS_LICENSE=../local/less-374/LICENSE
LESS_FILES=$(LESS_LICENSE) ../epoc/less/less ../tools/man ../tools/zless \
	more.lnk

emxless.sis: emxless.pkg $(LESS_FILES)
	recode ../crlf <$(LESS_LICENSE) >LICENSE
	emxsis -D KEmxLessUidValue=$(KEmxLessUidValue) \
		emxless.pkg emxless.sis
	rm -f LICENSE

more.lnk:
	emxlink less.exe more.lnk

emxless.zip: emxless.sis $(LESS_LICENSE)
	zip -9j emxless emxless.sis $(LESS_LICENSE)

SED_FILES=../epoc/sed/sed/sed ../epoc/sed/doc/sed.1

emxsed.sis: FSF ../COPYING emxsed.pkg $(SED_FILES)
	emxsis -D KEmxSedUidValue=$(KEmxSedUidValue) \
		emxsed.pkg emxsed.sis

GZ=../epoc/gzip

GZIP_FILES=$(GZ)/emxgzip.dll $(GZ)/gzip.exe $(GZ)/gunzip.exe $(GZ)/zcat.exe \
	$(GZ)/gzip.1

emxgzip.sis: FSF ../COPYING emxgzip.pkg $(GZIP_FILES)
	emxsis -D KEmxGzipUidValue=$(KEmxGzipUidValue) \
		emxgzip.pkg emxgzip.sis

BZ=../local/bzip2-1.0.2

BZIP2_FILES=$(BZ)/LICENSE \
	$(BZ)/bzip2 $(BZ)/bzip2recover $(BZ)/bzip2.1.preformatted

emxbzip2.sis: emxbzip2.pkg $(BZIP2_FILES)
	recode ../crlf <$(BZ)/LICENSE >LICENSE
	emxsis -D KEmxBzip2UidValue=$(KEmxBzip2UidValue) \
		emxbzip2.pkg emxbzip2.sis
	rm -f LICENSE

emxbzip2.zip: emxbzip2.sis $(BZ)/LICENSE
	zip -9j emxbzip2 emxbzip2.sis $(BZ)/LICENSE

A=../epoc/gawk

GAWK_FILES=$(A)/gawk

emxgawk.sis: FSF ../COPYING emxgawk.pkg $(GAWK_FILES)
	emxsis -D KEmxGawkUidValue=$(KEmxGawkUidValue) \
		emxgawk.pkg emxgawk.sis

R=../epoc/grep/src

GREP_FILES=$(R)/emxgrep.dll $(R)/grep.exe $(R)/egrep.exe $(R)/fgrep.exe \
	../epoc/grep/doc/grep.1

emxgrep.sis: FSF ../COPYING emxgrep.pkg $(GREP_FILES)
	emxsis -D KEmxGrepUidValue=$(KEmxGrepUidValue) \
		emxgrep.pkg emxgrep.sis

C=../epoc/recode/src

RECODE_FILES=$(C)/recode

emxrecode.sis: FSF ../COPYING emxrecode.pkg $(RECODE_FILES)
	emxsis -D KEmxRecodeUidValue=$(KEmxRecodeUidValue) \
		emxrecode.pkg emxrecode.sis

TAR_FILES=../epoc/tar/src/tar

emxtar.sis: FSF ../COPYING emxtar.pkg $(TAR_FILES)
	emxsis -D KEmxTarUidValue=$(KEmxTarUidValue) \
		emxtar.pkg emxtar.sis

F=../epoc/find

FIND_FILES=$(F)/find/find $(F)/xargs/xargs

emxfind.sis: FSF ../COPYING emxfind.pkg $(FIND_FILES)
	emxsis -D KEmxFindUidValue=$(KEmxFindUidValue) \
		emxfind.pkg emxfind.sis

D=../epoc/diff/src

DIFF_FILES=$(D)/cmp $(D)/diff $(D)/diff3 $(D)/sdiff

emxdiff.sis: FSF ../COPYING emxdiff.pkg $(DIFF_FILES)
	emxsis -D KEmxDiffUidValue=$(KEmxDiffUidValue) \
		emxdiff.pkg emxdiff.sis

G=../epoc/gcc/gcc

emxgcc-base.sis: FSF ../COPYING emxgcc-base.pkg \
		$(G)/xgcc $(G)/cpp $(G)/cpp0 $(G)/tradcpp0
	emxsis -D KEmxGccBaseUidValue=$(KEmxGccBaseUidValue) \
		emxgcc-base.pkg emxgcc-base.sis

emxgcc-c.sis: FSF ../COPYING emxgcc-c.pkg $(G)/cc1
	emxsis -D KEmxGccCUidValue=$(KEmxGccCUidValue) \
		emxgcc-c.pkg emxgcc-c.sis

emxgcc-c++.sis: FSF ../COPYING emxgcc-c++.pkg $(G)/cc1plus
	emxsis -D KEmxGccCppUidValue=$(KEmxGccCppUidValue) \
		emxgcc-c++.pkg emxgcc-c++.sis

U=../local/unzip-5.50

UNZIP_FILES=$(U)/LICENSE $(U)/unzip $(U)/unzip.txt $(U)/zipinfo.txt

emxunzip.sis: emxunzip.pkg $(UNZIP_FILES)
	recode ../crlf <$(U)/LICENSE >LICENSE
	emxsis -D KEmxUnzipUidValue=$(KEmxUnzipUidValue) \
		emxunzip.pkg emxunzip.sis
	rm -f LICENSE

emxunzip.zip: emxunzip.sis $(U)/LICENSE
	zip -9j emxunzip emxunzip.sis $(U)/LICENSE

Z=../local/zip-2.3

ZIP_FILES=$(Z)/LICENSE $(Z)/MANUAL $(Z)/zip

emxzip.sis: emxzip.pkg $(ZIP_FILES)
	recode ../crlf <$(Z)/LICENSE >LICENSE
	emxsis -D KEmxZipUidValue=$(KEmxZipUidValue) \
		emxzip.pkg emxzip.sis
	rm -f LICENSE

emxzip.zip: emxzip.sis $(Z)/LICENSE
	zip -9j emxzip emxzip.sis $(Z)/LICENSE

clean:
	rm -f *.sis *.zip LICENSE more.lnk
