1# Hello, emacs: this is a -*- Makefile -*-
2#
3# GNUPLOT Makefile for DJGPP version 2 using a cross compiler and a Unix-like shell
4#
5# Tested on Windows using MSYS2.
6#
7# Usage:
8#   Change the configuration section in 'config/djgpp/Makfile' to
9#     match your setup.
10#   Start e.g. the MSYS/MSYS2 prompt and change directory to 'config/djgpp'.
11#   Options can also be changed on the command line, e.g.:
12#	 make GD=1 LUA=1 ICONV=1 CERF=1 MGRX=1 all
13#	 make install
14#
15# AUTHORS : several ... including Edzer Pebesma <pebesma@metoor.frw.uva.nl>
16#           and         Hans-Bernhard Broeker <broeker@physik.rwth-aachen.de>
17#           and         Bastian Maerkisch
18#
19# "install" target: copies the executable etc.to a given
20# directory; to customize change FINALDEST below
21#
22
23# External libraries
24#  Use the MGRX fork instead of GRX
25#MGRX=1
26#  lua, libiconv and readline are available as binaries
27LUA=1
28ICONV=1
29#READLINE=1
30#  libgd has to be compiled from sources, it requires
31#  libjpeg, libpng16 and libz (binaries available) and
32#  freetype (sources)
33#GD=1
34#GD_FONTCONFIG=1
35#  cerf has to be compiled from sources
36#CERF=1
37
38# Options
39DJSVGA=1
40MOUSE=1
41#DEBUG=1
42
43# Choose cross-platform compilation (CROSS not defined is untested)
44CROSS=1
45
46#
47# Destination of the install target
48# (no trailing \ for directory names)
49FINALDEST=c:/dos
50
51# here customize the name of the executable
52# exe file will be  gnuplot.exe:
53EXENAME = gnuplot
54
55# where to place gnuplot.gih helpfile upon MAKE
56# note it will be built inside gnuplot\$(HELPDEST)
57# and eventually copied to FINALDEST during install
58HELPDEST =.
59
60# name of the helpfile
61HELPFILE =gnuplot.gih
62
63# gnuplot will look for gnuplotrc here:
64GNUPLOT_SHARE_DIR = share
65
66# Where to install the PostScript prologue files, relatively to the executable
67# gnuplot.exe
68GNUPLOT_PS_DIR = share/PostScript
69
70# Similarly for javascript files for the canvas terminal:
71GNUPLOT_JS_DIR = share/js
72
73# Similarly for lua scripts used by the lua terminal
74GNUPLOT_LUA_DIR = share/lua
75
76# Install will put TeX files here:
77GNUPLOT_TEX_DIR = share/texmf/tex
78
79
80# DJGPP (cross-)compiler
81ifdef CROSS
82DJDIR = c:/DJGPP/i586-pc-msdosdjgpp
83DJBIN = c:/DJGPP/bin
84CC = $(DJBIN)/i586-pc-msdosdjgpp-gcc
85OBJCOPY = $(DJBIN)/i586-pc-msdosdjgpp-objcopy
86STUBIFY = $(DJDIR)/bin/stubify
87DXE3GEN = $(DJDIR)/bin/dxe3gen
88UNIXTOOLS=1
89else
90CC = gcc
91OBJCOPY = objcopy
92STUBIFY = stubify
93DXE3GEN = dxe3gen
94endif
95
96ifdef UNIXTOOLS
97COPY = cp -p
98DEL = rm
99MKDIR = mkdir -p
100XCOPY = cp -r
101WD = ./
102SS = \"
103else
104COPY = copy
105DEL = del
106MKDIR = md
107XCOP = xcopy
108WD =
109SS = "
110endif
111
112# Native compiler
113NCC = gcc
114
115# include directories
116INCLUDE = -I. -I$(S) -Ic:/djgpp/include
117NINCLUDE = -I$(TOP)/config/mingw -I$(S)
118
119# libraries
120LIB = -Lc:/djgpp/lib
121
122TERMFLAGS = \
123	-DGNUPLOT_PS_DIR=$(SS)$(GNUPLOT_PS_DIR)$(SS) \
124	-DGNUPLOT_JS_DIR=$(SS)$(GNUPLOT_JS_DIR)$(SS)
125TERMLIBS =
126
127ifdef LUA
128	OPTS += -DHAVE_LUA
129	TERMFLAGS += -DGNUPLOT_LUA_DIR=$(SS)$(GNUPLOT_LUA_DIR)$(SS)
130	TERMLIBS += -llua
131	LUATARGETS += gnuplot-lua-tikz.sty
132	LUA_HELP = gnuplot-tikz.help
133endif
134
135# for svga term driver
136ifdef DJSVGA
137ifndef MGRX
138	TERMFLAGS += -DDJSVGA=1 -DHAVE_GRX -Ic:/djgpp/contrib/grx249/include
139	TERMLIBS  += -Lc:/djgpp/contrib/grx249/lib/dj2 -lgrx20
140else
141	TERMFLAGS += -DDJSVGA=1 -DHAVE_GRX -DHAVE_MGRX -Ic:/djgpp/contrib/mgrx110/include
142	TERMLIBS  += -Lc:/djgpp/contrib/mgrx110/lib/dj2 -lmgrx
143endif
144else
145	TERMFLAGS += -DDJSVGA=0
146endif
147
148ifdef MOUSE
149#ifdef MGRX
150	OPTS += -DUSE_MOUSE
151#endif
152endif
153
154ifdef ICONV
155	OPTS += -DHAVE_ICONV
156	LIB += -liconv
157endif
158
159ifdef GD
160	OPTS += -Ic:/djgpp/include/gd \
161		-DHAVE_LIBGD -DHAVE_GD_H -DHAVE_GD_GIF -DGIF_ANIMATION -DHAVE_GD_PNG -DHAVE_GD_JPEG \
162		-DHAVE_GD_TTF
163	TERMLIBS += -lgd -ljpeg -lpng16 -lz \
164		-lfreetype
165ifdef GD_FONTCONFIG
166	TERMLIBS += -lfontconfig -lexpat -luuid -lfreetype
167endif
168endif
169
170ifdef READLINE
171	OPTS += -DHAVE_LIBREADLINE -D HAVE_READLINE_READLINE_H -DHAVE_READLINE_HISTORY_H -DHAVE_READLINE_RESET \
172		-DHAVE_READLINE_SIGNAL_HANDLER -DHAVE_READLINE_PENDING_SIGNAL
173	LIB += -lreadline
174endif
175
176ifdef CERF
177	OPTS += -DHAVE_LIBCERF -DNEED_CEXP
178	LIB += -lcerf
179endif
180
181ifdef DEBUG
182	OPTS += -g
183endif
184
185# HBB : added $(OPTS) so user can
186#   change CFLAGS easily, without having to change makefile
187CFLAGS = -DHAVE_CONFIG_H \
188	-DGNUPLOT_SHARE_DIR=$(SS)$(GNUPLOT_SHARE_DIR)$(SS) \
189	-O2 $(OPTS) -Wall -Wno-misleading-indentation
190
191LINKOPT = $(LDFLAGS) $(LIB) $(TERMLIBS) -lm -lpc
192ifdef DEBUG
193	LINKOPT += -g
194endif
195
196# abbreviations for relative directory names
197TOP=../..
198S=$(TOP)/src/
199T=$(TOP)/term/
200D=$(TOP)/docs/
201M=$(TOP)/demo/
202O=o
203
204VPATH = $(S)
205
206# use makefile.all:
207include $(S)/makefile.all
208
209OBJS = $(COREOBJS) version.$(O)
210
211.SUFFIXES: .exe .o .c
212
213.c.o:
214	$(CC) -c $(CFLAGS) $(INCLUDE) -MMD -MT '$*.o' -MF $*.d -o $@ $<
215
216all: $(EXENAME).exe  $(HELPDEST)/$(HELPFILE)  $(M)binary?  demo_plugin.dxe  $(LUATARGETS)
217
218# -s performs the coff2exe step implicitly (?)
219# HBB: that's plain wrong: -s means 'strip executable',
220#   and stubify (formerly called stubify) is now always done
221#   automatically in the link step. I changed this so you
222#   get a debuggable gnuplot, but a stripped gnuplot.exe
223$(EXENAME).exe : $(OBJS)
224	$(CC) -o $(EXENAME) $(OBJS) $(LINKOPT)
225	$(OBJCOPY) --strip-all $(EXENAME) $(EXENAME).exe
226	$(STUBIFY) $(EXENAME).exe
227
228command.o: command.c plot.h setshow.h help.h
229	$(CC) -c $(CFLAGS) $(INCLUDE) -DHELPFILE=$(SS)$(HELPFILE)$(SS) -MMD -MT '$*.o' -MF $*.d -o $@ $<
230
231show.o: show.c plot.h setshow.h
232	$(CC) -c $(CFLAGS) $(INCLUDE) -DHELPFILE=$(SS)$(HELPFILE)$(SS) -MMD -MT '$*.o' -MF $*.d -o $@ $<
233
234term.o: term.c term.h plot.h setshow.h bitmap.h $(CORETERM)
235	$(CC) -c $(CFLAGS) $(INCLUDE) $(TERMFLAGS) -I$(T) -MMD -MT '$*.o' -MF $*.d -o $@ $<
236
237EMAIL=gnuplot-info@lists.sourceforge.net
238version.o: version.c
239	$(CC) -c -DCONTACT=$(SS)$(EMAIL)$(SS) $(CFLAGS) $(INCLUDE) -MMD -MT '$*.o' -MF $*.d -o $@ $<
240
241# convert gnuplot.doc to gnuplot.gih
242$(HELPDEST)/$(HELPFILE): doc2gih.exe $(D)gnuplot.doc
243	$(WD)doc2gih.exe  $(D)gnuplot.doc > $@
244
245doc2gih.exe: $(D)doc2gih.c $(D)termdoc.c $(CORETERM) $(LUA_HELP)
246	$(NCC) $(CFLAGS) -DWINDOWS_NO_GUI $(NINCLUDE) $(TERMFLAGS) -I$(T) -o $@ $(D)doc2gih.c $(D)termdoc.c
247
248demo_plugin.o: $(M)plugin/demo_plugin.c
249	$(CC) $(CFLAGS) $(INCLUDE) -I$(M)plugin -c -o $@ $<
250
251demo_plugin.dxe: demo_plugin.o
252ifdef CROSS
253	PATH=$(subst /,\\,$(DJBIN)) DJDIR=$(DJDIR) $(DXE3GEN) -o $@ -V -E _sinc -E _nsinc -E _divisors $< -lm -lc
254else
255	$(DXE3GEN) -o $@ -V -E _sinc -E _nsinc -E _divisors $< -lm -lc
256endif
257
258gnuplot-lua-tikz.sty: $(T)/lua/gnuplot-tikz.lua
259	lua.exe $< style
260
261$(LUA_HELP): $(T)/lua/gnuplot-tikz.lua
262	lua.exe $< termhelp > $@
263
264# now for the demo bin
265$(M)binary?: bf_test.exe
266	$(WD)bf_test.exe
267	$(COPY) binary? $(M)
268	$(DEL) binary?
269
270bf_test.o: bf_test.c
271	$(NCC) $(NINCLUDE) $(CFLAGS) -c $<
272
273bf_test.exe: bf_test.o
274	$(NCC) $(NINCLUDE) $(CFLAGS) -DWINDOWS_NO_GUI bf_test.o -lm -o $@
275
276# now install things and create a .bat file to make things easier
277install: all
278	-$(MKDIR) $(FINALDEST)\bin
279	$(COPY) $(EXENAME).exe $(FINALDEST)\bin
280ifdef DEBUG
281	$(COPY) $(EXENAME) $(FINALDEST)\bin
282endif
283	$(COPY) $(HELPDEST)\\$(HELPFILE) $(FINALDEST)\bin
284# configuration files
285	-$(MKDIR) $(FINALDEST)/$(GNUPLOT_SHARE_DIR)
286	$(COPY) $(TOP)/share/gnuplotrc $(FINALDEST)/$(GNUPLOT_SHARE_DIR)
287	$(COPY) $(TOP)/share/*.gp $(FINALDEST)/$(GNUPLOT_SHARE_DIR)
288# terminal support files
289	-$(MKDIR) $(FINALDEST)/$(GNUPLOT_PS_DIR)
290	$(COPY) $(TOP)/term/PostScript/*.ps $(FINALDEST)/$(GNUPLOT_PS_DIR)/
291	$(COPY) $(TOP)/term/PostScript/*.txt $(FINALDEST)/$(GNUPLOT_PS_DIR)/
292	-$(MKDIR) $(FINALDEST)/$(GNUPLOT_JS_DIR)
293	$(COPY) $(TOP)/term/js/*.* $(FINALDEST)/$(GNUPLOT_JS_DIR)/
294	$(COPY) $(TOP)/term/js/README $(FINALDEST)/$(GNUPLOT_JS_DIR)/
295	$(MKDIR) $(FINALDEST)/$(GNUPLOT_TEX_DIR)/generic/gnuplot
296	$(MKDIR) $(FINALDEST)/$(GNUPLOT_TEX_DIR)/plain/gnuplot
297	$(MKDIR) $(FINALDEST)/$(GNUPLOT_TEX_DIR)/latex/gnuplot
298	$(MKDIR) $(FINALDEST)/$(GNUPLOT_TEX_DIR)/context/gnuplot
299	$(COPY) $(TOP)/share/LaTeX/README $(FINALDEST)/$(GNUPLOT_TEX_DIR)/latex/gnuplot/
300	$(COPY) $(TOP)/share/LaTeX/gnuplot.cfg $(FINALDEST)/$(GNUPLOT_TEX_DIR)/latex/gnuplot/
301ifdef LUA
302	$(MKDIR) $(FINALDEST)/$(GNUPLOT_LUA_DIR)
303	$(COPY) $(TOP)/term/lua/README $(FINALDEST)/$(GNUPLOT_LUA_DIR)/
304	$(COPY) $(TOP)/term/lua/NEWS $(FINALDEST)/$(GNUPLOT_LUA_DIR)/
305	$(COPY) $(TOP)/term/lua/TODO $(FINALDEST)/$(GNUPLOT_LUA_DIR)/
306	$(COPY) $(TOP)/term/lua/gnuplot-tikz.lua $(FINALDEST)/$(GNUPLOT_LUA_DIR)/
307	-$(COPY) gnuplot-lua-tikz.sty $(FINALDEST)/$(GNUPLOT_TEX_DIR)/latex/gnuplot/
308	-$(COPY) gnuplot-lua-tikz.tex $(FINALDEST)/$(GNUPLOT_TEX_DIR)/plain/gnuplot/
309	-$(COPY) t-gnuplot-lua-tikz.tex $(FINALDEST)/$(GNUPLOT_TEX_DIR)/context/gnuplot/
310	-$(COPY) gnuplot-lua-tikz-common.tex $(FINALDEST)/$(GNUPLOT_TEX_DIR)/generic/gnuplot/
311endif
312# README etc
313	-$(COPY) $(TOP)/readme.dj2 $(FINALDEST)/
314	$(COPY) $(TOP)/Copyright $(FINALDEST)/
315	$(COPY) $(TOP)/README $(FINALDEST)/
316	$(COPY) $(TOP)/NEWS $(FINALDEST)/
317	$(COPY) $(TOP)/BUGS $(FINALDEST)/
318	$(COPY) $(TOP)/RELEASE_NOTES $(FINALDEST)/
319	$(COPY) $(TOP)/INSTALL $(FINALDEST)/
320	#-unix2dos $(FINALDEST)/*.txt $(FINALDEST)/README
321	#-unix2dos $(FINALDEST)/Copyright $(FINALDEST)/NEWS $(FINALDEST)/BUGS $(FINALDEST)/RELEASE_NOTES
322# demo and contrib
323	$(MKDIR) $(FINALDEST)/demo
324	-$(COPY) $(M)* $(FINALDEST)/demo/
325	$(MKDIR) $(FINALDEST)/demo/games
326	-$(COPY) $(M)games/* $(FINALDEST)/demo/games/
327	$(MKDIR) $(FINALDEST)/demo/plugin
328	-$(COPY) $(M)plugin/* $(FINALDEST)/demo/plugin/
329	-$(COPY) demo_plugin.dxe $(FINALDEST)/demo/plugin/
330#HBB: if at all, this batch-file should only be generated by a
331#separate target, like 'install-bat'. Besides, it doesn't work,
332#as is, because DOS always executes foo.exe before even looking for
333#a foo.bat
334#	$(DEL)  $(EXENAME).bat
335#	echo @echo off > $(EXENAME).bat
336#	echo SET GNUHELP= $(FINALDEST)\\$(HELPFILE) >> $(EXENAME).bat
337#	echo SET GNUPLOT= $(FINALDEST) >> $(EXENAME).bat
338#	echo $(FINALDEST)\\$(EXENAME).exe %1 %2 %3 %4 %5 %6 >> $(EXENAME).bat
339#	echo SET GNUHELP= >> $(EXENAME).bat
340#	echo SET GNUPLOT= >> $(EXENAME).bat
341#	$(COPY) $(EXENAME).bat $(FINALDEST)
342
343
344# clean target - remove all temp files, but leave executable intact
345clean:
346	-$(DEL) *.o
347	-$(DEL) $(EXENAME)
348	-$(DEL) doc2gih
349	-$(DEL) doc2gih.exe
350	-$(DEL) bf_test
351	-$(DEL) bf_test.exe
352
353# realclean target - remove all files created by the makefile
354realclean: clean
355	-$(DEL) $(EXENAME).exe
356	-$(DEL) $(HELPDEST)/$(HELPFILE)
357	-$(DEL) $(TOP)/demo/binary1
358	-$(DEL) $(TOP)/demo/binary2
359	-$(DEL) $(TOP)/demo/binary3
360	-$(DEL) $(TOP)/demo/fit.log
361	-$(DEL) $(TOP)/demo/soundfit.par
362	-$(DEL) demo_plugin.dxe
363
364ifndef NODEPS
365-include $(OBJS:.$(O)=.d)
366endif
367
368#####
369##     END OF GNUPLOT MAKEFILE FOR DJGPP V2
370#####
371