musl-cross-make icon indicating copy to clipboard operation
musl-cross-make copied to clipboard

Target directory in output folder

Open ghost opened this issue 4 years ago • 11 comments

Is it possible to rather than the header files, libraries, and linker to be placed rather than into the target directory in sysroot to the root output directory.

So from this...

output
    |
    + - bin
    + - lib
    + - ...
    + - x86_64-linux-musl
        + - bin
        + - lib
        + - ...

To this...

output
    |
    + - bin
    + - lib
    + - ...

I've tried setting GCC's --with-build-sysroot=/ however the sysroot dir is still present. Is there a way to forego this?

Thank you in advance.

ghost avatar Nov 10 '20 20:11 ghost

You would use --with-sysroot not --with-build-sysroot for this, but I don't have any idea if it will work - mcm is not setup to be installed like that, and it's rather going against logical organization, since the top-level output dir is binaries/libraries/etc. for the host (the system you run the cross toolchain on) and the $target-named directory under that is binaries/libraries/etc. for the target (the system you're cross-compiling for).

richfelker avatar Nov 10 '20 21:11 richfelker

I attempted to compile with --with-sysroot however to no avail; the target directory was still present in the output directory. Is there any other option which can possibly build the toolchain in the way that I've described?

Also, why is there no compiler in the target directory, e.g. output/x86_64-linux-musl/bin/cc? Is there an option to place the compiler binary into the target bin directory?

ghost avatar Nov 11 '20 14:11 ghost

I attempted to compile with --with-sysroot however to no avail; the target directory was still present in the output directory. Is there any other option which can possibly build the toolchain in the way that I've described?

You'd need to hack this into the makefile since, as written, it sets the sysroot itself. But I want to reiterate that this is not a good idea. It's gratuitously breaking the intended split between host and target files and unless I'm missing something you don't have any technical reason to do this, just an aesthetic one that seems to be based on misunderstanding the purpose of the existing layout.

Also, why is there no compiler in the target directory, e.g. output/x86_64-linux-musl/bin/cc?

Because building a cross compiler and cross-compiling a native compiler for the target are two completely different tasks, and doing them both when you don't need the latter would double the time and space required to build.

richfelker avatar Nov 11 '20 15:11 richfelker

Because building a cross compiler and cross-compiling a native compiler for the target are two completely different tasks, and doing them both when you don't need the latter would double the time and space required to build.

That's fair. Is there not a NATIVE option I can set in config.mak? I don't mind doing a second pass to build a native compiler.

ghost avatar Nov 11 '20 15:11 ghost

Yes, mcm can also cross-compile native compilers for your target, and in this case they don't have the cross directory structure you're unhappy with. You need to already have the cross compiler in your PATH, then run mcm with NATIVE=y, and it should just work.

richfelker avatar Nov 11 '20 15:11 richfelker

I set the compuler to my path and set NATIVE=1 in COMMON_CONFIG however my output directory still has the x86_64-linux-musl directory. Is this the intended result for building a native compiler? When looking into the bin dir in the x86_64... dir I can't seem to find the compiler.

Here's the config.mak I'm using:

TARGET = x86_64-linux-musl

OUTPUT = /home/ben/musl-root

COMMON_CONFIG += CC="/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-gcc -static --static"
COMMON_CONFIG += CPP="/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-g++ -E -static --static"
COMMON_CONFIG += CXX="/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-gcc -static --static"
COMMON_CONFIG += LD=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-ld
COMMON_CONFIG += AR=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-ar
COMMON_CONFIG += NM=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-nm
COMMON_CONFIG += OBJCOPY=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-objcopy
COMMON_CONFIG += OBJDUMP=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-objdump
COMMON_CONFIG += RANLIB=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-ranlib
COMMON_CONFIG += READELF=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-readelf
COMMON_CONFIG += SIZE=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-size
COMMON_CONFIG += STRINGS=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-strings
COMMON_CONFIG += STRIP=/home/ben/musl-cross-make/output/bin/x86_64-linux-musl-strip
COMMON_CONFIG += NATIVE=1
COMMON_CONFIG += --disable-wrapper --disable-multilib --disable-libssp --disable-libquadmath --disable-libgomp --disable-l
ibvtv --disable-plugin --disable-shared --with-sysroot=/ --with-build-sysroot=/
COMMON_CONFIG += CFLAGS="-g0 -Os" CXXFLAGS="-g0 -Os" LDFLAGS="-s"

ghost avatar Nov 11 '20 16:11 ghost

NATIVE=y is not part of COMMON_CONFIG. The latter is a variable containing gcc/binutils configure options. It's its own make variable. Just add a line NATIVE=y in config.mak or put it on the make command line.

richfelker avatar Nov 11 '20 17:11 richfelker

Upon adding NATIVE=y to config.mak I receive the following error:

make[1]: Entering directory '/home/ben/musl-cross-make/build/x86_64-linux-musl/x86_64-linux-musl'
mkdir -p obj_musl
ln -sf ../../../musl-1.2.1 src_musl
cd obj_musl && ../src_musl/configure  --prefix= --host=x86_64-linux-musl
checking for C compiler...
../src_musl/configure: cannot find a C compiler
make[1]: *** [Makefile:226: obj_musl/.lc_configured] Error 1
make[1]: Leaving directory '/home/ben/musl-cross-make/build/x86_64-linux-musl/x86_64-linux-musl'
make: *** [Makefile:182: all] Error 2

I've checked to make sure that the compiler exists in the output directory, pointed to in the config.mak I've pasted in my previous message.

EDIT: after setting path properly I was able to compile

ghost avatar Nov 11 '20 17:11 ghost

After some playing around with the environment I was able to compile a native Musl GCC compiler. Thanks, @richfelker!

ghost avatar Nov 12 '20 14:11 ghost

It would be really helpful to have a section in the readme on how to build a native compiler. Also it would be nice if it was scripted so it could be built in a single run of make.

clark800 avatar Sep 12 '21 15:09 clark800

would anyone be willing to share an implementation like our now-departed friend who started this thread>

SomethingGeneric avatar Sep 05 '22 02:09 SomethingGeneric