summaryrefslogtreecommitdiff
path: root/pc/Makefile
blob: 627a9612c04a78f35268910e1f25343f86f83fd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# Makefile for gawk (GNU awk)                                   31 Oct 1998
#
# - for GNU C (djgpp)         [32bit executable for DOS]
# - for GNU C (emx)           [32bit executable for OS/2 or DOS or Win32]
# - for GNU C (mingw32)	      [Win32 executable for Windows 9x/NT]
# - for MS-Visual C/C++ 4.x   [Win32 executable for Windows 9x/NT]
# - for Microsoft C 7         [16bit ececutable for DOS]
# - for Microsoft C 6.00A     [16bit executable for OS/2 or DOS]

# Tested with GNU make and dmake-3.8 under OS/2 and DOS, and ndmake and
# Microsoft nmake under DOS.  Compiling with dmake under DOS may require the 
# DOS-only version of dmake (so that swapping works).  nmake requires a
# few edits in the configuration section below.

default:
	@echo "Enter $(MAK) target "
	@echo " where 'target' is chosen from                          " 
	@echo "  djgpp ... DOS 32-bit exe [GNU C, Delorie, v2]         "
	@echo "  djgppv1 . DOS 32-bit exe [GNU C, Delorie, v1]         "
	@echo "  emx ..... OS/2 32-bit exe [emx/gcc; uses emxlibc.dll] "
	@echo "  emxnt ... NT exe [emx/gcc with RSXNT]                 "
	@echo "  emxbnd .. OS/2 and DOS 32-bit exe [emx/gcc]           "
	@echo "  mingw32 . Win32 exe [Mingw32 GNU C]                   "
	@echo "  msc ..... DOS exe [Microsoft C 7 & 8 (AKA 1.52)]      "
	@echo "  msc6 .... DOS exe [Microsoft C 6.00a]                 "
	@echo "  msc6os2 . OS/2 exe [Microsoft C 6.00a]                "
	@echo "  msc6bnd . OS/2 and DOS exe [Microsoft C 6.00a]        "
	@echo "  vcWin32 . Win32 exe [Microsoft Visual C]              "
	@echo "  ----------------------------------------------------- "
	@echo "  test .... Perform tests (see README_d/README.pc)      "
	@echo "  install . Install gawk under $(prefix)/               "

# Support dropped in 3.0
# - for Microsoft C 5.1       [16bit executable for OS/2 or DOS]
#	@echo "  msc51     DOS exe [Microsoft C 5.1]                   "
#	@echo "  msc51bnd  OS/2 and DOS exe [Microsoft C 5.1]          "

#======================= Configuration ==================================
RSPFILE = gawk.rsp
#
# Choose method for passing arguments to the linker.
#
# If compiling under OS/2 or if make can pass long lines
#LDRSP = $(GAWKOBJS)
#LNKRSP = $(LDRSP)
#
# else if make == dmake
# Response files for linker: dmake allows the macro expansion
#   $(macro_name:modifier_list:modifier_list:...)
# The macro mktmp creates a temporary file for the linker. 
# The 't' modifier is for tokenization. 
#LDRSP =   @$(mktmp $(<:t"\n"))
#LNKRSP = @$(mktmp $(<:t"+\n") ) # Space before final paren req
#
# else use brain-dead approach (emxbnd will need 'tr').
RSP = $(RSPFILE)
LDRSP = @$(RSP)
LNKRSP = $(LDRSP)
#------------------------------------------------------------------------
# Some makes do not define MAKE (and ndmake does not allow a define).
# Define MAK to be your make command.
#MAKE = dmake
MAK = $(MAKE) $(MAKEFILE)
#MAK = $(MAKE)
#MAKEFILE = -f Makefile
#MAK = make45 $(MAKEFILE)
#------------------------------------------------------------------------
# Define the base directory for the install. "make install" will install
# in bin, lib/awk, man, and info under $(prefix)/. Most likely, you should
# edit config.h so that $(prefix)/lib/awk appears as part of DEFPATH.
#prefix =
prefix = c:/gnu
#
# Define the install method. Method 1 is Unix-like (and requires cat,
# cp, mkdir, sed, and sh); method 2 uses gawk and batch files.
install = 1
#------------------------------------------------------------------------
# To work around command-line length problems, this makefile assumes
# that $($X) can be expanded.  If using a make (such as nmake) which 
# cannot handle such macros, define DO_LNK and DO_BIND for your target 
# as $(L<target>) and $(B<target>), resp.; e.g.,
#DO_LNK = $(LvcWin32)
#DO_BIND= $(BvcWin32)
# and then comment the following:
DO_LNK = $($(LNK))
DO_BIND= $($(BIND))
#========================================================================
# End of general configuration. Some platform-specific configuration
# notes appear below.

