@@ -131,7 +131,7 @@ used for **all the other lines**.
131
131
132
132
About the ** equal signs** :
133
133
134
- - ` := ` ** simply expand** the defined variable (like C equal sign ).
134
+ - ` := ` ** simply expand** the defined variable (like C ` = ` ).
135
135
- ` = ` ** recursively expand** the defined variable (the expression is expanded
136
136
afterward, when (and each time) the variable is used).
137
137
163
163
[ ** Version 1 / Simplest C project** ] ( #version-1 )
164
164
165
165
> - 42 C coding style conventions
166
- > - ` MAKE ` predefined variable
166
+ > - builtin variables
167
167
> - The C compilation implicit rule
168
168
> - pattern rule contains ` % ` character
169
169
> - Automatic variables in practice
202
202
> - ` addprefix ` make function
203
203
> - flags and libraries used by the linker
204
204
> - ` dir ` function
205
- > - Compiling with a library recap
205
+ > - Build with a library
206
+ > - Linking with a library
206
207
> - builds each of the required libraries
207
208
> - call rules recursively
208
209
@@ -231,7 +232,7 @@ The simplest, build a program called `icecream` with the following structure:
231
232
### v1 Brief
232
233
233
234
- 42 C coding style conventions
234
- - ` MAKE ` predefined variable
235
+ - builtin variables
235
236
- The C compilation implicit rule
236
237
- pattern rule contains ` % ` character
237
238
- Automatic variables in practice
@@ -266,9 +267,10 @@ CFLAGS := -Wall -Wextra -Werror
266
267
# UTENSILS #
267
268
# ------------------------------------------------#
268
269
# RM force remove
270
+ # MAKEFLAGS make flags
269
271
270
272
RM := rm -f
271
- MAKE := $( MAKE ) --no-print-directory
273
+ MAKEFLAGS += --no-print-directory
272
274
273
275
# ------------------------------------------------#
274
276
# RECIPES #
@@ -303,20 +305,23 @@ re:
303
305
# ###################################### END_1 ####
304
306
```
305
307
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).
311
313
312
314
<sub ><sub ><hr ></sub ></sub >
313
315
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.
320
325
321
326
<sub ><sub ><hr ></sub ></sub >
322
327
@@ -331,8 +336,8 @@ Where `%.o` expands to each objects, `%.c` to each sources, `$@` to the first
331
336
target (which is ` %.o ` ) and ` $< ` to the leftmost prerequisite (which is ` %.c ` ).
332
337
333
338
* 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.*
336
341
337
342
<sub ><sub ><hr ></sub ></sub >
338
343
@@ -485,10 +490,10 @@ CPPFLAGS := -I .
485
490
# UTENSILS #
486
491
# ------------------------------------------------#
487
492
# RM force remove
488
- # MAKE quietly make
493
+ # MAKEFLAGS make flags
489
494
490
495
RM := rm -f
491
- MAKE := $( MAKE ) --no-print-directory
496
+ MAKEFLAGS += --no-print-directory
492
497
493
498
# ------------------------------------------------#
494
499
# RECIPES #
@@ -650,11 +655,11 @@ CPPFLAGS := -I include
650
655
# UTENSILS #
651
656
# ------------------------------------------------#
652
657
# RM force remove
653
- # MAKE quietly make
658
+ # MAKEFLAGS make flags
654
659
# DIR_DUP duplicate directory tree
655
660
656
661
RM := rm -f
657
- MAKE := $( MAKE ) --no-print-directory
662
+ MAKEFLAGS += --no-print-directory
658
663
DIR_DUP = mkdir -p $(@D )
659
664
```
660
665
@@ -832,11 +837,11 @@ main.o: main.c main.o: main.c icecream.h
832
837
# UTENSILS #
833
838
# ------------------------------------------------#
834
839
# RM force remove
835
- # MAKE quietly make
840
+ # MAKEFLAGS make flags
836
841
# DIR_DUP duplicate directory tree
837
842
838
843
RM := rm -f
839
- MAKE := $( MAKE ) --no-print-directory
844
+ MAKEFLAGS += --no-print-directory
840
845
DIR_DUP = mkdir -p $(@D )
841
846
842
847
# ------------------------------------------------#
@@ -954,7 +959,8 @@ Builds an `icecream` **program that uses** `libbase` and `libarom`
954
959
- ` addprefix ` make function
955
960
- flags and libraries used by the linker
956
961
- ` dir ` function
957
- - Compiling with a library recap
962
+ - Build with a library
963
+ - Linking with a library
958
964
- builds each of the required libraries
959
965
- call rules recursively
960
966
@@ -1026,8 +1032,8 @@ LDLIBS := $(addprefix -l,$(LIBS))
1026
1032
1027
1033
<sub ><sub ><hr ></sub ></sub >
1028
1034
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.
1031
1037
1032
1038
<sub ><sub ><hr ></sub ></sub >
1033
1039
@@ -1037,12 +1043,9 @@ LDLIBS := $(addprefix -l,$(LIBS))
1037
1043
1038
1044
<sub ><sub ><hr ></sub ></sub >
1039
1045
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).
1046
1049
1047
1050
For example: ` -I lib/libarom/include -L lib/libarom -l arom `
1048
1051
@@ -1052,11 +1055,11 @@ For example: `-I lib/libarom/include -L lib/libarom -l arom`
1052
1055
# UTENSILS #
1053
1056
# ------------------------------------------------#
1054
1057
# RM force remove
1055
- # MAKE quietly make
1058
+ # MAKEFLAGS make flags
1056
1059
# DIR_DUP duplicate directory tree
1057
1060
1058
1061
RM := rm -f
1059
- MAKE := $( MAKE ) --silent --no-print-directory
1062
+ MAKEFLAGS += --silent --no-print-directory
1060
1063
DIR_DUP = mkdir -p $(@D )
1061
1064
1062
1065
# ------------------------------------------------#
@@ -1101,6 +1104,11 @@ re:
1101
1104
$(MAKE) all
1102
1105
```
1103
1106
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
+
1104
1112
- ` $(LIBS_TARGET) ` rule ** builds each of the required libraries** found in the
1105
1113
` INGREDIENTS ` part. It is a ` $(NAME) ` prerequisite for the same reason as
1106
1114
` $(OBJS) ` because our * final goal* needs the libraries as well as the objects
0 commit comments