sheepy

build system (sheepy) and package manager (spm) for C
git clone https://spartatek.se/git/sheepy.git
Log | Files | Refs | README | LICENSE

commit 37f232fc5ddb6b0af927e78ea6491f4231912647
parent 98609378b5d5a15ac39b666b79b060a1dd29f197
Author: Remy Noulin <loader2x@gmail.com>
Date:   Sat, 24 Oct 2020 21:35:27 +0200

list a files for library packages separate from object files to avoid undefined symbols, the a file list is placed last on the gcc command line

when an a file is before an object using it, the symbols are undefined.

src/sheepy.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)

Diffstat:
Msrc/sheepy.c | 37+++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/sheepy.c b/src/sheepy.c @@ -1903,6 +1903,7 @@ int MAIN(int ARGC, char** ARGV) { // collect lflags from packages char *packageLflags = NULL; createAllocateSmallArray(incList); + cleanAllocateSmallArray(aLibPackages); forEachSmallArray(inc, incL) { castS(L, incL) if (eqG(L, mainH)) { @@ -2002,13 +2003,18 @@ int MAIN(int ARGC, char** ARGV) { iPrependS(&s, "/"); iPrependS(&s, buildPath); } - pushG(incList, s); - free(s); + if (getG(s, unusedV, -1) == 'a') { + pushNFreeG(aLibPackages, s); + } + else { + pushNFreeG(incList, s); + } finishG(L); } // uniquify the object list to avoid multiple symbol definitions uniqG(incList, unusedV); + uniqG(aLibPackages, unusedV); //logVarG(inc); //logVarG(incList) @@ -2070,14 +2076,6 @@ int MAIN(int ARGC, char** ARGV) { l += strlen(buildPath); } - // L is in the format: shpPackages/NAME/NAME.a - if (hasG(l, PACKAGE_DIR)) { - // the packages are already compiled - // keep .a files - finishG(L); - continue; - } - if (fileExistsG(ssGet(L))) { if (getG(cfgD, rtBool, "print_compile_commands")) { printf("rm %s", ssGet(L)); @@ -2098,8 +2096,14 @@ int MAIN(int ARGC, char** ARGV) { // when there are no other object files beside the main one, set incList to empty string emptyS(incObjFiles); } + char *aLibFiles = joinSG(aLibPackages, " "); + if (!aLibFiles) { + // when there are no a libs, set aLibFiles to empty string + emptyS(aLibFiles); + } terminateG(incList); + terminateG(aLibPackages); //logVarG(incObjFiles) // setup lflags key depending on the options: -c lflags, -t testLflags, -m memcheckLflags @@ -2169,7 +2173,7 @@ int MAIN(int ARGC, char** ARGV) { if (!sheepyParams.compileLib) { if (!sheepyParams.dontCompileExe) { - asprintf(&ld, GCC " %s -o %s %s %s %s/%s "PTHREAD" %s%s %s", m32bit, buildExePath, mainOPath, incObjFiles, libsheepyDir, libsheepy, lflags, linker, run); + asprintf(&ld, GCC " %s -o %s %s %s %s %s/%s "PTHREAD" %s%s %s", m32bit, buildExePath, mainOPath, incObjFiles, aLibFiles, libsheepyDir, libsheepy, lflags, linker, run); } else { ld = emptySF(); @@ -2177,13 +2181,13 @@ int MAIN(int ARGC, char** ARGV) { } else { // link library in current folder - asprintf(&ld, "gcc %s -shared -o %s.so %s %s %s/%s "PTHREAD" %s%s", m32bit, rootMain, mainOPath, incObjFiles, libsheepyDir, libsheepy, lflags, linker); + asprintf(&ld, "gcc %s -shared -o %s.so %s %s %s %s/%s "PTHREAD" %s%s", m32bit, rootMain, mainOPath, incObjFiles, aLibFiles, libsheepyDir, libsheepy, lflags, linker); } } else { // TODO update command - ld = malloc(strlen(rootMain) + strlen(rootMain) + strlen(incObjFiles) + strlen(libsheepyDir) + strlen(libsheepy) + strlen(lflags) + strlen(run) + 1 + 24); - sprintf(ld, "tcc -o %s %s.o %s %s/%s -pthread %s %s", rootMain, rootMain, incObjFiles, libsheepyDir, libsheepy, lflags, run); + ld = malloc(strlen(rootMain) + strlen(rootMain) + strlen(incObjFiles) + strlen(aLibFiles) + strlen(libsheepyDir) + strlen(libsheepy) + strlen(lflags) + strlen(run) + 1 + 25); + sprintf(ld, "tcc -o %s %s.o %s %s %s/%s -pthread %s %s", rootMain, rootMain, incObjFiles, aLibFiles, libsheepyDir, libsheepy, lflags, run); } free(lflags); @@ -2201,8 +2205,8 @@ int MAIN(int ARGC, char** ARGV) { if (sheepyParams.compileLib) { // link library in current folder // options: c create, q append objects, T thin archive for recursive library dependencies in packages - ld = malloc(strlen(ar32bit) + strlen(rootMain) + strlen(mainOPath) + strlen(incObjFiles) + 1 + 25); - sprintf(ld, "ar %s -cqT %s.a %s %s > /dev/null", ar32bit, rootMain, mainOPath, incObjFiles); + ld = malloc(strlen(ar32bit) + strlen(rootMain) + strlen(mainOPath) + strlen(incObjFiles) + strlen(aLibFiles) + 1 + 26); + sprintf(ld, "ar %s -cqT %s.a %s %s %s > /dev/null", ar32bit, rootMain, mainOPath, incObjFiles, aLibFiles); if (getG(cfgD, rtBool, "print_compile_commands")) { printf("%s\n", ld); } @@ -2212,6 +2216,7 @@ int MAIN(int ARGC, char** ARGV) { // mainOPath is not used after link step free(mainOPath); free(incObjFiles); + free(aLibFiles); //puts("LIST SOURCES"); //TODO use logE in pError0 and setModificationTime and disable logging with setMaxLogLevel