Merge two lists in Makefile - makefile

I have following two lists in makefile:
SERVERS=172.16.0.117 172.16.0.147
PORTS=1600 1601
I want the new list as following
172.16.0.117-1600 172.16.0.17-1601 172.16.0.147-1600 172.16.0.147-1601
I don't know what am I doing wrong. Could you please help me out? Please have a look at makefile source code and the output. Thanks in advance.
Makefile source code:
SERVERS=172.16.0.117 172.16.0.147
PORTS=1600 1601
SERVER=$(addprefix Connect-to-, $(SERVERS))
PORT=$(addprefix $(SERVER)-, $(PORTS))
testall:
echo "PORTS - $(PORT)"
Output of makefile:
#make
echo "PORTS - Connect-to-172.16.0.117 Connect-to-172.16.0.147-1600 Connect-to-172.16.0.117 Connect-to-172.16.0.147-1601"
PORTS - Connect-to-172.16.0.117 Connect-to-172.16.0.147-1600 Connect-to-172.16.0.117 Connect-to-172.16.0.147-1601

Something like this?
PORT := $(foreach p,$(PORTS),$(patsubst %,%-$p,$(SERVERS)))

Related

Can reuse makefile multiple times within single execution?

Suppose I have:
# ./Makefile
CLUSTER=dev
include Makefile.cluster.mk
CLUSTER=local
include Makefile.cluster.mk
And in:
# ./Makefile.cluster.mk
${CLUSTER}.cmd:
cmd ${CLUSTER}
So now I can call:
make dev.cmd
make local.cmd
Great! Except the variable is evaluated too late. Running:
$ make local.cmd # cmd local
$ make dev.cmd # Also cmd local !
Make sense: according to: https://www.gnu.org/software/make/manual/html_node/Reading-Makefiles.html
rule steps are deferred evaluation (vs. immediate/on file load).
immediate : immediate ; deferred
deferred
Is there a better/other way to compose a set of make commands without maintaining multiple copies of the same file?
There are lots of ways to do it, even beyond the options above; you could use static pattern rules:
CLUSTERS := dev local
$(CLUSTERS:%=%.cmd) : %.cmd :
cmd $*
If you really want to have stuff in a separate makefile you can use target-specific variables; change your Makefile.cluster.mk to do this:
# ./Makefile.cluster.mk
${CLUSTER}.cmd: CLUSTER := $(CLUSTER)
${CLUSTER}.cmd:
cmd ${CLUSTER}
Is there a better/other way to compose a set of make commands without maintaining multiple copies of the same file?
Often it's pattern rules. In the case of your particular example, you might do
Makefile
%.cmd:
cmd '$*'
However, that particular version will enable any make foo.cmd, which might not be what you want.
Sometimes it's to make better use of the tools available to you. For example,
Makefile.cluster.mk
${CLUSTER}.cmd:
arg='$#'; cmd "$${arg%.cmd}"
That extracts the wanted cluster name from the name of the target.
Occasionally it is $(eval).
(See the manual for an example.)
And from time to time, it's "don't do that." For example,
Makefile
CLUSTERS = dev local
CMDS = $(patsubst %,%.cmd,$(CLUSTERS))
$(CMDS):
arg='$#'; cmd "$${arg%.cmd}"
That defines only dev.cmd and local.cmd targets, and avoids duplicating the recipe.

Make File Optional Options

i'm just creating my very first Makefile and would need some help:
make foobar stefan
expected:
i'd need the "stefan" in a variable to work with it - is there any way for it?
thanks,
Stefan

Why didn't the .rb execute?

I'm quite new to coding and terminal. Does anybody know what the problem is below with my last command line? I'm still working on all other files from 01 to 04, and they execute normally but not the 05. I couldn't put any other new command lines after that either.
Thank you for checking on it for me. Any help is appreciated! :)
hienthu#Hiens-MacBook-Air Webdev % cd algorithmic_strategies_exercise
hienthu#Hiens-MacBook-Air algorithmic_strategies_exercise % ls
01_swapper.rb 04_peak_finder.rb
02_is_sorted.rb 05_compress_str.rb
03_bubble_sort.rb algorithmic_strategies_exercise.zip
hienthu#Hiens-MacBook-Air algorithmic_strategies_exercise % ruby 05_compress_str.rb

Single title in JLine 3 help output

How do I customize the help command in JLine 3? The help in my JLine 3 shell sample displays as:
manager> help
System:
exit exit from app/script
help command help
Builtins:
ShellCommandRegistry:
create Create some stuff with minimal fuss...
delete Deletes some stuff with minimal fuss...
list List some stuff with minimal fuss...
I'd like to replace the section titles ("System:", "Builtins:", and "ShellCommandRegistry:") with single "Commands:" title like:
manager> help
Commands:
exit exit from app/script
help command help
create Create some stuff with minimal fuss...
delete Deletes some stuff with minimal fuss...
list List some stuff with minimal fuss...
Any ideas how to control this in JLine 3?
At the moment it is not possible to customize command groupings.
Will be fixed in next JLine version (> 3.15.0):
Added help command options: --nogroups (--groups) and --info.
Default grouping behaviour can be controlled by setting
systemRegistry.setGroupCommandsInHelp(true/false)
.
groovy-repl> help --help
help - command help
Usage: help [TOPIC...]
-? --help Displays command help
--nogroups Commands are not grouped by registeries
-i --info List commands with a short command infos
groovy-repl>
Using jline 3.20.0:
I wrote my own Registry and registered the other into this one, like this:
MyAppCommands myAppCommands = new MyAppCommands(parser, terminal, workDir, null);
myAppCommands.setCommandRegistries(builtins, picocliCommands);
myAppCommands.register("help", myAppCommands);
where MyAppCommands extends SystemRegistryImpl. Then the help command shows only the class-name "MyAppCommands:"
Therefore if you name your registry class "Commands" you'll get your desired result!

bash: wrong behavior in for... loop together with a test statement

I am trying to test if certain files, called up in a list of textfiles, are in a certain directory. Every once in a while (and I am quite certain I use the same statements every time) I get an error, complaining that the echo command cannot be found.
The textfiles I have in my directory /audio/playlists/ are named according to their date on which they are supposed to be used: 20130715.txt for example for today:
me#computer:/some/dir# ls /audio/playlists/
20130715.txt 20130802.txt 20130820.txt 20130907.txt 20130925.txt
20130716.txt 20130803.txt 20130821.txt 20130908.txt 20130926.txt
(...)
me#computer:/some/dir# cat /audio/playlists/20130715.txt
#A Comment line goes here
00:00:00 141-751.mp3
00:03:35 141-704.mp3
00:06:42 140-417.mp3
00:10:46 139-808.mp3
00:15:13 136-126.mp3
00:20:26 071-007.mp3
(...)
23:42:22 136-088.mp3
23:46:15 128-466.mp3
23:50:15 129-592.mp3
23:54:29 129-397.mp3
So much for the facts. The following statement, which lets me test if all files called upon in all of the textfiles in the given directory are actually a file in the directory /audio/mp3/, produces an error:
me#computer:/some/dir# for i in $(cat /audio/playlists/*.txt|cut -c 10-16|sort|uniq); do [ -f "/audio/mp3s/$i.mp3" ] || echo $i; done
 echo: command not found
me#computer:/some/dir#
I would guess bash wants to complain about the "A Comment"-line (actually " line ") not being a file, but why would that cause echo not to be found? Again, mostly this works, but every so often I get this error. Any help is greatly appreciated.
That space before echo isn't U+0020, it's U+00A0. And indeed, the command " echo" doesn't exist.

Resources