How should I design makefile hierarchy? - makefile

I'm learning to write make file but I don't really have a clear mind how should I design my makefile hierarchy. It is not easy to describe so I'll post exactly what I have right now and any suggestions are appreciated.
So what I want to ask is
1. Does my common.mk a general practice to contain TOP_DIR variable?
2. How can I make makefile(1) call makefile(2) if l_util objects are missing.
I have such folder hierarchy which I used to learn c++ algorithms:
-learning
- introduction_to_algorithms
- insertion_sort
- insertion_sort.cpp
- makefile(1)
- l_util
- include
- l_util_stlutil.h
- l_util_numberutil.h
- l_util_stlutil.cpp
- l_util_numberutil.cpp
- makefile(2)
- common.mk
where insertion_sort.cpp includes l_util files. Here are my make files:
common.mk:
1 # This must be the first this in Makefile.common
2 TOP_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
3
4 CC := g++
makefile(1):
1 include ../../common.mk
2
3 CPP_SRCS := \
4 insertion_sort.cpp \
5
6 LIBS := \
7
8 OBJS := \
9 insertion_sort.o \
10
11 OTHER_OBJS := \
12 $(TOP_DIR)l_util/l_util_stlutil.o \
13 $(TOP_DIR)l_util/l_util_numberutil.o \
14
15 INCLUDE_PATH := \
16 $(TOP_DIR)l_util/include
17
18 TASK := insertion_sort.tsk
19
20 # Tool invocations
21 $(TASK): $(OBJS) $(OTHER_OBJS)
22 $(CC) -o $(TASK) $(OBJS) $(OTHER_OBJS) $(LIBS)
23 #echo 'Finished building target: $#'
24
25 $(OBJS): $(CPP_SRCS)
26 $(CC) -c -Wall -I$(INCLUDE_PATH) $(CPP_SRCS)
27 #echo 'Finished building target: $#'
28
29 # Other Targets
30 .PHONY: clean
31 clean:
32 -$(RM) $(OBJS) $(OTHER_OBJS) $(TASK)
makefile(2):
1 include ../common.mk
2
3 CPP_SRCS := \
4 l_util_stlutil.cpp \
5 l_util_numberutil.cpp \
6
7 LIBS := \
8
9 OBJS := \
10 l_util_numberutil.o \
11 l_util_stlutil.o \
12
13 $(OBJS): $(CPP_SRCS)
14 $(CC) -c -Wall $(CPP_SRCS)
15 #echo 'Finished building target: $#'
16
17 # Other Targets
18 .PHONY: clean
19 clean:
20 -$(RM) $(OBJS)
When I run make in insertion_sort folder I get:
1 g++ -c -Wall -I../../l_util/include insertion_sort.cpp
2 Finished building target: insertion_sort.o
3 c++ -c -o ../../l_util/l_util_stlutil.o ../../l_util/l_util_stlutil.cpp
4 c++ -c -o ../../l_util/l_util_numberutil.o ../../l_util/l_util_numberutil.cpp
5 g++ -o insertion_sort.tsk insertion_sort.o ../../l_util/l_util_stlutil.o
../../l_util/l_util_numberutil.o
6 Finished building target: insertion_sort.tsk
I don't think line 3 and 4 are generated by makefile(2), it seems like it's been called automatically without calling makefile(2).

add some code in makefile1:
$(OTHER_OBJS):
make -C “The absolute dir of your makefile2"
your should tell makefile1, where is your makefile2, "make -C" will do that, and make makefile1 call makefile2.

You should use GNUmake and take advantage of its include functionality to build a single hierarchy of dependencies across the entire project.
This is, in practice, the only realistic way of creating a make-based build system that does incremental build correctly. This is they way kbuild, the Linux kernel build system works.
See Recursive Make Considered Harmful.

Related

How to avoid enumeration of object files?

