1##############################################################################
2# Copyright 2020 Thomas E. Dickey                                            #
3# Copyright 1998-2000,2006 Free Software Foundation, Inc.                    #
4#                                                                            #
5# Permission is hereby granted, free of charge, to any person obtaining a    #
6# copy of this software and associated documentation files (the "Software"), #
7# to deal in the Software without restriction, including without limitation  #
8# the rights to use, copy, modify, merge, publish, distribute, distribute    #
9# with modifications, sublicense, and/or sell copies of the Software, and to #
10# permit persons to whom the Software is furnished to do so, subject to the  #
11# following conditions:                                                      #
12#                                                                            #
13# The above copyright notice and this permission notice shall be included in #
14# all copies or substantial portions of the Software.                        #
15#                                                                            #
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
19# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
22# DEALINGS IN THE SOFTWARE.                                                  #
23#                                                                            #
24# Except as contained in this notice, the name(s) of the above copyright     #
25# holders shall not be used in advertising or otherwise to promote the sale, #
26# use or other dealings in this Software without prior written               #
27# authorization.                                                             #
28################################################################################
29# $Id: Makefile.os2,v 1.12 2020/02/02 23:34:34 tom Exp $
30#
31# Wrapper Makefile for ncurses library under OS/2.
32# Author:  Juan Jose Garcia Ripoll <worm@arrakis.es>.
33# Webpage: http://www.arrakis.es/~worm/
34################################################################################
35#
36# Notes (from I Zakharevich)
37# ~~~~~~~~~~~~~~~~~~~~~~~~~~
38# I could build the library with the following sequence of commands:
39#
40#   touch Makefile
41#   make -f Makefile.os2 config
42#   make -f Makefile.os2 CC=gcc HOSTCC=gcc CXX=gcc
43#
44# Ignoring the following errors:
45#   Invalid configuration `os2'...
46#   ... ac_maketemp="make": not found
47#   ... syntax error: `done' unexpected
48#   No rule to make target `lib/ncurses4.dll'
49#
50# You may need to run
51#
52#   rm make.defs
53#   make -f Makefile.os2 make.defs
54#
55# if the build of misc/panel.def fails.
56#
57# If you do not have perl, the configuration will fail.  Use autoconf to
58# generate the EMX-specific configure script (see README.emx), and run the
59# configure script to generate the makefiles.  Then, run
60#
61#   make -f Makefile.os2 make.dlls
62#
63# Notes (from J J G Ripoll)
64# ~~~~~~~~~~~~~~~~~~~~~~~~~
65# The `make.defs' rule creates the new '.def' files and outputs a diagnostic
66# about symbols that disappear from one release to the other, as well as
67# checks about the new '.def' consistency.  If there were no problems, the
68# maintainer is free to replace the `.ref' files with the newer ones using the
69# `save.defs' rule.  So, the only tough work is ensuring that the symbols that
70# disappear are not essential.
71#
72# I first thought about killing '_nc_*' symbols, but it seems that some of
73# them --_nc_panel_hook, _nc_ada*, etc-- are needed outside ncurses.dll. 
74# However, the whole size of the export table will not be larger than 1k or
75# so.
76#
77# [installation]
78#
79# The way things are handled in misc/Makefile is not well suited for OS/2,
80# where only emx.src is needed.  Thus, I've written a few wrapper rules in
81# Makefile.os2 that handle installation/deinstallation.
82#
83# [distribution]
84#
85# There's also a new rule that configures and builds a sort of binary
86# distribution, much like the one I prepared for 1.9.9e.  It's `os2dist'.
87#
88################################################################################
89
90all :: config
91
92# This is for configuring
93
94# What is a useful value for this?
95CONFIG_OPTS	= --enable-termcap
96WWWGET		= lynx -source
97MV_F		= mv -f
98DLL_LN_OPTS	= -Zcrtdll -Zdll -Zomf -Zmt
99
100config: config.cache
101
102config.cache: configure.cmd configure
103	-$(MV_F) $@ $@.ref
104	configure.cmd $(CONFIG_OPTS)
105
106configure.cmd: configure convert_configure.pl
107	perl convert_configure.pl configure > $@
108
109convert_configure.pl:
110	$(WWWGET) ftp://ftp.math.ohio-state.edu/pub/users/ilya/os2/$@ > $@
111
112install ::
113	echo ***
114	echo *** Do not use this command. Use install.os2 instead.
115	echo ***
116	exit 2
117
118install.os2 : install.emxdata install.libs install.progs
119
120include ./Makefile
121
122all :: make.dlls
123
124#
125# DLLs and that stuff
126#
127
128LIBRARIES = ncurses form menu panel
129
130DLL_TAG = $(NCURSES_MAJOR)
131LIB_TAG = _s
132
133DLL_ROOTS = $(addsuffix $(DLL_TAG), $(LIBRARIES))
134DLLS = $(addsuffix .dll, $(addprefix ./lib/, $(DLL_ROOTS)))
135
136LIB_ROOTS = $(addsuffix $(LIB_TAG), $(LIBRARIES))
137LIBS = $(addsuffix .lib, $(addprefix ./lib/, $(LIB_ROOTS)))
138
139LIBS_AOUT = $(addsuffix .a, $(addprefix ./lib/, $(LIB_ROOTS)))
140
141DEFS = $(addsuffix .def, $(addprefix ./misc/, $(LIBRARIES)))
142
143DLL_SIGNATURE = NCurses-$(NCURSES_MAJOR)-$(NCURSES_MINOR)-$(NCURSES_PATCH)
144
145./lib/%$(LIB_TAG).lib : ./misc/%.def
146	emximp -o $@ $<
147
148./lib/%$(LIB_TAG).a : ./misc/%.def
149	emximp -o $@ $<
150
151./lib/%$(DLL_TAG).dll : ./lib/%.a
152	emxomf -o ./lib/$*$(DLL_TAG).lib $<
153	if [ "$*" = "ncurses" ]; then \
154		gcc $(LDFLAGS) $(DLL_LN_OPTS) ./lib/$*$(DLL_TAG).lib \
155				./misc/$*.def -o $@; \
156	else \
157		gcc $(LDFLAGS) $(DLL_LN_OPTS) ./lib/$*$(DLL_TAG).lib \
158				./lib/ncurses$(LIB_TAG).lib ./misc/$*.def -o $@; \
159	fi
160	-rm -f ./lib/$*$(DLL_TAG).lib
161
162make.dlls : $(DEFS) $(LIBS) $(DLLS) $(LIBS_AOUT)
163
164$(DEFS) : make.defs
165
166LIBDIR	= $(DESTDIR)$(libdir)
167$(LIBDIR) :
168	mkdir -p $@
169
170install.libs :: $(LIBS) $(DLLS) $(LIBDIR)
171	@for i in $(DLL_ROOTS); do \
172	echo installing ./lib/$$i.dll as $(LIBDIR)/$$i.dll; \
173	$(INSTALL_DATA) ./lib/$$i.dll $(LIBDIR)/$$i.dll; done
174	@for i in $(LIB_ROOTS); do \
175	echo installing ./lib/$$i.lib as $(LIBDIR)/$$i.lib; \
176	$(INSTALL_DATA) ./lib/$$i.lib $(LIBDIR)/$$i.lib; done
177
178uninstall.libs ::
179	-@for i in $(DLL_ROOTS); do \
180	echo uninstalling $(LIBDIR)/$$i.dll; \
181	rm -f $(LIBDIR)/$$i.dll; done
182	-@for i in $(LIB_ROOTS); do \
183	echo uninstalling $(LIBDIR)/$$i.lib; \
184	rm -f $(LIBDIR)/$$i.lib; done
185
186make.defs :
187	for i in $(LIBRARIES); do \
188	echo LIBRARY $${i}$(DLL_TAG) INITINSTANCE TERMINSTANCE > ./misc/$$i.def; \
189	echo DESCRIPTION \"$(DLL_SIGNATURE), module $$i\" >> ./misc/$$i.def; \
190	echo CODE LOADONCALL >> ./misc/$$i.def; \
191	echo DATA LOADONCALL NONSHARED MULTIPLE >> ./misc/$$i.def; \
192	echo EXPORTS >> ./misc/$$i.def; \
193	echo Creating $$i.def; \
194	(cmd /C ".\\misc\\makedef.cmd ./lib/$$i.a ./misc/$$i.ref >> ./misc/$$i.def" \
195	 && cmd /C ".\\misc\\chkdef.cmd ./misc/$$i.def") \
196	|| exit 1; \
197	done
198	touch make.defs
199
200save.defs :
201	for i in $(LIBRARIES); do \
202	test -f ./misc/$$i.def && cp ./misc/$$i.def ./misc/$$i.ref; \
203	done
204
205clean \
206os2clean ::
207	-rm -f $(DLLS) $(LIBS)
208
209realclean ::
210	-rm -f $(addprefix ./misc/, $(addsuffix .def, $(LIBRARIES)))
211
212#
213# This is a simplified version of misc/Makefile
214#
215
216TICDIR = $(DESTDIR)$(datadir)/terminfo
217TABSETDIR = $(DESTDIR)$(datadir)/tabset
218
219$(TICDIR) :
220	mkdir -p $@
221
222install \
223install.emxdata :: $(TICDIR)
224	-@rm -fr $(TICDIR)/*
225	echo Building terminfo database, please wait...
226	set TERMINFO=$(TICDIR); ./progs/tic ./misc/emx.src
227	echo Installing the terminfo cleaner and the sources...
228	cp ./misc/emx.src ./misc/cleantic.cmd $(TICDIR)
229	./misc/cleantic.cmd $(TICDIR)
230
231uninstall \
232uninstall.emxdata ::
233	-cd $(TICDIR) && rm -rf *
234	-cd $(TABSETDIR) && rm -rf *
235
236#
237# This is for preparing binary distributions
238#
239
240OS2NAME=ncurses-$(NCURSES_MAJOR).$(NCURSES_MINOR)-emx
241
242#
243# FIXME: this assumes that we can rerun the configure script, changing only
244# the install-prefix.  That means we cannot provide "interesting" options
245# when building.
246#
247os2dist :
248	$(MAKE) -f Makefile.os2 os2clean
249	./configure --without-debug --with-install-prefix=`pwd|sed -e 's@^.:@@'`/$(OS2NAME)
250	$(MAKE) -f Makefile.os2 $(CF_MFLAGS) install.os2
251	-rm -f $(OS2NAME).zip
252	echo NCurses-$(NCURSES_MAJOR).$(NCURSES_MINOR)-$(NCURSES_PATCH) for emx > $(OS2NAME)/FILE_ID.DIZ
253	echo Binary release. >> $(OS2NAME)/FILE_ID.DIZ
254	zip -r $(OS2NAME).zip ./$(OS2NAME)
255
256clean \
257os2clean ::
258	-rm -rf $(OS2NAME)
259	-rm -f $(OS2NAME).zip
260
261