Skip to content

Instantly share code, notes, and snippets.

@samrat
Last active August 18, 2016 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samrat/f08e48eda4c2695c4c0668f5a0b5ba6c to your computer and use it in GitHub Desktop.
Save samrat/f08e48eda4c2695c4c0668f5a0b5ba6c to your computer and use it in GitHub Desktop.
Building lcc on x64 Linux
diff --git a/etc/linux.c b/etc/linux.c
index 5df6059..f039d69 100755
--- a/etc/linux.c
+++ b/etc/linux.c
@@ -17,18 +17,18 @@ char *cpp[] = { LCCDIR "gcc/cpp",
"$1", "$2", "$3", 0 };
char *include[] = {"-I" LCCDIR "include", "-I" LCCDIR "gcc/include", "-I/usr/include", 0 };
char *com[] = {LCCDIR "rcc", "-target=x86/linux", "$1", "$2", "$3", 0 };
-char *as[] = { "/usr/bin/as", "-o", "$3", "$1", "$2", 0 };
+char *as[] = { "/usr/bin/as", "--32", "-o", "$3", "$1", "$2", 0 };
char *ld[] = {
/* 0 */ "/usr/bin/ld", "-m", "elf_i386", "-dynamic-linker",
/* 4 */ "/lib/ld-linux.so.2", "-o", "$3",
- /* 7 */ "/usr/lib/crt1.o", "/usr/lib/crti.o",
- /* 9 */ LCCDIR "/gcc/crtbegin.o",
+ /* 7 */ "/usr/lib32/crt1.o", "/usr/lib32/crti.o",
+ /* 9 */ LCCDIR "/gcc/crtbegin.o",
"$1", "$2",
/* 12 */ "-L" LCCDIR,
/* 13 */ "-llcc",
/* 14 */ "-L" LCCDIR "/gcc", "-lgcc", "-lc", "-lm",
/* 18 */ "",
- /* 19 */ LCCDIR "/gcc/crtend.o", "/usr/lib/crtn.o",
+ /* 19 */ LCCDIR "/gcc/crtend.o", "/usr/lib32/crtn.o",
0 };
extern char *concat(char *, char *);
# gcc-multilib needs to be installed
rm build -r
mkdir build
BUILDDIR=build make -j2 CFLAGS="-m32 -g -DLCCDIR='\"build/\"'" HOSTFILE=./etc/linux.c lcc
BUILDDIR=build make -j2 CFLAGS="-m32 -g -DLCCDIR='\"build/\"'" all
mkdir build/include
mkdir build/gcc
ln -s /usr/lib/gcc/*-linux-gnu/*/include/* build/include/
ln -s /usr/lib/gcc/*-linux-gnu/*/32/crt* build/gcc/
cp /usr/lib/gcc/x86_64-pc-linux-gnu/*/32/libgcc.a build/
cp build/cpp build/gcc/
diff --git a/makefile b/makefile
index c96afff..d5ccb77 100755
--- a/makefile
+++ b/makefile
@@ -5,7 +5,7 @@ E=
CC=cc
CFLAGS=-g
LDFLAGS=-g
-LD=$(CC)
+LD=$(CC) -m32
AR=ar ruv
RANLIB=ranlib
DIFF=diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment