@@ -28,17 +28,31 @@ cd build
2828ungz --file ${DISTFILES} /${TCC_TAR} .tar.gz --output ${TCC_TAR} .tar
2929ungz --file ${DISTFILES} /${MES_PKG} .tar.gz --output ${MES_PKG} .tar
3030untar --non-strict --file ${TCC_TAR} .tar
31+
3132simple-patch ${TCC_PKG} /tcctools.c \
3233 ../simple-patches/remove-fileopen.before ../simple-patches/remove-fileopen.after
3334simple-patch ${TCC_PKG} /tcctools.c \
3435 ../simple-patches/addback-fileopen.before ../simple-patches/addback-fileopen.after
3536
37+ # Patches to get tcc to compile with pnut, these are reverted after tcc-pnut is built
38+ simple-patch ${TCC_PKG} /tccpp.c \
39+ ../simple-patches/array_sizeof.before ../simple-patches/array_sizeof.after
40+ simple-patch ${TCC_PKG} /tccgen.c \
41+ ../simple-patches/fix_stack_64_bit_operands_on_32_bit.before ../simple-patches/fix_stack_64_bit_operands_on_32_bit.after
42+ simple-patch ${TCC_PKG} /tccgen.c \
43+ ../simple-patches/float_negation.before ../simple-patches/float_negation.after
44+ simple-patch ${TCC_PKG} /libtcc.c \
45+ ../simple-patches/sscanf_TCC_VERSION.before ../simple-patches/sscanf_TCC_VERSION.after
46+ simple-patch ${TCC_PKG} /tcc.h \
47+ ../simple-patches/undefine_TCC_IS_NATIVE.before ../simple-patches/undefine_TCC_IS_NATIVE.after
48+
3649untar --non-strict --file ${MES_PKG} .tar
3750
51+ # Prepare Mes header files
52+
3853# Create config.h
3954catm ${MES_PKG} /include/mes/config.h
4055catm ${TCC_PKG} /config.h
41- cd ${TCC_PKG}
4256
4357if match ${ARCH} x86; then
4458 MES_ARCH=x86
@@ -56,85 +70,105 @@ if match ${ARCH} riscv64; then
5670 HAVE_LONG_LONG=1
5771fi
5872
73+ mkdir ${MES_PKG} /include/arch
74+ cp ${MES_PKG} /include/linux/${MES_ARCH} /kernel-stat.h ${MES_PKG} /include/arch/kernel-stat.h
75+ cp ${MES_PKG} /include/linux/${MES_ARCH} /signal.h ${MES_PKG} /include/arch/signal.h
76+ cp ${MES_PKG} /include/linux/${MES_ARCH} /syscall.h ${MES_PKG} /include/arch/syscall.h
5977
60- ${MES} --no-auto-compile -e main ${BINDIR} /mescc.scm -- \
61- -S \
62- -o tcc.s \
63- -I ${INCDIR} \
64- -D BOOTSTRAP=1 \
65- -D HAVE_LONG_LONG=${HAVE_LONG_LONG} \
66- -I . \
67- -D TCC_TARGET_${TCC_TARGET_ARCH} =1 \
68- -D inline= \
69- -D CONFIG_TCCDIR=\" ${LIBDIR} /tcc\" \
70- -D CONFIG_SYSROOT=\" /\" \
71- -D CONFIG_TCC_CRTPREFIX=\" ${LIBDIR} \" \
72- -D CONFIG_TCC_ELFINTERP=\" /mes/loader\" \
73- -D CONFIG_TCC_SYSINCLUDEPATHS=\" ${PREFIX} /include/mes\" \
74- -D TCC_LIBGCC=\" ${LIBDIR} /libc.a\" \
75- -D CONFIG_TCC_LIBTCC1_MES=0 \
76- -D CONFIG_TCCBOOT=1 \
77- -D CONFIG_TCC_STATIC=1 \
78- -D CONFIG_USE_LIBGCC=1 \
79- -D TCC_VERSION=\" 0.9.26\" \
80- -D ONE_SOURCE=1 \
81- tcc.c
82- ${MES} --no-auto-compile -e main ${BINDIR} /mescc.scm -- \
83- --base-address 0x08048000 \
84- -o tcc-mes \
85- -L ${LIBDIR} \
86- tcc.s \
87- -l c+tcc
88- cp tcc-mes ${BINDIR} /
89- chmod 755 ${BINDIR} /tcc-mes
78+ # Unpack pnut's portable libc, only used to bootstrap tcc-pnut
79+
80+ untar --file ${DISTFILES} /${PNUT_PKG} .tar
81+
82+ # Here we go!
9083
91- # test tcc-mes
92- tcc-mes -version
84+ cd ${TCC_PKG}
85+
86+ pnut \
87+ -I ../pnut-laurent-small-fixes-for-TCC/portable_libc/include/ \
88+ -D BOOTSTRAP=1 \
89+ -D HAVE_LONG_LONG=0 \
90+ -D TCC_TARGET_${TCC_TARGET_ARCH} =1 \
91+ -D CONFIG_SYSROOT=\" /\" \
92+ -D CONFIG_TCC_CRTPREFIX=\" ${LIBDIR} \" \
93+ -D CONFIG_TCC_ELFINTERP=\" /mes/loader\" \
94+ -D CONFIG_TCC_SYSINCLUDEPATHS=\" ${PREFIX} /include/mes\" \
95+ -D TCC_LIBGCC=\" ${LIBDIR} /libc.a\" \
96+ -D CONFIG_TCC_LIBTCC1_MES=0 \
97+ -D CONFIG_TCCBOOT=1 \
98+ -D CONFIG_TCC_STATIC=1 \
99+ -D CONFIG_USE_LIBGCC=1 \
100+ -D TCC_VERSION=\" 0.9.26\" \
101+ -D ONE_SOURCE=1 \
102+ -D CONFIG_TCCDIR=\" ${LIBDIR} /tcc\" \
103+ -D __intptr_t_defined=1 \
104+ tcc.c \
105+ ../pnut-laurent-small-fixes-for-TCC/portable_libc/libc.c \
106+ -o tcc-pnut
107+
108+ cp tcc-pnut ${BINDIR} /
109+ chmod 755 ${BINDIR} /tcc-pnut
110+
111+ # test tcc-pnut
112+ tcc-pnut -version
113+
114+ cd ..
115+
116+ # Revert patches
117+ simple-patch ${TCC_PKG} /tccpp.c \
118+ ../simple-patches/array_sizeof.after ../simple-patches/array_sizeof.before
119+ simple-patch ${TCC_PKG} /tccgen.c \
120+ ../simple-patches/fix_stack_64_bit_operands_on_32_bit.after ../simple-patches/fix_stack_64_bit_operands_on_32_bit.before
121+ simple-patch ${TCC_PKG} /tccgen.c \
122+ ../simple-patches/float_negation.after ../simple-patches/float_negation.before
123+ simple-patch ${TCC_PKG} /libtcc.c \
124+ ../simple-patches/sscanf_TCC_VERSION.after ../simple-patches/sscanf_TCC_VERSION.before
125+ simple-patch ${TCC_PKG} /tcc.h \
126+ ../simple-patches/undefine_TCC_IS_NATIVE.after ../simple-patches/undefine_TCC_IS_NATIVE.before
93127
94128# Recompile the mes C library
95- cd ../ ${MES_PKG}
129+ cd ${MES_PKG}
96130
97131# Create unified libc file
98132cd lib
99133catm ../unified-libc.c ctype/isalnum.c ctype/isalpha.c ctype/isascii.c ctype/iscntrl.c ctype/isdigit.c ctype/isgraph.c ctype/islower.c ctype/isnumber.c ctype/isprint.c ctype/ispunct.c ctype/isspace.c ctype/isupper.c ctype/isxdigit.c ctype/tolower.c ctype/toupper.c dirent/closedir.c dirent/__getdirentries.c dirent/opendir.c linux/readdir.c linux/access.c linux/brk.c linux/chdir.c linux/chmod.c linux/clock_gettime.c linux/close.c linux/dup2.c linux/dup.c linux/execve.c linux/fcntl.c linux/fork.c linux/fsync.c linux/fstat.c linux/_getcwd.c linux/getdents.c linux/getegid.c linux/geteuid.c linux/getgid.c linux/getpid.c linux/getppid.c linux/getrusage.c linux/gettimeofday.c linux/getuid.c linux/ioctl.c linux/ioctl3.c linux/kill.c linux/link.c linux/lseek.c linux/lstat.c linux/malloc.c linux/mkdir.c linux/mknod.c linux/nanosleep.c linux/_open3.c linux/pipe.c linux/_read.c linux/readlink.c linux/rename.c linux/rmdir.c linux/setgid.c linux/settimer.c linux/setuid.c linux/signal.c linux/sigprogmask.c linux/symlink.c linux/stat.c linux/time.c linux/unlink.c linux/waitpid.c linux/wait4.c linux/${MES_ARCH}-mes-gcc/_exit.c linux/${MES_ARCH}-mes-gcc/syscall.c linux/${MES_ARCH}-mes-gcc/_write.c math/ceil.c math/fabs.c math/floor.c mes/abtod.c mes/abtol.c mes/__assert_fail.c mes/assert_msg.c mes/__buffered_read.c mes/__init_io.c mes/cast.c mes/dtoab.c mes/eputc.c mes/eputs.c mes/fdgetc.c mes/fdgets.c mes/fdputc.c mes/fdputs.c mes/fdungetc.c mes/globals.c mes/itoa.c mes/ltoab.c mes/ltoa.c mes/__mes_debug.c mes/mes_open.c mes/ntoab.c mes/oputc.c mes/oputs.c mes/search-path.c mes/ultoa.c mes/utoa.c posix/alarm.c posix/buffered-read.c posix/execl.c posix/execlp.c posix/execv.c posix/execvp.c posix/getcwd.c posix/getenv.c posix/isatty.c posix/mktemp.c posix/open.c posix/pathconf.c posix/raise.c posix/sbrk.c posix/setenv.c posix/sleep.c posix/unsetenv.c posix/wait.c posix/write.c stdio/clearerr.c stdio/fclose.c stdio/fdopen.c stdio/feof.c stdio/ferror.c stdio/fflush.c stdio/fgetc.c stdio/fgets.c stdio/fileno.c stdio/fopen.c stdio/fprintf.c stdio/fputc.c stdio/fputs.c stdio/fread.c stdio/freopen.c stdio/fscanf.c stdio/fseek.c stdio/ftell.c stdio/fwrite.c stdio/getc.c stdio/getchar.c stdio/perror.c stdio/printf.c stdio/putc.c stdio/putchar.c stdio/remove.c stdio/snprintf.c stdio/sprintf.c stdio/sscanf.c stdio/ungetc.c stdio/vfprintf.c stdio/vfscanf.c stdio/vprintf.c stdio/vsnprintf.c stdio/vsprintf.c stdio/vsscanf.c stdlib/abort.c stdlib/abs.c stdlib/alloca.c stdlib/atexit.c stdlib/atof.c stdlib/atoi.c stdlib/atol.c stdlib/calloc.c stdlib/__exit.c stdlib/exit.c stdlib/free.c stdlib/mbstowcs.c stdlib/puts.c stdlib/qsort.c stdlib/realloc.c stdlib/strtod.c stdlib/strtof.c stdlib/strtol.c stdlib/strtold.c stdlib/strtoll.c stdlib/strtoul.c stdlib/strtoull.c string/bcmp.c string/bcopy.c string/bzero.c string/index.c string/memchr.c string/memcmp.c string/memcpy.c string/memmem.c string/memmove.c string/memset.c string/rindex.c string/strcat.c string/strchr.c string/strcmp.c string/strcpy.c string/strcspn.c string/strdup.c string/strerror.c string/strlen.c string/strlwr.c string/strncat.c string/strncmp.c string/strncpy.c string/strpbrk.c string/strrchr.c string/strspn.c string/strstr.c string/strupr.c stub/atan2.c stub/bsearch.c stub/chown.c stub/__cleanup.c stub/cos.c stub/ctime.c stub/exp.c stub/fpurge.c stub/freadahead.c stub/frexp.c stub/getgrgid.c stub/getgrnam.c stub/getlogin.c stub/getpgid.c stub/getpgrp.c stub/getpwnam.c stub/getpwuid.c stub/gmtime.c stub/ldexp.c stub/localtime.c stub/log.c stub/mktime.c stub/modf.c stub/mprotect.c stub/pclose.c stub/popen.c stub/pow.c stub/putenv.c stub/rand.c stub/realpath.c stub/rewind.c stub/setbuf.c stub/setgrent.c stub/setlocale.c stub/setvbuf.c stub/sigaction.c stub/sigaddset.c stub/sigblock.c stub/sigdelset.c stub/sigemptyset.c stub/sigsetmask.c stub/sin.c stub/sys_siglist.c stub/system.c stub/sqrt.c stub/strftime.c stub/times.c stub/ttyname.c stub/umask.c stub/utime.c ${MES_ARCH}-mes-gcc/setjmp.c
100134cd ..
101135
102136# crt1.o
103- tcc-mes -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} -o ${LIBDIR} /crt1.o lib/linux/${MES_ARCH} -mes-gcc/crt1.c
137+ tcc-pnut -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} -o ${LIBDIR} /crt1.o lib/linux/${MES_ARCH} -mes-gcc/crt1.c
104138
105139catm ${LIBDIR} /crtn.o
106140catm ${LIBDIR} /crti.o
107141if match ${ARCH} x86; then
108142 # crtn.o
109- tcc-mes -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} -o ${LIBDIR} /crtn.o lib/linux/${MES_ARCH} -mes-gcc/crtn.c
143+ tcc-pnut -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} -o ${LIBDIR} /crtn.o lib/linux/${MES_ARCH} -mes-gcc/crtn.c
110144
111145 # crti.o
112- tcc-mes -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} -o ${LIBDIR} /crti.o lib/linux/${MES_ARCH} -mes-gcc/crti.c
146+ tcc-pnut -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} -o ${LIBDIR} /crti.o lib/linux/${MES_ARCH} -mes-gcc/crti.c
113147fi
114148
115149# libc+gcc.a
116- tcc-mes -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} -o unified-libc.o unified-libc.c
117- tcc-mes -ar cr ${LIBDIR} /libc.a unified-libc.o
150+ tcc-pnut -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} -I include/arch -o unified-libc.o unified-libc.c
151+ tcc-pnut -ar cr ${LIBDIR} /libc.a unified-libc.o
118152
119153# libtcc1.a
120154mkdir ${LIBDIR} /tcc
121- tcc-mes -c -D HAVE_CONFIG_H=1 -D HAVE_LONG_LONG=1 -D HAVE_FLOAT=1 -I include -I include/linux/${MES_ARCH} -o libtcc1.o lib/libtcc1.c
155+ tcc-pnut -c -D HAVE_CONFIG_H=1 -D HAVE_LONG_LONG=1 -D HAVE_FLOAT=1 -I include -I include/linux/${MES_ARCH} -o libtcc1.o lib/libtcc1.c
122156if match ${ARCH} riscv64; then
123- tcc-mes -c -D HAVE_CONFIG_H=1 -D HAVE_LONG_LONG=1 -D HAVE_FLOAT=1 -I include -I include/linux/${MES_ARCH} -o lib-arm64.o ../${TCC_PKG} /lib/lib-arm64.c
124- tcc-mes -ar cr ${LIBDIR} /tcc/libtcc1.a libtcc1.o lib-arm64.o
157+ tcc-pnut -c -D HAVE_CONFIG_H=1 -D HAVE_LONG_LONG=1 -D HAVE_FLOAT=1 -I include -I include/linux/${MES_ARCH} -o lib-arm64.o ../${TCC_PKG} /lib/lib-arm64.c
158+ tcc-pnut -ar cr ${LIBDIR} /tcc/libtcc1.a libtcc1.o lib-arm64.o
125159else
126- tcc-mes -ar cr ${LIBDIR} /tcc/libtcc1.a libtcc1.o
160+ tcc-pnut -ar cr ${LIBDIR} /tcc/libtcc1.a libtcc1.o
127161fi
128162
129163# libgetopt.a
130- tcc-mes -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} lib/posix/getopt.c
131- tcc-mes -ar cr ${LIBDIR} /libgetopt.a getopt.o
164+ tcc-pnut -c -D HAVE_CONFIG_H=1 -I include -I include/linux/${MES_ARCH} lib/posix/getopt.c
165+ tcc-pnut -ar cr ${LIBDIR} /libgetopt.a getopt.o
132166
133167cd ../${TCC_PKG}
134168
135169# boot0 (ref comments here for all boot*)
136170# compile
137- tcc-mes \
171+ tcc-pnut \
138172 -g \
139173 -v \
140174 -static \
@@ -307,10 +341,12 @@ tcc -ar cr ${LIBDIR}/libgetopt.a getopt.o
307341
308342cd ../..
309343
344+ sha256sum /usr/bin/tcc-pnut
345+
310346# Checksums
311347if match x${UPDATE_CHECKSUMS} xTrue; then
312348 sha256sum -o ${pkg} .${ARCH} .checksums \
313- /usr/bin/tcc-mes \
349+ /usr/bin/tcc-pnut \
314350 /usr/bin/tcc-boot0 \
315351 /usr/bin/tcc-boot1 \
316352 /usr/bin/tcc \
0 commit comments