#========================================================================
#========================== DJGPP =======================================
#========================================================================

LDJG = $(CC) $(LF) -o gawk.exe $(LDRSP) $(LF2)
BDJG = stubify -g awk.exe | stubedit awk.exe runfile=gawk

djgpp:
	$(MAK) all \
	CC=gcc O=.o CF=-O2 \
	LNK=LDJG LF=-s LF2=-lm \
	BIND=BDJG

djgpp-debug:
	$(MAK) all \
	CC=gcc O=.o CF='-O2 -g' \
	LNK=LDJG LF2=-lm \
	BIND=BDJG

LDJGv1 = $(CC) $(LF) -o gawk $(LDRSP) $(LF2)
#BDJGv1 = coff2exe -s /djgpp/bin/go32.exe gawk
BDJGv1 = coff2exe gawk

djgppv1:
	$(MAK) all \
	CC=gcc O=.o CF=-O \
	LNK=LDJGv1 LF=-s LF2=-lm \
	BIND=BDJGv1

#========================================================================
#========================== EMX =========================================
#========================================================================

# Link command for OS/2 versions.
LEMX = $(CC) $(LF) -o $@ $(GAWKOBJS) gawk.def -lbsd $(LF2)

# Link and bind for DOS and OS/2 versions.
# emx-09 needs '-p' emx option here or in EMXOPT environ var.
# The following works with 0.9a or newer
LEMXBND = $(CC) $(LF) -o gawk $(LDRSP) gawk.def -lbsd $(LF2)
BEMX = emxbind -bs gawk  -p
# The following works with 0.9c or newer
#LEMXBND = $(CC) $(LF) -o a.out $(LDRSP) gawk.def -lbsd $(LF2)
#BEMX = emxbind -bs -o $@ a.out -p
#BEMX = emxbind -bs /emx/bin/emx.exe a.out $@ -p
BEMXD = emxbind -b -o $@ a.out -p

emx:
	$(MAK) all \
	"CC=gcc -Zomf" O=.obj "CF=-O -DOS2" \
	LNK=LEMX "LF=-s -Zcrtdll -Zstack 512" RSP=

emxnt:
	$(MAK) all \
	"CC=gcc -Zwin32 -Zcrtdll=rsxntcs" O=.o "CF=-O -DOS2" \
	LNK=LEMX "LF=-s -Zstack 512" RSP=

emxbnd:
	$(MAK) all \
	CC=gcc O=.o "CF=-O -DOS2 -DMSDOS" OBJ=popen.o \
	LNK=LEMXBND \
	BIND=BEMX "P=|tr \" \" \"\n\""

emxbnd-debug:
	$(MAK) all \
	CC=gcc O=.o "CF=-g -DOS2 -DMSDOS" OBJ=popen.o \
	LNK=LEMXBND \
	BIND=BEMXD "P=|tr \" \" \"\n\""

#========================================================================
#========================== MINGW32 =====================================
#========================================================================

LMINGW32 = $(CC) $(LF) -o $@ $(GAWKOBJS) $(LF2)
# The following might work around command-line length limitations:
#LMINGW32 = $(CC) $(LF) -o $@ *.o $(LF2)

mingw32:
	$(MAK) all \
	CC=gcc O=.o CF=-O OBJ=popen.o \
	LNK=LMINGW32 LF=-s RSP=

#========================================================================
#========================== MSC =========================================
#========================================================================

# stdargv, glob, and director are from Stewartson's sh. These provide
# globbing and enhanced argument-passing. MSC setargv.obj is a 
# more limited alternative (and it will permit a bound version).
#STDARGV = stdargv.obj glob.obj director.obj 
STDARGV = setargv.obj

