# HG changeset patch # User Rob Landley # Date 1404349536 18000 # Node ID 35b8949e9d9cbfbdd6f54e5afb5439d86970f666 # Parent 8c8256e18ad23fb35a0d12f38c23fe09c165c0ba Very basic musl support. Still needs debugging and to be enabled per-target. diff -r 8c8256e18ad2 -r 35b8949e9d9c native-compiler.sh --- a/native-compiler.sh Wed Jul 02 20:04:18 2014 -0500 +++ b/native-compiler.sh Wed Jul 02 20:05:36 2014 -0500 @@ -7,7 +7,7 @@ # build a more portable and capable cross compiler for an arbitrary host. # The new compiler is built --with-shared, with thread support, has uClibc++ -# installed, and is linked against uClibc (see BUILD_STATIC in config). +# installed, and is linked against musl (see BUILD_STATIC in config). source sources/include.sh && load_target "$1" || exit 1 check_for_base_arch || exit 0 @@ -21,7 +21,7 @@ # Build C Library build_section linux-headers -build_section uClibc +[ -z "$UCLIBC_CONFIG" ] && build_section musl || build_section uClibc # Build binutils, gcc, and ccwrap diff -r 8c8256e18ad2 -r 35b8949e9d9c simple-cross-compiler.sh --- a/simple-cross-compiler.sh Wed Jul 02 20:04:18 2014 -0500 +++ b/simple-cross-compiler.sh Wed Jul 02 20:05:36 2014 -0500 @@ -33,7 +33,8 @@ # Build C Library build_section linux-headers -build_section uClibc + +[ -z "$UCLIBC_CONFIG" ] && build_section musl || build_section uClibc cat > "${STAGE_DIR}"/README << EOF && Cross compiler for $ARCH from http://aboriginal.impactlinux.com diff -r 8c8256e18ad2 -r 35b8949e9d9c sources/sections/ccwrap.sh --- a/sources/sections/ccwrap.sh Wed Jul 02 20:04:18 2014 -0500 +++ b/sources/sections/ccwrap.sh Wed Jul 02 20:05:36 2014 -0500 @@ -7,7 +7,9 @@ # Build wrapper binary +mkdir -p "$STAGE_DIR/bin" && "$TEMP" "$SOURCES/toys/ccwrap.c" -Os $CFLAGS \ -o "$STAGE_DIR/bin/${TOOLCHAIN_PREFIX}cc" $STATIC_FLAGS && -echo -e '#!/bin/bash\n\ncc -E "$@"' > "$STAGE_DIR/bin/cpp" && -chmod +x "$STAGE_DIR/bin/cpp" || dienow +echo -e "#!/bin/bash\n\n${TOOLCHAIN_PREFIX}cc -E "'"$@"' \ + > "$STAGE_DIR/bin/${TOOLCHAIN_PREFIX}cpp" && +chmod +x "$STAGE_DIR/bin/${TOOLCHAIN_PREFIX}cpp" || dienow diff -r 8c8256e18ad2 -r 35b8949e9d9c sources/sections/musl.build --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sources/sections/musl.build Wed Jul 02 20:05:36 2014 -0500 @@ -0,0 +1,4 @@ +# Build and install musl + +CC= CROSS_COMPILE=${ARCH}- ./configure --prefix=/ && +DESTDIR="$STAGE_DIR" make -j $CPUS CROSS_COMPILE=${ARCH}- all install diff -r 8c8256e18ad2 -r 35b8949e9d9c sources/toys/ccwrap.c --- a/sources/toys/ccwrap.c Wed Jul 02 20:04:18 2014 -0500 +++ b/sources/toys/ccwrap.c Wed Jul 02 20:05:36 2014 -0500 @@ -31,6 +31,8 @@ fprintf(stderr, "bad malloc\n"); exit(1); } + + return ret; } // Die unless we can allocate enough space to sprintf() into. @@ -72,17 +74,18 @@ // Find a file in a colon-separated path char *find_in_path(char *path, char *filename, int has_exe) { - char *cwd = getcwd(0, 0); + char *cwd; if (index(filename, '/') && is_file(filename, has_exe)) return realpath(filename, 0); + if (!path || !(cwd = getcwd(0, 0))) return 0; while (path) { - char *str, *next = path ? index(path, ':') : 0; + char *str, *next = index(path, ':'); int len = next ? next-path : strlen(path); if (!len) str = xmprintf("%s/%s", cwd, filename); - else str = xmprintf("%*s/%s", len, path, filename); + else str = xmprintf("%.*s/%s", len, path, filename); // If it's not a directory, return it. if (is_file(str, has_exe)) { @@ -174,8 +177,29 @@ fprintf(stderr, "\n\n"); } + // figure out cross compiler prefix + i = strlen(ccprefix = basename(*argv)); + if (i<2) { + fprintf(stderr, "Bad name '%s'\n", ccprefix); + exit(1); + } + if (!strcmp("++", ccprefix+i-2)) { + cc = "raw++"; + SET_FLAG(CP); + SET_FLAG(CPstdinc); + if (i<3) exit(1); + i -= 3; + } else if (!strcmp("gcc", ccprefix+i-3)) i -= 3; // TODO: yank + else if (!strcmp("cc", ccprefix+i-2)) i-=2; + else if (!strcmp("cpp", ccprefix+i-3)) { + i -= 3; + CLEAR_FLAG(Clink); + } else return 1; // TODO: wrap ld + if (!(ccprefix = strndup(ccprefix, i))) exit(1); + // Find the cannonical path to the directory containing our executable topdir = find_in_path(getenv("PATH"), *argv, 1); + if (!topdir || !(temp = rindex(topdir, '/')) || strlen(*argv)<2) { fprintf(stderr, "Can't find %s in $PATH (did you export it?)\n", *argv); exit(1); @@ -206,30 +230,10 @@ free(topdir); topdir = temp; } - + // Name of the C compiler we're wrapping. cc = getenv("CCWRAP_CC"); if (!cc) cc = "rawcc"; - - // figure out cross compiler prefix - i = strlen(ccprefix = basename(*argv)); - if (i<2) { - fprintf(stderr, "Bad name '%s'\n", ccprefix); - exit(1); - } - if (!strcmp("++", ccprefix+i-2)) { - cc = "raw++"; - SET_FLAG(CP); - SET_FLAG(CPstdinc); - if (i<3) exit(1); - i -= 3; - } else if (!strcmp("gcc", ccprefix+i-3)) i -= 3; // TODO: yank - else if (!strcmp("cc", ccprefix+i-2)) i-=2; - else if (!strcmp("cpp", ccprefix+i-3)) { - i -= 3; - CLEAR_FLAG(Clink); - } else return 1; // TODO: wrap ld - if (!(ccprefix = strndup(ccprefix, i))) exit(1); // Does toolchain have a shared libcc? temp = xmprintf("%s/lib/libgcc_s.so", topdir);