diff --git a/README.md b/README.md index 5be363e..e2f370d 100644 --- a/README.md +++ b/README.md @@ -334,4 +334,19 @@ is required later for autotools. #### Part 28: gawk 3.0.4 `gawk` is the GNU implementation of `awk`, yet another pattern matching and data -extraction utility. It is also required for autotools. \ No newline at end of file +extraction utility. It is also required for autotools. + +#### Part 29: perl 5.000 + +Perl is a general purpose programming language that is especially suitable for +text processing. It is essential for autotools build system because automake +and some other tools are written in Perl. + +Perl itself is written in C but ships with some pre-generated files that need +perl for processing. To bootstrap Perl we will start with the oldest Perl 5 +version which has the fewest number of pregenerated files. We reimplement two +remaining perl scripts in awk and use our custom makefile instead of Perl's +pre-generated Configure script. + +At this first step we build `miniperl` which is `perl` without support for +loading modules. diff --git a/SHA256SUMS.sources b/SHA256SUMS.sources index 763570e..f86ee27 100644 --- a/SHA256SUMS.sources +++ b/SHA256SUMS.sources @@ -13,4 +13,5 @@ a32032bab36208509466654df12f507600dfe0313feebbcd218c32a70bf72a16 grep-2.4.tar.g 64b30b41fde2ebf669e6af489883fb1df6a06ac30555a96cfa3c39ecce7267dd make-3.80.tar.gz 1370c9a812b2cf2a7d92802510cca0058cc37e66a7bedd70051f0a34015022a3 musl-1.1.24.tar.gz ecb5c6469d732bcf01d6ec1afe9e64f1668caba5bfdb103c28d7f537ba3cdb8a patch-2.5.9.tar.gz +1beb92a6fc29483d0a8ab71379fb0e930a2c90198d81ba2930c1e788b5f58873 perl5.000.tar.gz c6c37e888b136ccefab903c51149f4b7bd659d69d4aea21245f61053a57aa60a tar-1.12.tar.gz diff --git a/rootfs.sh b/rootfs.sh index bb43667..e7e4ce1 100755 --- a/rootfs.sh +++ b/rootfs.sh @@ -190,6 +190,9 @@ get_file https://ftp.gnu.org/gnu/diffutils/diffutils-2.7.tar.gz # gawk 3.0.4 get_file https://ftp.gnu.org/gnu/gawk/gawk-3.0.4.tar.gz +# perl 5.000 +get_file http://mirrors.develooper.com/perl/really-ancient-perls/oldperl/dist/leo/src/perl5/perl5.000.tar.gz + # General cleanup find tmp -name .git -exec rm -rf \; diff --git a/sysa/perl5.000/files/config.h b/sysa/perl5.000/files/config.h new file mode 100644 index 0000000..a5126e6 --- /dev/null +++ b/sysa/perl5.000/files/config.h @@ -0,0 +1,73 @@ +// SPDX-FileCopyrightText: 2021 Andrius Štikonas + +// SPDX-License-Identifier: GPL-3.0-or-later + +#define MEM_ALIGNBYTES 8 +#define BIN "/after/bin" +#define BYTEORDER 0x4321 +#define CPPSTDIN "tcc -E" +#define CPPMINUS "-" +#define HAS_ALARM +#define HAS_FORK +#define HAS_MKDIR +#define HAS_PAUSE +#define HAS_RMDIR +#define HAS_STRERROR +#define HAS_SYS_ERRLIST +#define Strerror(e) strerror(e) + +#define HAS_SYSCALL +#define HAS_TIMES + +#define HAS_VPRINTF +#define Gid_t gid_t + +#define I_DIRENT +#define Direntry_t struct dirent + +#define I_DLFCN +#define I_FCNTL +#define I_LIMITS +#define I_MATH +#define I_NETINET_IN +#define I_STDDEF +#define I_STDLIB +#define I_STRING +#define I_SYS_DIR +#define I_SYS_IOCTL +#define I_SYS_PARAM +#define I_SYS_SELECT +#define I_SYS_TIMES +#define I_TERMIOS +#define I_TIME +#define I_UNISTD +#define I_UTIME +#define I_STDARG + +#define INTSIZE 4 +#define Off_t off_t + +#define PRIVLIB "/after/lib/perl5" + +#define _(args) args + +#define RANDBITS 31 + +#define SCRIPTDIR "/after/bin" + +#define SIG_NAME "ZERO","HUP","INT","QUIT","ILL","TRAP","IOT","BUS","FPE","KILL","USR1","SEGV","USR2","PIPE","ALRM","TERM","STKFLT","CHLD","CONT","STOP","TSTP","TTIN","TTOU","URG","XCPU","XFSZ","VTALRM","PROF","WINCH", "IO", "POLL", "PWR", "SYS", "UNUSED" + +#define Size_t size_t + +#define STDCHAR char +#define Uid_t uid_t + +#define LOC_SED "/after/bin/sed" +#define ARCHLIB "/after/lib/perl5/" + +#define CAT2(a,b) a##b +#define Gconvert(x,n,t,b) gcvt((x),(n),(b)) + +#define Time_t time_t + +#define SSize_t ssize_t diff --git a/sysa/perl5.000/files/keywords.sh b/sysa/perl5.000/files/keywords.sh new file mode 100644 index 0000000..76950e5 --- /dev/null +++ b/sysa/perl5.000/files/keywords.sh @@ -0,0 +1,6 @@ +#!/bin/sh -e +# SPDX-FileCopyrightText: 2021 Andrius Štikonas +# +# SPDX-License-Identifier: GPL-3.0-or-later + +sed -e '1,/__END__/ d' keywords.pl | sed '1d' | awk '{print "#define", "KEY_"$0, NR-1}' > keywords.h diff --git a/sysa/perl5.000/files/opcode.awk b/sysa/perl5.000/files/opcode.awk new file mode 100644 index 0000000..e81d7e2 --- /dev/null +++ b/sysa/perl5.000/files/opcode.awk @@ -0,0 +1,31 @@ +# SPDX-FileCopyrightText: 2021 Andrius Štikonas +# +# SPDX-License-Identifier: GPL-3.0-or-later + +{ + argsum = 0 + + argsum = or(argsum, 1 * (index($4, "m") != 0)) + argsum = or(argsum, 2 * (index($4, "f") != 0)) + argsum = or(argsum, 4 * (index($4, "s") != 0)) + argsum = or(argsum, 8 * (index($4, "t") != 0)) + argsum = or(argsum, 16 * (index($4, "i") != 0)) + argsum = or(argsum, 32 * (index($4, "I") != 0)) + argsum = or(argsum, 64 * (index($4, "d") != 0)) + argsum = or(argsum, 128 * (index($4, "u") != 0)) + + mul = 256 + + arg_val="SLAHCFR" + + argstr=$5 + gsub(" ", "", argstr) + split(argstr, args, "") + for(i=1; i<=length(argstr); i+=1) { + argnum = (index(argstr, "?") != 0) * 8 + argnum += index(arg_val, args[i]) + argsum += argnum * mul + mul = lshift(mul, 4) + } + printf("\t0x%08x,\t/* %s */\n", argsum, $1) +} diff --git a/sysa/perl5.000/files/opcode.sh b/sysa/perl5.000/files/opcode.sh new file mode 100755 index 0000000..9f52c18 --- /dev/null +++ b/sysa/perl5.000/files/opcode.sh @@ -0,0 +1,71 @@ +#!/bin/sh -e +# SPDX-FileCopyrightText: 2021 Andrius Štikonas +# +# SPDX-License-Identifier: GPL-3.0-or-later + + +sed -e '1,/__END__/ d; s/[#].*$//g; /^$/d' opcode.pl | tr -s '\t' '\t' > data + +exec 1> opcode.h + +# Emit defines. +echo "typedef enum {"; +awk '{print "\tOP_"toupper($1)","}' data +echo " OP_max" +echo "} opcode;" +echo "#define MAXO " $(wc -l data | awk '{print $1}') + +# Emit opnames. +printf " +#ifndef DOINIT +EXT char *op_name[]; +#else +EXT char *op_name[] = { +" +awk -F'\t' '{print "\t\""$2"\","}' data +printf "}; +#endif + +" + +# Emit function declarations. +awk -F'\t' '{print "OP *\t"$3"\t_((OP* op));"}' data | sort | uniq +awk '{print "OP *\tpp_"$1"\t_((void));"}' data + +# Emit ppcode switch array. +printf " +#ifndef DOINIT +EXT OP * (*ppaddr[])(); +#else +EXT OP * (*ppaddr[])() = { +" +awk '{print "\tpp_"$1","}' data +printf "}; +#endif +" + +# Emit check routines. +printf " +#ifndef DOINIT +EXT OP * (*check[])(); +#else +EXT OP * (*check[])() = { +" +awk -F'\t' '{print "\t"$3",\t/* "$1" */"}' data +printf "}; +#endif +" + +# Emit allowed argument types. +printf " +#ifndef DOINIT +EXT U32 opargs[]; +#else +EXT U32 opargs[] = { +" +awk -F'\t' -f opcode.awk data +printf "}; +#endif +" + +rm data diff --git a/sysa/perl5.000/mk/main.mk b/sysa/perl5.000/mk/main.mk new file mode 100644 index 0000000..9cfa285 --- /dev/null +++ b/sysa/perl5.000/mk/main.mk @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2021 Andrius Štikonas + +# SPDX-License-Identifier: GPL-3.0-or-later + +CC = tcc + +.PHONY: all + +MINIPERL_SRC = av deb doio doop dump gv hv mg miniperlmain op perl perly pp pp_ctl pp_hot pp_sys regcomp regexec run scope sv taint toke util +MINIPERL_OBJ = $(addsuffix .o, $(MINIPERL_SRC)) + +all: miniperl + +miniperl: $(MINIPERL_OBJ) + $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ + +install: all + install miniperl $(PREFIX)/bin/perl diff --git a/sysa/perl5.000/perl5.000.sh b/sysa/perl5.000/perl5.000.sh new file mode 100755 index 0000000..56c0a90 --- /dev/null +++ b/sysa/perl5.000/perl5.000.sh @@ -0,0 +1,23 @@ +# SPDX-FileCopyrightText: 2021 Andrius Štikonas +# +# SPDX-License-Identifier: GPL-3.0-or-later + +src_prepare() { + default_src_prepare + + rm perly.c perly.h + bison -d perly.y + mv perly.tab.c perly.c + mv perly.tab.h perly.h + + rm embed.h + ./embed_h.SH + + rm keywords.h + chmod +x keywords.sh + ./keywords.sh + + rm opcode.h + chmod +x opcode.sh + ./opcode.sh +} diff --git a/sysa/run.sh b/sysa/run.sh index facb32c..7c73ca1 100755 --- a/sysa/run.sh +++ b/sysa/run.sh @@ -41,4 +41,7 @@ build coreutils-5.0 # Part 28 build gawk-3.0.4 +# Part 29 +build perl5.000 + echo "Bootstrapping completed."