# Optimization and library options:
# Os == optimize for size, Ot == optimize for speed, G2 == 286 or better
#MSCOPT = -Os -G2
MSCOPT = -Ot # -G2
# Alternate lib, does not use math coprocessor.
#MSCLIB = llibca
#MSCCL = -FPa
# Emulator lib, uses math coprocessor if present.
MSCLIB = llibce
MSCCL = -FPi
#MSCCL = -FPc

LMSC = link $(LF) $(LNKRSP) $(STDARGV)/NOE,$@,,/NOD:llibce $(MSCLIB)$(LF2)/STACK:0x4990,nul

# CLMSC-linking works when building under OS/2
CLMSC = $(CC) -o $@ $(LF) $(GAWKOBJS) $(STDARGV) $(LF2) -link /NOE/NOI/STACK:0x6f00

BMSC = bind $@ /n DOSMAKEPIPE DOSCWAIT


# Ugly hack: config.h defines __STDC__ if not defined on command-line.
# OS/2 versions can't use -Za in getid.c. MSC7 uses stub headers in pc/ 
# due to ANSI conflicts. MSC 5.1 defines __STDC__=0 regardless of ANSI flag.

# dmake-3.8 runs out of memory under DOS. Request that dmake
# swap itself out on these targets. Note that this won't have
# any affect on the bound OS/2 and DOS version of dmake-3.8.

.SWAP: msc msc-debug msc6 msc6os2 msc6bnd msc51 check

msc: 
	$(MAK) all \
	"CC=cl -nologo $(MSCCL)" O=.obj "CF=-AL -Ze -Ipc/include $(MSCOPT)" \
	OBJ=popen.obj \
	LNK=LMSC P=+
Lmsc = $(LMSC)  # for broken makes (nmake) which cannot expand $($X)
Bmsc =

msc-debug: 
	$(MAK) all \
	"CC=cl $(MSCCL)" O=.obj "CF=-AL -Ze -Ipc/include -W2 -Zi -Od" \
	OBJ=popen.obj \
	LNK=LMSC LF2=/CO P=+

msc6: 
	$(MAK) builtin.obj \
	"CC=cl -nologo $(MSCCL)" O=.obj "CF=-AL -Za $(MSCOPT) -Od"
	$(MAK) all \
	"CC=cl -nologo $(MSCCL)" O=.obj "CF=-AL -Za $(MSCOPT)" \
	OBJ=popen.obj \
	LNK=LMSC P=+
Lmsc6 = $(LMSC)  # for broken makes (nmake) which cannot expand $($X)
Bmsc6 =

msc6os2: 
	$(MAK) builtin.obj \
	"CC=cl -nologo $(MSCCL)" O=.obj "CF=-AL -DOS2 -UMSDOS $(MSCOPT) -Od"
	$(MAK) all \
	"CC=cl $(MSCCL)" O=.obj "CF=-AL -DOS2 -UMSDOS $(MSCOPT)" \
	LNK=LMSC "LF2=p,gawk.def" P=+

msc6bnd:
	$(MAK) builtin.obj \
	"CC=cl -nologo $(MSCCL)" O=.obj "CF=-AL -DOS2 $(MSCOPT) -Od"
	$(MAK) all \
	"CC=cl $(MSCCL)" O=.obj "CF=-AL -DOS2 $(MSCOPT)" \
	OBJ=popen.obj \
	LNK=LMSC "LF2=p,gawk.def" P=+ \
	BIND=BMSC
Lmsc6bnd = $(LMSC)  # for broken makes (nmake) which cannot expand $($X)
Bmsc6bnd = $(BMSC)


# Windows '9x / NT 
LvcWin32 = link -nologo -subsystem:console -release -out:$@ $(LNKRSP)

vcWin32:
	$(MAK) all \
	"CC=cl -nologo" O=.obj "CF=-o2 -DWIN32 -D__STDC__=0" \
	OBJ=popen.obj \
	LNK=LvcWin32


# Support dropped in 3.0
#msc51: 
#	$(MAK) all \
#	"CC=cl $(MSCCL)" O=.obj "CF=-AL -Za -D_MSC_VER=510 $(MSCOPT)" \
#	OBJ=popen.obj \
#	LNK=LMSC P=+
#
#msc51bnd:
#	$(MAK) all \
#	"CC=cl -AL ($MSCCL)" O=.obj "CF=-DOS2 -D_MSC_VER=510 $(MSCOPT)" \
#	OBJ=popen.obj \
#	LNK=CLMSC "LF=-Lp -Fb" "LF2=gawk.def"

