# -*- Makefile -*- for gettext-tools/lib

#### Start of system configuration section. ####

# Flags that can be set on the nmake command line:
#   DLL=1     for compiling a .dll with a stub .lib (default is a static .lib)
#             Note that this works only with MFLAGS=-MD.
#   MFLAGS={-ML|-MT|-MD} for defining the compilation model
#     MFLAGS=-ML (the default)  Single-threaded, statically linked - libc.lib
#     MFLAGS=-MT                Multi-threaded, statically linked  - libcmt.lib
#     MFLAGS=-MD                Multi-threaded, dynamically linked - msvcrt.lib
#   DEBUG=1   for compiling with debugging information
#   PREFIX=Some\Directory   Base directory for installation
!if !defined(DLL)
DLL=0
!endif
!if !defined(DEBUG)
DEBUG=0
!endif
!if !defined(MFLAGS)
!if !$(DLL)
MFLAGS=
!else
MFLAGS=-MD
!endif
!endif
!if !defined(PREFIX)
PREFIX = c:\usr
!endif

# Directories used by "make install":
prefix = $(PREFIX)
exec_prefix = $(prefix)
bindir = $(exec_prefix)\bin
libdir = $(exec_prefix)\lib
includedir = $(prefix)\include

# Programs used by "make":

CC = cl

# Set to -W3 if you want to see maximum amount of warnings, including stupid
# ones. Set to -W1 to avoid warnings about signed/unsigned combinations.
WARN_CFLAGS = -W1

!if !$(DLL)
PICFLAGS =
!else
# "-GD" (msvc5) optimizes for DLL.
# mscv4 doesn't know about this flag and ignores it.
PICFLAGS = -GD
!endif

!if $(DEBUG)
OPTIMFLAGS = -Od -Z7
DEBUGFLAGS = -Z7
!else
# Some people prefer -O2 -G6 instead of -O1, but -O2 is not reliable in MSVC5.
OPTIMFLAGS = -D_NDEBUG -O1
DEBUGFLAGS =
!endif

CFLAGS = $(MFLAGS) $(WARN_CFLAGS) $(OPTIMFLAGS) -DHAVE_CONFIG_H -DEXEEXT=\".exe\" -DDEPENDS_ON_LIBINTL=1 -DDEPENDS_ON_LIBICONV=1

INCLUDES = -I. -I.. -I..\intl -I..\windows -I$(includedir)

AR = lib
AR_FLAGS = /out:

LN = copy
RM = -del

# Programs used by "make install":
INSTALL = copy
INSTALL_PROGRAM = copy
INSTALL_DATA = copy

#### End of system configuration section. ####

SHELL = /bin/sh

OBJECTS = \
  argmatch.obj \
  backupfile.obj addext.obj \
  basename.obj \
  c-ctype.obj \
  classpath.obj \
  copy-file.obj \
  error.obj \
  execute.obj \
  findprog.obj \
  fstrcmp.obj \
  full-write.obj \
  gcd.obj \
  getopt.obj getopt1.obj \
  hash.obj \
  javacomp.obj \
  javaexec.obj \
  linebreak.obj \
  mbswidth.obj \
  obstack.obj \
  concatpath.obj \
  pipe-bidi.obj pipe-in.obj pipe-out.obj \
  progname.obj progreloc.obj \
  safe-read.obj \
  safe-write.obj \
  sh-quote.obj \
  stpncpy.obj \
  strtoul.obj \
  tmpdir.obj \
  wait-process.obj \
  xerror.obj \
  xmalloc.obj xstrdup.obj \
  xsetenv.obj \
  \
  getline.obj \
  mkdtemp.obj \
  pfnmatch.obj \
  relocatable.obj \
  setenv.obj unsetenv.obj \
  stpcpy.obj \
  strcasecmp.obj strncasecmp.obj \
  vasprintf.obj

RESOURCES = gettextlib.res

all : gettextlib.lib

argmatch.obj : argmatch.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c argmatch.c

backupfile.obj : backupfile.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c backupfile.c

addext.obj : addext.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c addext.c

