作者jans0204 (jans0204)
看板PLT
标题[实作] J005:AWKcc - awk-to-C transcompiler B
时间Tue Aug 23 13:43:09 2022
J005:AWKcc - awk-to-C transcompiler (PART B)
B. make libAWK.a
1. 抽取 awkcc-main.zip\awkcc-main\1988\orig\lib -> R:\_W_\lib\
2. 备份原档 -> R:\_W_\lib\prog\
cp awkrun.c
cp ear.h
mv makefile
cp misc.c
cp xprintf.c
cp y.tab.h
cp 表补钉。
3. 复制:stdarg.h
copy R:\_W_\awkcc\stdarg.h R:\_W_\lib\
4.1 PATCH - ear.h LINE_55
//extern char *malloc(), *realloc(), *calloc();
extern void *malloc(), *realloc(), *calloc();
4.2 PATCH - awkrun.c
LINE_98
//extern int fpecatch();
extern void fpecatch();
LINE_716
//fpecatch()
void fpecatch()
4.3 PATCH - misc.c LINE_129
//#include <varargs.h>
#include "stdarg.h"
4.4 PATCH - xprintf.c LINE_13
//#include <varargs.h>
#include "stdarg.h"
4.5 PATCH - y.tab.h 依据 R:\_W_\awkcc\y.tab.h 修正 token id
#define FINAL 268
#define DOT 269
#define ALL 270
#define CCL 271
#define NCCL 272
#define CHAR 273
#define OR 274
#define STAR 275
#define QUEST 276
#define PLUS 277
#define CAT 342 // same
4.6 编码 makefile
CC=gcc
CFLAGS=-O
SOURCES=misc.o lines.o make_str.o copystr.o index.o xprintf.o \
isreg.o awkrun.o awkmod.o assignvars.o awkerr.o clear_htb.o \
free_array.o clearctest.o delete.o docomp.o docompN.o \
regexp.o newb.o awkparse.o filedrop.o fileget.o getd.o \
getrec.o gsub.o n_insert.o s_insert.o insert.o make_array.o \
make_buckets.o make_elem.o make_var.o member.o number.o \
opennext.o pipeget.o printD0.o print_var.o resize.o \
rgetrec.o setctest.o split.o split2.o split3.o splitrec.o \
strsplitrec.o resplitrec.o sresize.o substr.o
libAWK.a: $(SOURCES)
ar -q libAWK.a $(SOURCES)
ranlib libAWK.a
clean:
rm -f *.o
5.1 产生 libAWK.a
进入 MSYS
$ cd /r/_W_/lib
$ make > make.log 2>&1
$ nm -s libAWK.a > libAWK.idx
$ make clean
rm -f *.o
5.2 安装:
md R:\awkcc\lib
mv libAWK.a R:\awkcc\lib
md R:\awkcc\include
cp *.h R:\awkcc\include
del R:\awkcc\include\stdarg.h
6. 测试:
下载 Hello_world_Text.awk -> R:\
https://rosettacode.org/wiki/Hello_world/Text#AWK
R:\set path=r:\awkcc\bin;%path%
R:\>awkcc Hello_world_Text.awk
R:\>set HEADERDIR=r:\awkcc\include
R:\>set AWKLIB=r:\awkcc\lib\libAWK.a
R:\>set MATHLIB=-lm
:: R:\>gcc -O -Ir:\awkcc\include -o a.out awker.c r:\awkcc\lib\libAWK.a -lm
R:\>gcc -O -I%HEADERDIR% -o a.out awker.c %AWKLIB% %MATHLIB%
R:\>strip a.out
R:\>del awker.c
R:\>a.out
Hello world!
R:\>
7. (END)
https://github.com/jans0204/J005-AWKcc---awk-to-C-transcompiler
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 124.218.31.163 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/PLT/M.1661233393.A.509.html
※ 编辑: jans0204 (124.218.31.163 台湾), 09/21/2022 16:21:08