@@ -131,7 +131,7 @@ used for **all the other lines**.
131131
132132About the ** equal signs** :
133133
134- - ` := ` ** simply expand** the defined variable (like C equal sign ).
134+ - ` := ` ** simply expand** the defined variable (like C ` = ` ).
135135- ` = ` ** recursively expand** the defined variable (the expression is expanded
136136 afterward, when (and each time) the variable is used).
137137
163163[ ** Version 1 / Simplest C project** ] ( #version-1 )
164164
165165> - 42 C coding style conventions
166- > - ` MAKE ` predefined variable
166+ > - builtin variables
167167> - The C compilation implicit rule
168168> - pattern rule contains ` % ` character
169169> - Automatic variables in practice
202202> - ` addprefix ` make function
203203> - flags and libraries used by the linker
204204> - ` dir ` function
205- > - Compiling with a library recap
205+ > - Build with a library
206+ > - Linking with a library
206207> - builds each of the required libraries
207208> - call rules recursively
208209
@@ -231,7 +232,7 @@ The simplest, build a program called `icecream` with the following structure:
231232### v1 Brief
232233
233234- 42 C coding style conventions
234- - ` MAKE ` predefined variable
235+ - builtin variables
235236- The C compilation implicit rule
236237- pattern rule contains ` % ` character
237238- Automatic variables in practice
@@ -266,9 +267,10 @@ CFLAGS := -Wall -Wextra -Werror
266267# UTENSILS #
267268# ------------------------------------------------#
268269# RM force remove
270+ # MAKEFLAGS make flags
269271
270272RM := rm -f
271- MAKE := $( MAKE ) --no-print-directory
273+ MAKEFLAGS += --no-print-directory
272274
273275# ------------------------------------------------#
274276# RECIPES #
@@ -303,20 +305,23 @@ re:
303305# ###################################### END_1 ####
304306```
305307
306- - The choice of the ` CC ` and ` CFLAGS ` values, ` $( NAME) ` , ` clean ` , ` fclean ` ,
307- ` all ` and ` re ` as the basic rules as well as not using a wildcard to auto
308- generate the sources list is guided by the ** 42 C coding style conventions** ,
309- do not hesitate to disagree and change it (like renaming ` clean ` and ` fclean `
310- to the more GNU conventional ` mostlyclean ` and ` clean ` respectively).
308+ - The choice of the ` CC ` and ` CFLAGS ` values, ` NAME ` , ` clean ` , ` fclean ` , ` all `
309+ and ` re ` as the basic rules as well as not using a wildcard to auto generate
310+ the sources list is guided by the ** 42 C coding style conventions** , do not
311+ hesitate to disagree and change it (like renaming ` clean ` and ` fclean ` to the
312+ more GNU conventional ` mostlyclean ` and ` clean ` respectively).
311313
312314<sub ><sub ><hr ></sub ></sub >
313315
314- - ** ` MAKE ` ** is a ** predefined variable** whose value corresponds to the make
315- executable being run, for this reason we choose to increment its options.
316- When a Makefile is executed from another Makefile, the called's ` MAKE `
317- variable inherit from the caller's ` MAKE ` value. We pass it the
318- ` --no-print-directory ` flag for a cleaner output, try to remove it and run
319- ` make ` to see the difference.
316+ - ` MAKE ` and ` MAKEFLAGS ` are ** builtin variables** like ` CFLAGS ` and a lot of
317+ others that you can find in the * data-base* (` make --print-data-base `
318+ command). ` MAKE ` value corresponds to the ` make ` executable being run and
319+ ` MAKEFLAGS ` to its flags. When a Makefile is executed from another Makefile,
320+ the called's ` MAKE ` ` MAKEFLAGS ` variables inherit from the caller's ` MAKE `
321+ ` MAKEFLAGS ` values.
322+
323+ Here we append ` --no-print-directory ` to ` MAKEFLAGS ` content to have a clearer
324+ output, try to remove it and ` make re ` to see the difference.
320325
321326<sub ><sub ><hr ></sub ></sub >
322327
@@ -331,8 +336,8 @@ Where `%.o` expands to each objects, `%.c` to each sources, `$@` to the first
331336target (which is ` %.o ` ) and ` $< ` to the leftmost prerequisite (which is ` %.c ` ).
332337
333338* As their name implies implicit rules are implicit and do not need to be
334- written. All the implicit rules can be found in the data-base, accessible
335- with a ` make -p -f/dev/null | less ` shell command.*
339+ written. As well as the builtin variables, all the implicit rules can be found
340+ in the data-base, accessible with ` make -p -f/dev/null | less ` command.*
336341
337342<sub ><sub ><hr ></sub ></sub >
338343
@@ -485,10 +490,10 @@ CPPFLAGS := -I .
485490# UTENSILS #
486491# ------------------------------------------------#
487492# RM force remove
488- # MAKE quietly make
493+ # MAKEFLAGS make flags
489494
490495RM := rm -f
491- MAKE := $( MAKE ) --no-print-directory
496+ MAKEFLAGS += --no-print-directory
492497
493498# ------------------------------------------------#
494499# RECIPES #
@@ -650,11 +655,11 @@ CPPFLAGS := -I include
650655# UTENSILS #
651656# ------------------------------------------------#
652657# RM force remove
653- # MAKE quietly make
658+ # MAKEFLAGS make flags
654659# DIR_DUP duplicate directory tree
655660
656661RM := rm -f
657- MAKE := $( MAKE ) --no-print-directory
662+ MAKEFLAGS += --no-print-directory
658663DIR_DUP = mkdir -p $(@D )
659664```
660665
@@ -832,11 +837,11 @@ main.o: main.c main.o: main.c icecream.h
832837# UTENSILS #
833838# ------------------------------------------------#
834839# RM force remove
835- # MAKE quietly make
840+ # MAKEFLAGS make flags
836841# DIR_DUP duplicate directory tree
837842
838843RM := rm -f
839- MAKE := $( MAKE ) --no-print-directory
844+ MAKEFLAGS += --no-print-directory
840845DIR_DUP = mkdir -p $(@D )
841846
842847# ------------------------------------------------#
@@ -954,7 +959,8 @@ Builds an `icecream` **program that uses** `libbase` and `libarom`
954959- ` addprefix ` make function
955960- flags and libraries used by the linker
956961- ` dir ` function
957- - Compiling with a library recap
962+ - Build with a library
963+ - Linking with a library
958964- builds each of the required libraries
959965- call rules recursively
960966
@@ -1026,8 +1032,8 @@ LDLIBS := $(addprefix -l,$(LIBS))
10261032
10271033<sub ><sub ><hr ></sub ></sub >
10281034
1029- - ` LDFLAGS ` and ` LDLIBS ` contains the ** flags and libraries** that will be
1030- ** used by the linker** ` ld ` to link the library to our project sources.
1035+ - ` LDFLAGS ` and ` LDLIBS ` contain the ** flags and libraries** that will be ** used
1036+ by the linker** ` ld ` to link the library to our project sources.
10311037
10321038<sub ><sub ><hr ></sub ></sub >
10331039
@@ -1037,12 +1043,9 @@ LDLIBS := $(addprefix -l,$(LIBS))
10371043
10381044<sub ><sub ><hr ></sub ></sub >
10391045
1040- - ** Compiling with a library recap** :
1041-
1042- Compiling with a library requires, in addition to a C project and a library, a
1043- ` -I ` flag that indicates to the compiler where to find the library header files,
1044- ` -L ` indicate to the linker where to find the library and ` -l ` the name of this
1045- library (conventionally: lib<name >).
1046+ - ** Build with a library** requires three flags: ` -I ` tell the compiler where to
1047+ find the lib header files, ` -L ` tells the linker where to look for the library
1048+ and ` -l ` the name of this library (without its conventional ` lib ` prefix).
10461049
10471050For example: ` -I lib/libarom/include -L lib/libarom -l arom `
10481051
@@ -1052,11 +1055,11 @@ For example: `-I lib/libarom/include -L lib/libarom -l arom`
10521055# UTENSILS #
10531056# ------------------------------------------------#
10541057# RM force remove
1055- # MAKE quietly make
1058+ # MAKEFLAGS make flags
10561059# DIR_DUP duplicate directory tree
10571060
10581061RM := rm -f
1059- MAKE := $( MAKE ) --silent --no-print-directory
1062+ MAKEFLAGS += --silent --no-print-directory
10601063DIR_DUP = mkdir -p $(@D )
10611064
10621065# ------------------------------------------------#
@@ -1101,6 +1104,11 @@ re:
11011104 $(MAKE) all
11021105```
11031106
1107+ - ** Linking with a library** requires special attention to the order of the
1108+ linking flags. In our case we need to make sure that ` $(LDFLAGS) ` and
1109+ ` $(LDLIBS) ` passes respectively before and after the ` $(OBJS) ` in the linking
1110+ recipe.
1111+
11041112- ` $(LIBS_TARGET) ` rule ** builds each of the required libraries** found in the
11051113 ` INGREDIENTS ` part. It is a ` $(NAME) ` prerequisite for the same reason as
11061114 ` $(OBJS) ` because our * final goal* needs the libraries as well as the objects
0 commit comments