Well, project has:
-include directory /* for header files */
-src dir. /* for source code */
-build dir. /* for object and executable files */
Makefile:
1 BUILD_DIR = $(CURRENT_DIR)/build
2 INCLUDE_DIR = $(CURRENT_DIR)/include
3 SRC_DIR = $(CURRENT_DIR)/src
4
5 CC = gcc
6 CFLAGS = -Wall -g -I
7
8 $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(INCLUDE_DIR)/%.h
9 #$(CC) $(CFLAGS) $(INCLUDE_DIR) -c $< -o $#
10
11 SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
12 HEADER_FILES= $(wildcard $(INCLUDE_DIR)/*.h)
13
14
15 OBJECT_FILES= $(BUILD_DIR)/module_1.o \
16 $(BUILD_DIR)/module_2.o \
17 $(BUILD_DIR)/module_3.o
18
19
20 prog: $(SRC_DIR)/main.c $(OBJECT_FILES)
21 #$(CC) $(CFLAGS) $(INCLUDE_DIR) $^ -o $(BUILD_DIR)/$#
How to avoid enumeration of object files, smth like:
OBJECT_FILES = $(wildcard $(BUILD_DIR)/*.o)
but this line produce "undefined reference" error.
You can't use $(wildcard $(BUILD_DIR)/*.o) because those files don't exist when the makefile is read in: they are built by the makefile. So this will be empty when you start to build.
Generally what people do is convert the list of source files into object files, since that's what the compiler does. So:
OBJECT_FILES := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRC_FILES))

compiling *.C and *.S sources from same directory 'make'

I have been working with a project that only compiles C sources but I've found I need some assembler too, I'm reticent to inline the asm code in a C file as GCC may not interpret it correctly.
My predecesor created the makefile for the project (apologies, it's fairly long):
# Compiler and options
CC := sparc-rtems-gcc
# The application software binary
TARGET := icu_asw
# Source and build directories
SRCDIR := src
BUILDDIR := obj
TARGETDIR := bin
HDSWROOT := ../../hdsw
BSWTOOLS := ../../bsw/sw/tools
SRCEXT := c
DEPEXT := d
OBJEXT := o
MRAMEXT := img.elf
# Flags, libraries and includes
CFLAGS := -std=gnu99 -Wall -Wextra -g
LIBDRV := $(HDSWROOT)/lib/libdrv.a
INCFLAGS := -I$(HDSWROOT)/include -I$(HDSWROOT)/osal/rtems
# Debug flags
DEBUGFLAGS = -DLOGERROR=1 -DLOGWARN=1 -DLOGDEBUG=1 -DLOGINFO=1 -DMAKECHECKS=1
NODEBUGFLAGS = -DLOGERROR=1 -DLOGWARN=0 -DLOGDEBUG=0 -DLOGINFO=0 -DMAKECHECKS=1
#-----------------------------------------------------------------------
# Build instructions
#-----------------------------------------------------------------------
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
# Default make
all: $(TARGET)
# Remake
remake: cleaner all
# Clean only objects
clean:
#$(RM) -rf $(BUILDDIR)
# Full clean (objects and binaries)
cleaner: clean
#$(RM) -rf $(TARGETDIR)
# Pull in dependency info for *existing* .o files
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
# Link (uses an order-only prerequisite for the directories so that they
# don't affect the use of the $^)
$(TARGET): $(OBJECTS) | directories
$(CC) -o $(TARGETDIR)/$(TARGET) $^ $(LIBDRV)
# Make the build and target directories
directories:
#mkdir -p $(TARGETDIR)
#mkdir -p $(BUILDDIR)
# Compile
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
#mkdir -p $(dir $#)
$(CC) $(CFLAGS) $(INCFLAGS) $(NODEBUGFLAGS) -c -o $# $<
#$(CC) $(CFLAGS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT)
#cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp
#sed -e 's|.*:|$(BUILDDIR)/$*.$(OBJEXT):|' < $(BUILDDIR)/$*.$(DEPEXT).tmp > $(BUILDDIR)/$*.$(DEPEXT)
#sed -e 's/.*://' -e 's/\\$$//' < $(BUILDDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(BUILDDIR)/$*.$(DEPEXT)
#rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp
# Non-File Targets
.PHONY: all remake clean cleaner
I want to also bring in and compile two .S files, so, I edited the following line
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT) -or -name *.$(ASMEXT))
To bring in the .S files, then I edited the OBJECTS to also include the ASM sources ("*.S")
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)),$(SOURCES:.$(ASMEXT)=.$(OBJEXT)))
But when recompiling with 'make all' I'm getting:
$ make all
make: *** No rule to make target `obj/asi_access.S', needed by `icu_asw'. Stop.
I don't suppose someone could spot where I am going wrong? I think I have not correctly added to the OBJECTS line!
Thanks
The expression $(var:.ext1=.ext2) does not filter by .ext1, i.e.
$(SOURCES:.$(SRCEXT)=.$(OBJEXT)) $(SOURCES:.$(ASMEXT)=.$(OBJEXT))
gives for a test source list the following result
a.o b.o c.S a.c b.c c.o
I.e. you duplicated your files and you have source files in the OBJECTS definition.
The following would be a correct approach:
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%, \
$(patsubst %.$(SRCEXT),%.$(OBJEXT), \
$(patsubst %.$(ASMEXT),%.$(OBJEXT),$(SOURCES)) \
) \
)
UPDATE: you should consider to use 2 separate object lists, so that you can apply different rules for them, e.g.
SOURCES_C := $(filter %.$(SRCEXT),$(SOURCES))
OBJECTS_C := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_C:%.$(SRCEXT)=%.$(OBJEXT)))
SOURCES_ASM := $(filter %.$(ASMEXT),$(SOURCES))
OBJECTS_ASM := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES_ASM:%.$(ASMEXT)=%.$(OBJEXT)))
$(OBJECTS_C): $(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
.... C compiler recipe ....
$(OBJECTS_ASM): $(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(ASMEXT)
.... assembler recipe ....
$(TARGET): $(OBJECTS_C) $(OBJECTS_ASM) | directories

How to build a program with Make using different build configurations?

yesterday I wrote a Makefile to build a Programm which works fine.
Now, I try to build different build configurations.
What is the recommended way to build different configurations which differ in the list of source files and output paths?
I tried to use target specific variables...
Executables of the compiler toolchain.
COMPILER := ccrl
LINKER := rlink
ASSEMBLER := asrl
DEVICE_FILE := DR5F100LL.DVF
Compiler flags used to generate *.d files.
DFLAGS := \
-MM \
-MP \
-cpu=S2 \
-dev="$(DEVICE_FILE)" \
-no_warning_num=11179,11180 \
-g \
-Onothing
Compiler flags used to generate *.obj files from c source files.
CFLAGS := \
-cpu=S2 \
-c \
-dev="$(DEVICE_FILE)" \
-no_warning_num=11179,11180 \
-g \
-Onothing
Compiler flags used to generate *.obj files from assembler files.
ASMFLAGS := $(CFLAGS)
Linker flags
LDFLAGS := \
-library="${COMPILER_PATH}/lib/rl78cm4s.lib" \
-library="${COMPILER_PATH}/lib/rl78cm4r.lib" \
-library="./FFT_Library/libfft_rl78g13.lib" \
-nooptimize \
-entry=_start \
-security_id=00000000000000000000 \
-ocdbg=04 \
-user_opt_byte=EEFFE9 \
-debug \
-nocompress \
-memory=high \
-vectn=2=ffff \
-rom=.data=.dataR \
-rom=.sdata=.sdataR \
-nomessage \
-device="$(DEVICE_FILE)" \
-nologo \
-start=.const,.text,.RLIB,.SLIB,.textf,.constf,.data,.sdata/03000,.dataR,.bss/0F7F00,.sdataR,.sbss/0FFE20
Include directories
C_INCS := \
-I${COMPILER_PATH}/inc \
...
C source files used build the program.
C_SRCS_FFT_TEST := \
CodeGenerator/r_cg_cgc.c \
...
C_SRCS_HISTORY_TEST := \
CodeGenerator/r_cg_cgc.c \
...
C_SRCS_IOLINK_TEST := \
CodeGenerator/r_cg_cgc.c \
...
Assembler files used to build the program.
ASM_SRCS := \
...
Root directories of the build results.
OUT_ROOT_DIR := build
PUBLISH_ROOT_DIR := publish
.SECONDEXPANSION:
Name of the build configuration.
BUILD_CONFIG = Unknown
OUT_DIR =$(OUT_ROOT_DIR)/$(BUILD_CONFIG)
PUB_DIR =$(PUBLISH_ROOT_DIR)/$(BUILD_CONFIG)
Determine file paths of generated files.
OBJS = $(patsubst %.c,$(OUT_DIR)/%.obj,$(C_SRCS))
OBJS += $(patsubst %.asm,$(OUT_DIR)/%.obj,$(ASM_SRCS))
DEPS = $(OBJS:.obj=.d)
Filenames of the output files.
OUT_FILE = $(PUB_DIR)/MyFile.abs
MAP_FILE = $(OUT_DIR)/MyFile.map
.PHONY: build-definitions
build-definitions: fft-test history-test iolink-test
fft-test: BUILD_CONFIG=FFT_Test
fft-test: C_SRCS=$(C_SRCS_FFT_TEST)
.PHONY: fft-test
fft-test: $$(OUT_FILE)
history-test: BUILD_CONFIG=History_Test
history-test: C_SRCS=$(C_SRCS_HISTORY_TEST)
.PHONY: history-test
history-test:
#echo -e "Building $(BUILD_CONFIG)."
iolink-test: BUILD_CONFIG=IOLink_Test
iolink-test: C_SRCS=$(C_SRCS_IOLINK_TEST)
.PHONY: iolink-test
iolink-test:
#echo -e "Building $(BUILD_CONFIG)."
.PHONY: all
all: pre-build $(OUT_FILE) post-build
.PHONY: pre-build
pre-build:
#echo -e "Run pre-build target."
.PHONE: post-build
post-build:
#echo -e "Run post-build target."
.PHONY: clean
clean:
#echo -e "Run clean target."
#rm -f -v $(OUT_DIR)/LinkerSubCommand.tmp
#rm -f -v $(OBJS)
#rm -f -v $(DEPS)
#rm -f -v $(OUT_FILE)
#rm -f -v $(MAP_FILE)
How to build the dependency file from a c source file.
$(OUT_DIR)/%.d : %.c
#echo 'Building d file: $<'
#mkdir -p "$(dir $#)"
$(COMPILER) $(DFLAGS) $(C_INCS) -o "$(#:%.obj=%.d)" -MT="$#" -MT="$(#:%.obj=%.d)" "$<"
How to build the dependency file from an asm file.
$(OUT_DIR)/%.d : %.asm
#echo 'Building d file: $<'
#mkdir -p "$(dir $#)"
$(COMPILER) $(DFLAGS) $(C_INCS) -o "$(#:%.obj=%.d)" -MT="$#" -MT="$(#:%.obj=%.d)" "$<"
How to build the object file from a c source file.
$(OUT_DIR)/%.obj : %.c
#echo 'Building obj file: $<'
#mkdir -p "$(dir $#)"
$(COMPILER) $(CFLAGS) $(C_INCS) -o "$#" "$<"
#echo -e $(#:%=-input=\"%\") >> $(OUT_DIR)/LinkerSubCommand.tmp
How to build the object file from an asm file.
$(OUT_DIR)/%.obj : %.asm
#echo 'Building asm file: $<'
#mkdir -p "$(dir $#)"
$(COMPILER) $(CFLAGS) $(C_INCS) -o "$#" "$<"
#echo -e $(#:%=-input=\"%\") >> $$(OUT_DIR)/LinkerSubCommand.tmp
#
$(OBJ): %.obj: %.c $(DEPS)
How to build the output file from all object files.
%.abs : $(OBJS)
#echo -e "Building $(BUILD_CONFIG)."
#echo -e "The output directory is $(OUT_DIR)."
#echo -e "The publish directory is $(PUB_DIR)."
#echo -e "The source files are $(C_SRCS)."
#echo -e "The assembler files are $(ASM_SRCS)."
#echo -e "The generated object files are $(OBJS)."
#echo -e "Building output file is $#."
#mkdir -p "$(PUB_DIR)"
#mkdir -p "$(OUT_DIR)"
$(LINKER) $(LDFLAGS) -subcommand="$(OUT_DIR)/LinkerSubCommand.tmp" -list="$(MAP_FILE)" -output="$(OUT_FILE)"
I know that I should use private as scope of the target specific variables but than I have to download/compile a newer make Version...
I would like to know the recommended way to build such configurations.
Maybe someone can provide a simple (and complete) example?
Thanks a lot!
Michael
Makefile:
ifeq ($(config), debug)
CFLAGS := -DDEBUG -g
OUT_PATH := ./build/debug/
else ifeq ($(config), light_debug)
CFLAGS := -g
OUT_PATH := ./build/light_debug/
else #release config by default
OUT_PATH := ./build/release
endif
#...
Then make invokation is like this:
make confg=debug
or
make config=light_debug
or
make config=release

makefile-compiling-back-and-forth - follow up

In continuation with my earlier question
Makefile - compiling back and forth
I made an attempt in creating a single Makefile. The two subdirectories are HAM-src and GFS-src. However, I am still unable to build it. I paste my Makefile below:
export
SHELL = /bin/sh
top_srcdir=./Temp
objdir=$(top_srcdir)/obj
bindir=${exec_prefix}/bin
cfssrcdir=${top_srcdir}/GFS-src
hamsrcdir=${top_srcdir}/HAM-src
incdir=${top_srcdir}/include
exec=${bindir}/esm_gfs-ham_v0
PROG=$(exec)
LDR = mpxlf90_r -qsmp=noauto
FFLAG90 = $(OPTS90) $(FINCS) -qfree=f90 -NS2048 -qmoddir=$(objdir) -I$(objdir)
FFLAGM = -NS2048 -qfixed -qmoddir=$(objdir) -I$(objdir)
F77 = mpxlf95
F90 = mpxlf95
F90_x = xlf90_r
F90_r = mpxlf95_r
SRCHAM = $(hamsrcdir)/ham_control.f90 $(hamsrcdir)/mo_filename.f90 \
$(hamsrcdir)/ham_namelist.f90 $(hamsrcdir)/ham_submodel.f90 \
$(hamsrcdir)/ham_submodel_diag.f90 $(hamsrcdir)/ham_ham.f90
SRCGFS_MOD=$(cfssrcdir)/machine.f $(cfssrcdir)/resol_def.f \
$(cfssrcdir)/omegas.f $(cfssrcdir)/cnvcld_v.f
OBJGFS_MOD = $(patsubst $(cfssrcdir)/%.f,$(objdir)/%.o,$(SRCGFS_MOD))
OBJHAM = $(patsubst $(hamsrcdir)/%.f90,$(objdir)/%.o,$(SRCHAM))
.SUFFIXES: $(SUFFIXES) .f90 .f .o
all: $(PROG)
$(PROG): $(OBJHAM) $(OBJGFS_MOD)
$(LDR) $(CFS_LDFLAGS) -o $# $(OBJGFS_MOD) $(OBJHAM) $(CFS_LIBS) -L$(LDFLAGS)
$(objdir)/%.o: $(cfssrcdir)/%.f
$(F77) $(FFLAGS) -c $< -o $#
$(objdir)/%.o: $(hamsrcdir)/%.f90
$(F90_r) $(F90FLAGS) -c $< -o $#
########## dependencies for $(hamsrcdir) ###########
ham_filename.o: ham_control.o
ham_namelist.o: ham_control.o ham_filename.o
ham_submodel.o: ham_control.o ham_namelist.o $(objdir)/resol_def.o
ham_submodel_diag.o: ham_submodel.o
########## dependencies for $(cfssrcdir) ###########
$(objdir)/omegas.o: $(cfssrcdir)/omegas.f
$(F77) $(FFLAGM) -c $(cfssrcdir)/omegas.f -o $#
$(objdir)/cnvcld_v.o: $(cfssrcdir)/cnvcld_v.f
$(F77) $(FFLAGM) -c $(cfssrcdir)/cnvcld_v.f -o $#
The error:
mpxlf95_r -q64 -O3 -qstrict -qMAXMEM=-1 -qarch=auto -qtune=auto -qcache=auto -qfloat=fltint -qsuffix=cpp=f90 -lessl_r -lmass -lmassv -I./Temp/include -I./Temp/HAM-src -qmoddir=./Temp/obj -I./Temp/obj -c ./Temp/HAM-src/ham_namelist.f90 -o ./Temp/obj/ham_namelist.o
** ham_namelist === End of Compilation 1 ===
1501-510 Compilation successful for file ham_namelist.f90.
mpxlf95_r -q64 -O3 -qstrict -qMAXMEM=-1 -qarch=auto -qtune=auto -qcache=auto -qfloat=fltint -qsuffix=cpp=f90 -lessl_r -lmass -lmassv -I./Temp/include -./Temp/HAM-src -qmoddir=./Temp/obj -I./Temp/obj -c ./Temp/HAM-src/ham_submodel.f90 -o ./Temp/obj/ham_submodel.o
"./Temp/HAM-src/ham_submodel.f90", line 425.7: 1514-219 (S) Unable to access module symbol file for module resol_def. Check path and file permissions of file. Use association not done for this module.
1501-511 Compilation failed for file ham_submodel.f90.
gmake: *** [/gpfs1/home/cccrmod/ham_expt_dec11/regrid_test/CFS-HAM/SORC_CFS-HAM/Temp/obj/ham_submodel.o] Error 1
Why makefile does not compile the resol_def.f module on encountering the dependency?
Another issue - my makefile is not working properly. It goes in a sequence in which the sources are defined.
This is difficult to untangle (a minimal, complete example really would help), but I'd suggest you change this
ham_submodel.o: ham_control.o ham_namelist.o $(objdir)/resol_def.o
to this
$(objdir)/ham_submodel.o: ham_control.o ham_namelist.o $(objdir)/resol_def.o
and see if that solves the first problem. I don't understand the last line of your question ("Another issue...").

How to generate targets in a Makefile by iterating over a list?

CODE:
LIST=0 1 2 3 4 5
PREFIX=rambo
# some looping logic to interate over LIST
EXPECTED RESULT:
rambo0:
sh rambo_script0.sh
rambo1:
sh rambo_script1.sh
Since my LIST has 6 elements, 6 targets should be generated. In future, if I want to add more targets, I want to be able to just modify my LIST and not touch any other part of the code.
How should the looping logic be written?
If you're using GNU make, you can generate arbitrary targets at run-time:
LIST = 0 1 2 3 4 5
define make-rambo-target
rambo$1:
sh rambo_script$1.sh
all:: rambo$1
endef
$(foreach element,$(LIST),$(eval $(call make-rambo-target,$(element))))
Use text-transforming functions. With patsubst you can make quite general transformations. For constructing filenames, addsuffix and addprefix are both convenient.
For the rules, use pattern rules.
The overall result might look something like this:
LIST = 0 1 3 4 5
targets = $(addprefix rambo, $(LIST))
all: $(targets)
$(targets): rambo%: rambo%.sh
sh $<
Just my 2 cents to #Idelic answer, if you need to use some Make $cmd you must escape them using $$
e.g.
LIST = 0 1 2 3 4 5
define make-rambo-target
$(info create target: $(addprefix rambo_script, $(addsuffix .sh, $1)).)
rambo$1: $$(addprefix rambo_script, $$(addsuffix .sh, $1))
sh $$<
endef
all: $(addprefix rambo, $(LIST))
$(foreach element, $(LIST), $(eval $(call make-rambo-target,$(element))))
output:
$ make
create target: rambo_script0.sh.
create target: rambo_script1.sh.
create target: rambo_script2.sh.
create target: rambo_script3.sh.
create target: rambo_script4.sh.
create target: rambo_script5.sh.
sh rambo_script0.sh
sh rambo_script1.sh
sh rambo_script2.sh
sh rambo_script3.sh
sh rambo_script4.sh
sh rambo_script5.sh
note: here rules "are seen" by Make as
rambo0: $(addprefix rambo_script, $(addsuffix .sh, 0))
sh $<
But here we could have written without escaping i.e.
rambo$1: $(addprefix rambo_script, $(addsuffix .sh, $1))
sh $$<
So rule "are seen" as:
rambo0 : rambo_script0.sh
sh $<
when Make parse it.

Resources