# Makefile -- this file is part of the SYMLINK Library.
#
# Copyright (C) 1994, 1995 Ralph Schleicher
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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 Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


prefix = /usr/local
libdir = $(prefix)/lib
includedir = $(prefix)/include
moduledir = /lib
emxdir = /emx

# -DEMX				Use emx extensions instead of the OS/2 API.
#				This may not work correctly.  Thus, do not
#				define it.
# -DUSE_OS2_TOOLKIT_HEADERS	IBM's coding style does not obey ANSI rules.
#				Fix the Toolkit headers with this one-liner:
#				  perl -p -i~ -e "s/^(\s+)#/#\1/" *.h vdd/*.h
#
DEFS = -DUSE_OS2_TOOLKIT_HEADERS


### No more changes required.

SHELL = /bin/sh

O = .o
A = .a

CC = gcc
CPPFLAGS = -I. $(DEFS)
CFLAGS = -O2 -Wall
LDFLAGS = -s
LIBS =
AR = ar
RANLIB = $(AR) s

library = symlink
sources = symlink.c readlink.c resolvlink.c \
	open.c creat.c sopen.c access.c chmod.c	stat.c lstat.c \
        fopen.c freopen.c rename.c remove.c unlink.c \
	ea_open.c ea_close.c ea_get.c ea_set.c
objects = symlink$O readlink$O resolvlink$O \
	open$O creat$O sopen$O access$O chmod$O	stat$O lstat$O \
	fopen$O freopen$O rename$O remove$O unlink$O \
	ea_open$O ea_close$O ea_get$O ea_set$O


.SUFFIXES: .c $O .def .a .lib .sed

.c$O:
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $<

.a.lib:
	emxomf -s -l $<

.def.lib:
	implib -nologo -noignorecase $@ $<

.sed.def:
	sed -f $< < $(library).def.in > $@


default: static dynamic

static:
	$(MAKE) "subdir=st" "CC=gcc" mostlyclean all-static
	$(MAKE) "subdir=mt" "CC=gcc -Zmt" "CFLAGS=$(CFLAGS) -mprobe" \
	  mostlyclean all-static

all-static: $(library).a $(library).lib move

dynamic:
	$(MAKE) "O=.obj" "A=.lib" "subdir=st" "module=$(library)s" \
	  "CC=gcc -Zomf -Zdll -Zcrtdll" "CFLAGS=$(CFLAGS) -mprobe" \
	  mostlyclean all-dynamic
	$(MAKE) "O=.obj" "A=.lib" "subdir=mt" "module=$(library)m" \
	  "CC=gcc -Zomf -Zdll -Zcrtdll -Zmt" "CFLAGS=$(CFLAGS) -mprobe" \
	  mostlyclean all-dynamic

all-dynamic: $(module).lib $(module).dll move


ifeq ($(strip $(module)),)

$(library)$A: $(objects)
	-rm -f $@
	$(AR) cr $@ $(objects)
	$(RANLIB) $@

move:
	-mv -f $(library).a $(subdir)
	-mv -f $(library).lib $(subdir)

else

$(module).lib: $(module).def

$(module).dll: $(objects) $(module).def
	$(CC) $(LDFLAGS) -o $@ $(objects) $(module).def $(LIBS)

move:
	-mv -f $(module).lib $(subdir)/$(library)_import.lib

endif


mostlyclean:
	-rm -f *.o *.obj *.def

clean: mostlyclean
	-rm -f *.a *.lib *.dll *.exe *~


install:
	-$(SHELL) mkdirchain $(libdir)/st
	cp -f st/* $(libdir)/st
	-$(SHELL) mkdirchain $(libdir)/mt
	cp -f mt/* $(libdir)/mt
	-$(SHELL) mkdirchain $(includedir)/symlink
	cp -f symlink.h $(includedir)
	cp -f symlink/*.h $(includedir)/symlink
	-$(SHELL) mkdirchain $(moduledir)
	cp -f *.dll $(moduledir)

install-emx:
	cp -f st/* $(emxdir)/lib/st
	cp -f mt/* $(emxdir)/lib/mt

uninstall:
	-rm -f $(libdir)/st/symlink*
	-rm -f $(libdir)/mt/symlink*
	-rm -fr $(includedir)/symlink*
	-rm -f $(moduledir)/symlink*

uninstall-emx:
	-rm -f $(emxdir)/lib/st/symlink*
	-rm -f $(emxdir)/lib/mt/symlink*
