# [Makefile wk 5.3.91] WkSWN: Simple Window System
#     Copyright (c) 1988-93 by Werner Koch (dd9jn)
# This file is part of WkSWN.
#
# WkSWN 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.
#
# WkSWN 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#

# Try to get some standard macros
-include $(WKLIBS)/wklib/config.mak

ifndef PROD
D=1
endif

include $(WKLIBS)/wklib/common.mak

TARGET_PREFIX := ../obj-wkswn
ifeq ($(target),i286-wtc-windoze)
# wtc-16-bit seems to be buggy
DO_NOT_OPTIMIZE = 1
endif
LDSH_FLAGS = -mv

include $(WKLIBS)/wklib/wklib.mak

X = $(exe_dir)/
O = $(obj_dir)/
C = $(target_prefix)/common/


########################################
# default path for target "distribution"
########################################
ifndef host_is_os2
dist_path=/vol1/OS2/D/usr/deliver
else
dist_path=d:/usr/deliver
endif
########################################

#---- list of source files ------
SRCS  = Makefile
SRCS += dlgwin0.c	#-- High level functions
SRCS += dlgwin1.c	#-- Open, close, get, put etc.
SRCS += dlgwin2.c	#-- Edit procedures
SRCS += dlgwin3.c	#-- Button handler
SRCS += dlgwin4.c	#-- Listbox handler
SRCS += dlgsig.c	#-- Signal handling
SRCS += pdmenu.c	#-- PullDown Menue handler
SRCS += hlpwin.c	#-- Help system
SRCS += event.c 	#-- Event handler

SRCS += rcmgr1.c	#-- Resource manager

SRCS += dlgsig.rc	#-- resources used by Signal handler

SRCS += scrmod0.c	#-- Init, open , close, hide etc.
SRCS += scrmod1.c	#-- Redirector and misc. functions
SRCS += scrmod2.c	#-- Scrollbar
ifdef host_is_os2
SRCS += scrdrv0.c	#-- Text mode driver
else
SRCS += scrdrv1.c	#-- Text mode driver using curses
endif

SRCS += dlgwin.h	#-- internal definitions for Dialog subsystem
SRCS += scr_sy.h	#-- internal definitions for Screen subsystem

SRCS_HC  = hc.c        #-- Help Compiler
SRCS_RC  = wkrc.c      #-  Resource Compiler
SRCS_RC += wkrc1.c
SRCS_RC += wkrc2.c
SRCS_RC += wkrc3.c
SRCS_RC += wkrc4.c
SRCS_RC += wkrc_1.c    #-- resource StrBlk + StrMsg
SRCS_RC += wkrc_2.c    #-- resource Plain
SRCS_RC += wkrc_3.c    #-- resource PDMenu
SRCS_RC += wkrc_4.c    #-- resource DlgWin
SRCS_RC += wkrc.h
SRCS_RC += rc.doc


#----- end of source list -----

OBJS := $(strip $(addprefix $(obj_dir)/, \
			    $(patsubst %.c,%$o	,$(filter %.c,$(SRCS)))))
OBJS_RC := $(strip $(addprefix $(obj_dir)/, \
			    $(patsubst %.c,%$o	,$(filter %.c,$(SRCS_RC)))))
OBJS_HC := $(strip $(addprefix $(obj_dir)/, \
			    $(patsubst %.c,%$o	,$(filter %.c,$(SRCS_HC)))))

ifndef host_is_os2
ADD_CFLAGS += -I/usr/include/ncurses
endif

ifdef WORK_IN_SRCDIR
%$x : %$o
	$(CC) -o $*$x $^ $(WKLIBS)/wklib/libwk1.a
endif

#######  dependencies  ##########

default :  check-args libwkswn$a tools

libwkswn$a : $(OBJS)
ifndef host_is_os2
	ar r $(lib_dir)/libwkswn$a $?
	ranlib $(lib_dir)/libwkswn$a
else
ifdef have_emx_tools
	emxomfar rc $(lib_dir)/libwkswn$a $?
else
	timecmp -v \"-f-+ '%s'\\n\" -o$(lib_dir)/lbc.tmp \
		  $(obj_dir)/*$o  $(lib_dir)/libwkswn$a
	wlib '$(subst /,\\,$(lib_dir)/libwkswn$a)' \
	     @'$(subst /,\\,$(obj_dir)/lbc.tmp)'
endif
endif

ifdef host_is_os2
world:
	$(MAKE) PROD=1 CPU=i386  SYSTEM=os2
	$(MAKE) PROD=1 CPU=i86	 SYSTEM=msdos  MODEL=L
	$(MAKE) PROD=1 CPU=i286  SYSTEM=windoze  MODEL=L
	$(MAKE) PROD=1 CPU=i386  SYSTEM=netware
	$(MAKE) PROD=1 DO_NOT_OPTIMIZE=1 CPU=i386  SYSTEM=msdos

else # host is not OS2
world:
	$(MAKE) PROD=1

endif # host is not OS2

make-dirs:
	for f in $(target_prefix) $(target_prefix)/common \
		 $(target_prefix)/$(target) $(obj_dir); do \
	   test -d $$f || mkdir $$f; \
	done

clean:
	-$(RM) out out2 *$o


tools : $Xwkrc$x   $Xhc$x


install: distribution

distribution: copy_source
	wkdutil -s $(dist_path)/  zip -u -r wkswn.zip wkswn

copy_source:
	update README Makefile *.c *.h	*.def *.asm *.rc *.doc \
	       $(dist_path)/wkswn/

.PHONY:  all clean all_dos all_os2 production all_unix world \
	 install distribution copy_source examples tools


#-------------------------------------
#-------------- deps -----------------
#-------------------------------------



$Xwkrc$x   : $(OBJS_RC)

$Xhc$x	   : $(OBJS_HC)


$Odlgwin0$o: dlgwin.h
$Odlgwin1$o: dlgwin.h
$Odlgwin2$o: dlgwin.h
$Odlgwin3$o: dlgwin.h
$Odlgwin4$o: dlgwin.h


#-------------------------------------
#--------- Test programs -------------
#-------------------------------------

examples :  $Xdtest$x	$Xdtest.exr


$Xdtest$x: $Odtest$o   $(OBJS)

$Xdtest.exr : dtest.h dtest.rc dlgsig.rc
	 $Xwkrc -o$Xdtest dtest.rc dlgsig.rc


#---- end of makefile ----#