#========================================================================

# Define BIND for BINDless compiles, otherwise $($(BIND)) may break.
BIND = EMPTY
EMPTY=

# bitwise operations (-DBITOPS) and non-decimal input data (-DNONDECDATA) are
# undocumented in 3.0.3.  They may be enabled in config.h, or added to CFLAGS.
CFLAGS = $(CF) -DGAWK -I. -DHAVE_CONFIG_H

# object files
AWKOBJS1 = array$O builtin$O eval$O field$O gawkmisc$O io$O main$O
AWKOBJS2 = missing$O msg$O node$O re$O version$O
AWKOBJS = $(AWKOBJS1) $(AWKOBJS2)

ALLOBJS = $(AWKOBJS) awktab$O getid$O $(OBJ)

# LIBOBJS
#       GNU and other stuff that gawk uses as library routines.
LIBOBJS= getopt$O getopt1$O regex$O dfa$O random$O

GAWKOBJS = $(ALLOBJS) $(LIBOBJS)

# clear out suffixes list
# .SUFFIXES:
.SUFFIXES: .c $O

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

# rules to build gawk
all : gawk.exe

gawk.exe:: $(GAWKOBJS) $(RSP)
	$(DO_LNK)
	$(DO_BIND)

$(RSPFILE) : $(GAWKOBJS)
	echo $(AWKOBJS1)$P > $@
	echo $(AWKOBJS2)$P >> $@
	echo awktab$O getid$O $(OBJ) $(LIBOBJS)$P >> $@

$(ALLOBJS):	awk.h dfa.h regex.h config.h

gawkmisc$O:	pc/gawkmisc.pc

getopt$O:	getopt.h

getopt1$O:	getopt.h

main$O:	patchlevel.h

# A bug in ndmake requires the following rule
awktab$O: awk.h awktab.c
	$(CC) -c $(CFLAGS) awktab.c

awktab.c:	awk.y
	bison -o $@ awk.y

alloca$O:	alloca.c


install: install$(install)

install1: 
	echo extproc sh $(prefix)/bin/igawk.cmd > igawk.cmd
	echo shift >> igawk.cmd
	cat pc/awklib/igawk >> igawk.cmd
	sed "s;igawk;$(prefix)/bin/igawk;" pc/awklib/igawk.bat > igawk.bat
	sh mkinstal.sh $(prefix)/bin
	sh mkinstal.sh $(prefix)/lib/awk $(prefix)/man/man1 $(prefix)/info
	cp *awk.exe igawk.bat igawk.cmd pc/awklib/igawk $(prefix)/bin
	cp awklib/eg/lib/* pc/awklib/igawk.awk $(prefix)/lib/awk
	cp doc/*.1 $(prefix)/man/man1
	cp doc/gawk.info $(prefix)/info

# install2 is equivalent to install1, but doesn't require cp, sed, etc.
install2:
	gawk -v prefix=$(prefix) -f install.awk

clean:
	rm -rf gawk gawk.exe gawk.map *.o *.obj core a.out $(RSPFILE)
#	cd doc && $(MAKE) clean
#	cd test && $(MAKE) clean
#	cd awklib && $(MAKE) clean

awklib/eg: doc/gawk.texi
	rm -fr awklib/eg
	sh -c "cd awklib && ../gawk -f extract.awk ../doc/gawk.texi"

check:
	@echo "Running the tests requires several unix-like utilities.  The"
	@echo "recommendation is to copy pc/Makefile.tst to test/Makefile.  Under"
	@echo "DOS, it may be necessary to run make from the test directory."
# The `-k' option to make should be unnecessary if using pc/Makefile.tst.
	sh -c "cd test && $(MAK) -k AWK=../gawk.exe"
#	sh -c "cd test && $(MAK) AWK=../gawk.exe bigtest extra"

test:	check

# for those who have the necessary tools:
TAGS:
	etags awk.h *.y custom.h *.c *.h

tags:
	ctags awk.h *.y custom.h *.c *.h