Shell Help with pipe and echo

I am trying to append text to every Makefile in /usr/ports/ directory and I am trying to figure out methods.

find /usr/ports/ -type f -name Makefile | echo "MAKE_ARGS+=STATIC=1" >>

echo "MAKE_ARGS+=STATIC=1" >> | find /usr/ports/ -type f -name Makefile

I think I need xargs but unure. I see examples with tee instead of find.. Maybe I need grep instead.

Can you help?

I have /usr/ports/Makefile backed up for this experiment. It is special..
 
Find itself has exec built in. I am having troubles though.
find /usr/ports/ -type f -name Makefile -execdir 'echo "MAKE_ARGS+=STATIC=1;"' ;
find: -exec: no terminating ";" or "+"

The man has an example for xargs that look similar. I am trying to grasp it.
echo -e "/usr/ports\n/etc\n/usr/local" | xargs -J % -P2 -n1 find % -name file
 
what about sed or awk





 
I saw some stackexchange posts with Tee and sed. That might be another future attempt.

One problem you get is different escaping on different shells
 
echo -e "/usr/ports\n/etc\n/usr/local" | xargs -J % -P2 -n1 find % -name file
Like I say it's all right here I just need to grasp. Figue out how many processes I want to spawn.
I guess xargs can run embedded commands too ( find in this example) even without a flag?
 
The -n value is what I am looking at.
I might need to increase This value -n to 40K for number of ports directories?

The current default value for number is 5000.

Since I am heavily jetlagged I get blurry looking at text desc for -J flag.
-J replstr
So I take it that means replacment string. Aka use this replacement string.
This is less useful because it uses the flags for cp in there.
list some files and sort | xargs -J % cp -Rp % destdir
So -J % triggers the command to use?


I dont think I want -J . I want to Append for sure.
replace the first occurrence of replstr in-stead of appending
 
Well I got somewhere. Not sure where but no errors. No Makefiles are touched.
I am noticing categories have Makefiles too.
Ouch. I did not see that coming.

find /usr/ports/ -type f -name Makefile | xargs -P0 -n 40000 echo "MAKE_ARGS+=STATIC=1"
 
I forgot the KISS process. Keep it simple stoopid.
Use one port and then expand outward.

find /usr/ports/sysutils/u-boot-master -type f -name Makefile | xargs -p -P0 echo "MAKE_ARGS+=STATIC=1"

Also implement -p for prompt to continue.
echo MAKE_ARGS+=STATIC=1 /usr/ports/sysutils/flashrom/Makefile?...yes
MAKE_ARGS+=STATIC=1 /usr/ports/sysutils/flashrom/Makefile
Still not writing to file. Removing -J needs something else to append.
 
xargs won't be able to use shell redirections. try something like this:

Code:
find /usr/ports -name Makefile | while read fn; do echo 'MAKE_ARGS+=STATIC=1' >> $fn ; done

this will get tripped up in the case of files with spaces in their name, but that's not the case in the ports tree.
 
I would simplify into steps:
find ... -type f -name ... > /tmp/foo
Then manually review that /tmp/foo has the correct list of files.
Then test the next step:
cat /tmp/foo | while read f ; do echo $f ; done
That should give you the list of files, and is now easy to decorate:
cat /tmp/foo | while read f ; do echo ... >> $f ; done
 
this will get tripped up in the case of files with spaces in their name, but that's not the case in the ports tree.
This is where -print0 in find and xargs -0 comes in. It can also sometimes get fixed by quoting correctly, although in the case of the find | xargs pipeline, that doesn't tend to work well. My solution with an intermediate file containing just the file names can get fixed quote easily: Edit the file name, to add quotes at the beginning and end of each line. This assumes that people don't put newlines into the file names (which is legal, but very evil).

Personally, I often find that it is easier to write a simple script with 10% of the effort to get 99% of the job done automatically. For example: When processing the files, check that they exist. That catches file names that were torn apart by having spaces in them:
cat /tmp/foo | while read f
Code:
cat /tmp/foo | while read f
do
    if [ -e $f ]
    then
        ... do whatever to process $f
    else
        echo File $f not found, please manually process it | tee /tmp/foo.errors
    fi
done
Then you know how many problems you have to fix, and you get a list of the problems.
 
Why don't use Makefile.local per port or bsd.local.mk?
So I can do one line-er inside Makefile.local per port
Thanks for that avenue.

This is one of those silly things I always wanted to try.
Just spike the whole ports tree to see how it builds with this setting.

What about Poudriere. Anyway to do static ports builds?
 
 
I often find that it is easier to write a simple script
I totally agree. That way you know the shebang it is using and these crazy escape codes and different esacping for different shells.

I am terrible with command line but practice is the only way to learn.

So a make.conf approach in Poudriere will be an easy way to build, test and teardown.

I had terrible problems with packages and Poudriere and ignored them and just built images.
It is easily a replacment for NanoBSD.
Maybe this is a good time to learn package building and bulk.

The purpose suits as well. I build embedded stuff with Poudriere Image so static built packages shouldn't be a big deal.
Embedded seems perfect place for static builds.
 
Back
Top