basename.obj : basename.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c basename.c

c-ctype.obj : c-ctype.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c c-ctype.c

classpath.obj : classpath.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c classpath.c

copy-file.obj : copy-file.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c copy-file.c

error.obj : error.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c error.c

execute.obj : execute.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c execute.c

findprog.obj : findprog.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c findprog.c

fstrcmp.obj : fstrcmp.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c fstrcmp.c

full-write.obj : full-write.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c full-write.c

gcd.obj : gcd.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c gcd.c

getopt.obj : getopt.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c getopt.c

getopt1.obj : getopt1.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c getopt1.c

hash.obj : hash.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c hash.c

javacomp.obj : javacomp.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c javacomp.c

javaexec.obj : javaexec.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c javaexec.c

linebreak.obj : linebreak.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c linebreak.c

mbswidth.obj : mbswidth.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c mbswidth.c

obstack.obj : obstack.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c obstack.c

concatpath.obj : concatpath.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c concatpath.c

pipe-bidi.obj : pipe-bidi.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c pipe-bidi.c

pipe-in.obj : pipe-in.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c pipe-in.c

pipe-out.obj : pipe-out.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c pipe-out.c

progname.obj : progname.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c progname.c

progreloc.obj : progreloc.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c progreloc.c

safe-read.obj : safe-read.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c safe-read.c

safe-write.obj : safe-write.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c safe-write.c

sh-quote.obj : sh-quote.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c sh-quote.c

stpncpy.obj : stpncpy.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c stpncpy.c

strtoul.obj : strtoul.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c strtoul.c

tmpdir.obj : tmpdir.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c tmpdir.c

wait-process.obj : wait-process.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c wait-process.c

xerror.obj : xerror.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c xerror.c

xmalloc.obj : xmalloc.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c xmalloc.c

xstrdup.obj : xstrdup.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c xstrdup.c

xsetenv.obj : xsetenv.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c xsetenv.c

getline.obj : getline.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c getline.c

mkdtemp.obj : mkdtemp.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c mkdtemp.c

pfnmatch.obj : pfnmatch.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c pfnmatch.c

relocatable.obj : relocatable.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c relocatable.c

setenv.obj : setenv.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c setenv.c

unsetenv.obj : unsetenv.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c unsetenv.c

stpcpy.obj : stpcpy.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c stpcpy.c

strcasecmp.obj : strcasecmp.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c strcasecmp.c

strncasecmp.obj : strncasecmp.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c strncasecmp.c

vasprintf.obj : vasprintf.c
	$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c vasprintf.c

!if !$(DLL)

gettextlib.lib : $(OBJECTS)
	-$(RM) gettextlib.lib
	$(AR) $(AR_FLAGS)gettextlib.lib $(OBJECTS)

!else

# gettextlib.dll and gettextlib.lib are created together.
gettextlib.lib : ..\windows\gettextlib.def $(OBJECTS) $(RESOURCES)
	$(CC) $(MFLAGS) $(DEBUGFLAGS) -LD ..\windows\gettextlib.def $(OBJECTS) ..\intl\intl.lib $(libdir)\iconv.lib $(RESOURCES) -Fegettextlib.dll

gettextlib.res : ../windows/gettextlib.rc
	rc -Fo gettextlib.res ../windows/gettextlib.rc

!endif

install : all force
	-mkdir $(prefix)
	-mkdir $(exec_prefix)
!if $(DLL)
	-mkdir $(bindir)
	$(INSTALL_DATA) gettextlib.dll $(bindir)\gettextlib.dll
!endif

installdirs : force
	-mkdir $(prefix)
	-mkdir $(exec_prefix)
!if $(DLL)
	-mkdir $(bindir)
!endif

uninstall : force
!if $(DLL)
	$(RM) $(bindir)\gettextlib.dll
!endif

check : all

mostlyclean : clean

clean : force
	$(RM) *.obj
	$(RM) *.lib
	$(RM) *.exp
	$(RM) *.dll
	$(RM) gettextlib.res
	$(RM) core

distclean : clean

maintainer-clean : distclean

force :
