sabotage-linux / netbsd-curses

libcurses and dependencies taken from netbsd and brought into a portable shape (at least to musl or glibc)
Other
147 stars 14 forks source link

Cannot seem to build static w/ specified lib && include paths #29

Closed caryatid closed 7 years ago

caryatid commented 7 years ago

Attempting a static build. I have a static binutils, musl-libc, and gcc targeted to that libc.

My config.mak (aside, would be nice if build recognized config.mk as well ) looks like:

PREFIX = /home/[me]/repos/toolbox/ins
TARGET = x86_64-linux-musl
CFLAGS=-O2 -I. -I${PREFIX}/${TARGET}/include -I./libcurses -I${PREFIX}/include -nostdinc
LDFLAGS=-static -L${PREFIX}/lib -L${PREFIX}/${TARGET}/lib -nodefaultlibs
CC=${TARGET}-gcc

I then run "make all-static" but it doesn't seem to pull in the LDFLAGS and the build does not build nbperf statically:

file src/netbsd-curses/nbperf/nbperf
src/netbsd-curses/nbperf/nbperf: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

It is just after the nbperf build that I get the error which is ( with nbperf's called build command for context )

x86_64-linux-musl-gcc  nbperf/nbperf.o nbperf/nbperf-bdz.o nbperf/nbperf-chm.o nbperf/nbperf-chm3.o nbperf/graph2.o nbperf/graph3.o nbperf/mi_vector_hash.o -o nbperf/nbperf
Generating terminfo hash
TERMINFODIR=./terminfo TOOL_AWK=awk TOOL_NBPERF=nbperf/nbperf TOOL_SED=sed TOOL_SORT=sort TOOL_TIC=tic/host_tic /bin/sh libterminfo/genhash libterminfo/term.h nbperf/nbperf > libterminfo/hash.c
libterminfo/genhash: nbperf/nbperf: /lib/ld-musl-x86_64.so.1: bad ELF interpreter: No such file or directory
make: *** [libterminfo/hash.c] Error 126

Any ideas what could be going on? Also apologies if this is in the wrong place; didn't see anywhere else in the readme to submit a build issue.

Thank you!

rofl0r commented 7 years ago

oh i see what's going on here. nbperf is a tool that's supposed to run on the host, so it is subject to be compiled with the host C compiler:

$(TOOL_NBPERF): $(NBPERF_OBJS)
        $(HOSTCC) $(LDFLAGS_HOST) $^ -o $@

what you're doing here is effectively cross-compiling, because your native toolchain is different from the target toolchain, and so the intention is that you set HOSTCC=gcc, and if you want the temporary throw-away nbperf statically linked for whatever reason, you can use LDFLAGS_HOST. HOSTCC is the standard variable name for the hostcompiler in makefile-only build systems, such as e.g. the one from linux kernel, busybox, etc. HTH

rofl0r commented 7 years ago

just for clarification: you can leave everything else as you have it right now, just add the HOSTCC. the build system detects crosscompilation when CC != HOSTCC and will do the right thing. if you encounter any more issues, you're welcome to ask!

caryatid commented 7 years ago

Awesome && built. Thank you so much!

rofl0r commented 7 years ago

great! thanks for your report!