Re: multi-threaded compiling
Mischa Baars <[email protected]> Tue, 12 Mar 2024 09:42:22 +0100
| Newsgroups | gmane.comp.gnu.make.general,gmane.comp.shells.bash.bugs |
|---|---|
| Message-ID | <CA+b5WFE6ZoXD-j8u6VNy0CU-y4NorLWi_rjF3vebCme4yekSiQ@mail.gmail.com> |
Here's the script and the Makefile using "printf '<%s>'": On Tue, Mar 12, 2024 at 9:32 AM Martin D Kealey <[email protected]> wrote: > In section one, the problem is that "wait -n" does not do what you think > it does. (Lots of us think this behaviour is broken, and it may be fixed in > an upcoming version of Bash.) You don't need '-n' when you specify a PID; > the fix is simply to remove it. > > In section two, the problem is that quote removal is done BEFORE variables > are expanded, even though it prevents word splitting from being done AFTER > variable expansion. Therefore writing VAR=" \"string 1\" \"string 2\" " > absolutely cannot do what you might expect; the embedded quote marks will > be used literally, and then (because ${CFLAGS[0]} is not quoted) the > resulting string will be split on any embedded whitespace.. > > > On Mon, 11 Mar 2024 at 18:56, Mischa Baars <[email protected]> > wrote: > >> Hi, >> >> I'd like to compile a project of mine using multiple logical cores. >> >> I've attached the problem. It consists of two parts: >> >> 1) multi-threaded bash script and / or multi-threaded Makefile >> >> Running bash script functions as expected, but executing the same line of >> code with make and / or the command line, does not function. Perhaps >> someone could explain to me why? >> >> 2) passing a string argument from a bash script and / or Makefile to the >> gcc -D option >> >> Running the makefile functions as expected, but I have not been able to >> get >> similar code to work from a bash script. Can someone please explain to me >> what I'm doing wrong? >> >> Hope to hear from you soon. >> >> Best regards, >> Mischa Baars. >> >
Makefile
(application/octet-stream, 1.2 KB) - not displayed
make.sh
(application/x-shellscript, 1.2 KB)
#
# :set tabstop=9
#
#!/bin/bash
STR[0]="one and two"
STR[1]=one\ and\ two
CFLAGS[0]="-D__STRINGIZED__=0 -D__STRING__=\"${STR[0]}\""
CFLAGS[1]="-D__STRINGIZED__=0 -D__STRING__=\"${STR[1]}\""
CFLAGS[2]="-D__STRINGIZED__=1 -D__STRING__=\"${STR[0]}\""
CFLAGS[3]="-D__STRINGIZED__=1 -D__STRING__=\"${STR[1]}\""
# 1
printf '<%s>' gcc -o main main.c -D__STRINGIZED__=0 -D__STRING__="one and two"; echo;
printf '<%s>' gcc -o main main.c -D__STRINGIZED__=0 -D__STRING__=one\ and\ two; echo;
printf '<%s>' gcc -o main main.c -D__STRINGIZED__=1 -D__STRING__="one and two"; echo;
printf '<%s>' gcc -o main main.c -D__STRINGIZED__=1 -D__STRING__=one\ and\ two; echo;
# 2
printf '<%s>' gcc -o main main.c -D__STRINGIZED__=0 -D__STRING__="${STR[0]}"; echo;
printf '<%s>' gcc -o main main.c -D__STRINGIZED__=0 -D__STRING__="${STR[1]}"; echo;
printf '<%s>' gcc -o main main.c -D__STRINGIZED__=1 -D__STRING__="${STR[0]}"; echo;
printf '<%s>' gcc -o main main.c -D__STRINGIZED__=1 -D__STRING__="${STR[1]}"; echo;
# 3
printf '<%s>' gcc -o main main.c "${CFLAGS[0]}"; echo;
printf '<%s>' gcc -o main main.c "${CFLAGS[1]}"; echo;
printf '<%s>' gcc -o main main.c "${CFLAGS[2]}"; echo;
printf '<%s>' gcc -o main main.c "${CFLAGS[3]}"; echo;
main.c
(text/x-csrc, 285 B)
/* * * *
* :set tabstop=9
*/
#include <stdio.h>
#define str(x) lit(x)
#define lit(x) #x
int main ()
{
#ifndef __STRINGIZED__
const char* s = __STRING__ ;
#else
const char* s = str(__STRING__);
#endif
printf ("STRINGIZED: %d, STRING: %s\n", __STRINGIZED__, s);
}