-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathspecial_variables.html
More file actions
1141 lines (697 loc) · 45.2 KB
/
special_variables.html
File metadata and controls
1141 lines (697 loc) · 45.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html lang="ko" >
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-161001174-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-161001174-4');
</script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Special Variables | Introduction</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="">
<meta name="generator" content="GitBook 2.6.7">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/plugins/gitbook-plugin-fontsettings/website.css">
<link rel="next" href="./directives.html" />
<link rel="prev" href="./substitution_references.html" />
</head>
<body>
<div class="book"
data-level="3"
data-chapter-title="Special Variables"
data-filepath="special_variables.md"
data-basepath="."
data-innerlanguage="">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="0" data-path="index.html">
<a href="./index.html">
<i class="fa fa-check"></i>
Introduction
</a>
</li>
<li class="chapter " data-level="1" data-path="bug_reports.html">
<a href="./bug_reports.html">
<i class="fa fa-check"></i>
<b>1.</b>
Bug reports
</a>
</li>
<li class="chapter " data-level="2" data-path="variables_and_functions.html">
<a href="./variables_and_functions.html">
<i class="fa fa-check"></i>
<b>2.</b>
Variables and Functions
</a>
<ul class="articles">
<li class="chapter " data-level="2.1" data-path="multiline_variables.html">
<a href="./multiline_variables.html">
<i class="fa fa-check"></i>
<b>2.1.</b>
Multi-Line Variables
</a>
</li>
<li class="chapter " data-level="2.2" data-path="target_specific_variables.html">
<a href="./target_specific_variables.html">
<i class="fa fa-check"></i>
<b>2.2.</b>
Target-Specific Variables
</a>
</li>
<li class="chapter " data-level="2.3" data-path="automatic_variables.html">
<a href="./automatic_variables.html">
<i class="fa fa-check"></i>
<b>2.3.</b>
Automatic Variables
</a>
</li>
<li class="chapter " data-level="2.4" data-path="substitution_references.html">
<a href="./substitution_references.html">
<i class="fa fa-check"></i>
<b>2.4.</b>
Substitution References
</a>
</li>
</ul>
</li>
<li class="chapter active" data-level="3" data-path="special_variables.html">
<a href="./special_variables.html">
<i class="fa fa-check"></i>
<b>3.</b>
Special Variables
</a>
</li>
<li class="chapter " data-level="4" data-path="directives.html">
<a href="./directives.html">
<i class="fa fa-check"></i>
<b>4.</b>
Directives
</a>
<ul class="articles">
<li class="chapter " data-level="4.1" data-path="conditional_directives.html">
<a href="./conditional_directives.html">
<i class="fa fa-check"></i>
<b>4.1.</b>
Conditional Directives
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="5" data-path="rules.html">
<a href="./rules.html">
<i class="fa fa-check"></i>
<b>5.</b>
Rules
</a>
<ul class="articles">
<li class="chapter " data-level="5.1" data-path="double_colon_rules.html">
<a href="./double_colon_rules.html">
<i class="fa fa-check"></i>
<b>5.1.</b>
Double-Colon Rules
</a>
</li>
<li class="chapter " data-level="5.2" data-path="pattern_rules.html">
<a href="./pattern_rules.html">
<i class="fa fa-check"></i>
<b>5.2.</b>
Pattern Rules
</a>
</li>
<li class="chapter " data-level="5.3" data-path="static_pattern_rules.html">
<a href="./static_pattern_rules.html">
<i class="fa fa-check"></i>
<b>5.3.</b>
Static Pattern Rules
</a>
</li>
<li class="chapter " data-level="5.4" data-path="recipes.html">
<a href="./recipes.html">
<i class="fa fa-check"></i>
<b>5.4.</b>
Recipes
</a>
</li>
<li class="chapter " data-level="5.5" data-path="DAG.html">
<a href="./DAG.html">
<i class="fa fa-check"></i>
<b>5.5.</b>
DAG
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="6" data-path="special_targets.html">
<a href="./special_targets.html">
<i class="fa fa-check"></i>
<b>6.</b>
Special Targets
</a>
</li>
<li class="chapter " data-level="7" data-path="recursive_make.html">
<a href="./recursive_make.html">
<i class="fa fa-check"></i>
<b>7.</b>
Recursive Make
</a>
</li>
<li class="chapter " data-level="8" data-path="include.html">
<a href="./include.html">
<i class="fa fa-check"></i>
<b>8.</b>
Include
</a>
</li>
<li class="chapter " data-level="9" data-path="one_DAG.html">
<a href="./one_DAG.html">
<i class="fa fa-check"></i>
<b>9.</b>
One DAG
</a>
</li>
<li class="chapter " data-level="10" data-path="parallel_execution.html">
<a href="./parallel_execution.html">
<i class="fa fa-check"></i>
<b>10.</b>
Parallel Execution
</a>
</li>
<li class="chapter " data-level="11" data-path="builtin_functions.html">
<a href="./builtin_functions.html">
<i class="fa fa-check"></i>
<b>11.</b>
Built-in Functions
</a>
<ul class="articles">
<li class="chapter " data-level="11.1" data-path="builtin_functions/text_functions.html">
<a href="./builtin_functions/text_functions.html">
<i class="fa fa-check"></i>
<b>11.1.</b>
Text Functions
</a>
</li>
<li class="chapter " data-level="11.2" data-path="builtin_functions/file_name_functions.html">
<a href="./builtin_functions/file_name_functions.html">
<i class="fa fa-check"></i>
<b>11.2.</b>
File Name Functions
</a>
</li>
<li class="chapter " data-level="11.3" data-path="builtin_functions/conditional_functions.html">
<a href="./builtin_functions/conditional_functions.html">
<i class="fa fa-check"></i>
<b>11.3.</b>
Conditional Functions
</a>
</li>
<li class="chapter " data-level="11.4" data-path="builtin_functions/foreach_function.html">
<a href="./builtin_functions/foreach_function.html">
<i class="fa fa-check"></i>
<b>11.4.</b>
Foreach Function
</a>
</li>
<li class="chapter " data-level="11.5" data-path="builtin_functions/file_function.html">
<a href="./builtin_functions/file_function.html">
<i class="fa fa-check"></i>
<b>11.5.</b>
File Function
</a>
</li>
<li class="chapter " data-level="11.6" data-path="builtin_functions/call_function.html">
<a href="./builtin_functions/call_function.html">
<i class="fa fa-check"></i>
<b>11.6.</b>
Call Function
</a>
</li>
<li class="chapter " data-level="11.7" data-path="builtin_functions/eval_function.html">
<a href="./builtin_functions/eval_function.html">
<i class="fa fa-check"></i>
<b>11.7.</b>
Eval Function
</a>
</li>
<li class="chapter " data-level="11.8" data-path="builtin_functions/value_function.html">
<a href="./builtin_functions/value_function.html">
<i class="fa fa-check"></i>
<b>11.8.</b>
Value Function
</a>
</li>
<li class="chapter " data-level="11.9" data-path="builtin_functions/origin_function.html">
<a href="./builtin_functions/origin_function.html">
<i class="fa fa-check"></i>
<b>11.9.</b>
Origin Function
</a>
</li>
<li class="chapter " data-level="11.10" data-path="builtin_functions/flavor_function.html">
<a href="./builtin_functions/flavor_function.html">
<i class="fa fa-check"></i>
<b>11.10.</b>
Flavor Function
</a>
</li>
<li class="chapter " data-level="11.11" data-path="builtin_functions/make_control_functions.html">
<a href="./builtin_functions/make_control_functions.html">
<i class="fa fa-check"></i>
<b>11.11.</b>
Make Control Functions
</a>
</li>
<li class="chapter " data-level="11.12" data-path="builtin_functions/shell_function.html">
<a href="./builtin_functions/shell_function.html">
<i class="fa fa-check"></i>
<b>11.12.</b>
Shell Function
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="12" data-path="command_line_options.html">
<a href="./command_line_options.html">
<i class="fa fa-check"></i>
<b>12.</b>
Command-line Options
</a>
</li>
<li class="chapter " data-level="13" data-path="debugging.html">
<a href="./debugging.html">
<i class="fa fa-check"></i>
<b>13.</b>
Debugging
</a>
</li>
<li class="chapter " data-level="14" data-path="tips.html">
<a href="./tips.html">
<i class="fa fa-check"></i>
<b>14.</b>
Tips
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Actions Left -->
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="./" >Introduction</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<h1 id="special-variables">Special Variables</h1>
<h4 id="curdir">CURDIR</h4>
<p>make 실행시 현재 디렉토리 경로를 나타냅니다.</p>
<pre><code class="lang-makefile">$(info CURDIR : $(CURDIR))
<span class="hljs-comment"># recursive make 에서 CURDIR 값을 출력할 경우</span>
CURDIR : /home/mug896/make
make[1]: Entering directory '/home/mug896/make/dir1'
CURDIR : /home/mug896/make/dir1
make[1]: Leaving directory '/home/mug896/make/dir1'
</code></pre>
<h4 id="defaultgoal">.DEFAULT_GOAL</h4>
<p>make 명령 실행 시에 아무런 타겟 인수를 주지 않으면
기본적으로 makefile 작성시 제일 위에 위치한 explicit rule 이 실행됩니다.
만약에 이것을 변경하고 싶으면 <code>.DEFAULT_GOAL</code> 변수를 설정하면 됩니다.</p>
<pre><code class="lang-makefile"><span class="hljs-title">foo:</span>
@echo target: $@
<span class="hljs-title">bar:</span>
@echo target: $@
.DEFAULT_GOAL := bar <span class="hljs-comment"># foo 타겟 대신에 bar 타겟이 실행된다.</span>
<span class="hljs-comment">####### 실행 결과 #######</span>
target: bar
</code></pre>
<h4 id="includedirs">.INCLUDE_DIRS</h4>
<p><code>include</code> 지시자를 이용해 makefile 을 include 할때 파일명이 <code>/</code> 로 시작하지 않으면
현재 디렉토리로부터의 경로를 검색한 후 없을 경우 다음 순으로 디렉토리를 검색합니다.</p>
<ol>
<li>make 명령 라인에서 <code>-I</code> or <code>--include-dir</code> 옵션으로 지정한 디렉토리</li>
<li><code>.INCLUDE_DIRS</code> 변수에 있는 디렉토리</li>
</ol>
<pre><code class="lang-makefile">$(info $(.INCLUDE_DIRS))
/usr/include /usr/local/include /usr/include
</code></pre>
<p><a name="libpatterns"></a></p>
<h4 id="libpatterns">.LIBPATTERNS</h4>
<p>make 이 라이브러리 파일을 검색할 때 사용하는 파일 패턴입니다.
디폴트 값은 <code>lib%.so lib%.a</code> 이므로 만약에 prerequisites 으로 <code>-lm</code> 을 설정하였다면
<code>libm.so libm.a</code> 순으로 찾게 됩니다.</p>
<pre><code class="lang-makefile">$(info $(.LIBPATTERNS))
<span class="hljs-comment">###### 실행 결과 ######</span>
lib%.so lib%.a
</code></pre>
<h4 id="makecmdgoals">MAKECMDGOALS</h4>
<p>make 명령을 실행할 때 명령 라인에서 설정한 타겟 이름이 들어있는 변수입니다.
옵션이나 변수 정의는 포함되지 않습니다.
조건 지시자를 이용해 선택적으로 include 문을 실행시키거나 sub-make 실행시 인수를 전달때,
argument processing 등에 활용할 수 있습니다.</p>
<pre><code class="lang-makefile">
$(info $(MAKECMDGOALS))
<span class="hljs-comment">####### 실행 결과 #######</span>
<span class="hljs-comment"># -rR --keep-going 같은 옵션과 release=1 변수 정의는 포함되지 않는다.</span>
sh$ make -rR --keep-going foobar release=1
foobar
------------------------------------------------------------------
.DEFAULT_GOAL := all
foo : ;@echo 2222222222
all : ;@echo 1111111111
$(info $(MAKECMDGOALS))
<span class="hljs-comment">####### 실행 결과 #######</span>
sh$ make <span class="hljs-comment"># .DEFAULT_GOAL 값은 포함되지 않는다.</span>
1111111111
sh$ make all
all
1111111111
------------------------------------------------------------------
<span class="hljs-comment"># 실행할 타겟이 clean 일 경우 *.d 파일은 삭제되므로 include 할 필요가 없다.</span>
ifneq "$(MAKECMDGOALS)" "clean"
include $(OBJS:.o=.d)
endif
------------------------------------------------------------------
<span class="hljs-constant">TOPTARGETS</span> := all clean
<span class="hljs-constant">SUBDIRS</span> := <span class="hljs-variable">$(wildcard */)</span>
$(TOPTARGETS) : $(SUBDIRS)
$(SUBDIRS) :
$(MAKE) -C $@ $(MAKECMDGOALS) <span class="hljs-comment"># sub-make 실행시 인수를 전달할 때</span>
<span class="hljs-phony"><span class="hljs-keyword">.PHONY</span>: $(TOPTARGETS) $(SUBDIRS)</span>
</code></pre>
<h4 id="makefilelist">MAKEFILE_LIST</h4>
<p>make 명령에 의해 처리되는 makefile 의 목록이 저장되는 변수입니다.<br>include 지시자에 의해 makefile 파일이 include 될 때마다 변수에 추가 됩니다.</p>
<pre><code class="lang-makefile">$(info 1: $(MAKEFILE_LIST))
include inc1.mk
$(info 2: $(MAKEFILE_LIST))
include inc2.mk
$(info 3: $(MAKEFILE_LIST))
include inc3.mk
$(info 4: $(MAKEFILE_LIST))
<span class="hljs-comment">############# 실행 결과 #############</span>
1: Makefile <span class="hljs-comment"># top makefile</span>
2: Makefile inc1.mk
3: Makefile inc1.mk inc2.mk
4: Makefile inc1.mk inc2.mk inc3.mk
</code></pre>
<p><a name="makeflags"></a></p>
<h4 id="makeflags">MAKEFLAGS</h4>
<p>make 명령 실행시 명령 라인에서 사용한 옵션이 1 문자 플래그로 저장됩니다.
<code>--directory (-C)</code>, <code>--file (-f)</code>, <code>--old-file (-o)</code>, <code>--new-file (-W)</code>
옵션은 예외로 저장되지 않습니다.
기본적으로 변수가 export 되므로 sub-make 에도 적용됩니다.</p>
<pre><code class="lang-makefile">
$(info $(MAKEFLAGS))
<span class="hljs-comment">####### 실행 결과 #######</span>
sh$ make -k -s --no-builtin-rules --no-builtin-variables
krRs <span class="hljs-comment"># 1 문자 플래그로 저장된다.</span>
--------------------------------------------------------
<span class="hljs-comment"># 특정 옵션은 1 문자 플래그로 저장되지 않으므로 값을 체크할 때는 filter-out 함수를 사용합니다.</span>
sh$ make -k -s --no-print-directory --trace
ks --trace --no-print-directory
<span class="hljs-comment"># 먼저 '--' 로 시작하는 옵션을 제거</span>
ifeq "$(findstring s,$(filter-out --%,$(MAKEFLAGS)))" "s"
quiet = silent_
endif
--------------------------------------------------------
<span class="hljs-comment"># 만약에 sub-make 에는 전달되지 않게 하려면 다음과 같이하면 됩니다.</span>
<span class="hljs-title">subsystem:</span>
$(MAKE) -C subdir MAKEFLAGS=
</code></pre>
<p>옵션을 명령 라인에서 설정하지 않고 Makefile 내에서 직접 설정해 사용할 수도 있습니다.<br>( 이때는 1 문자로 변경되지 않고 문자 그대로 저장됩니다. )</p>
<pre><code class="lang-makefile"><span class="hljs-constant">MAKEFLAGS</span> += -rR
</code></pre>
<p><a name="makelevel"></a></p>
<h4 id="makelevel">MAKELEVEL</h4>
<p>recursive make 에서 sub-make 의 depth 정도를 나타냅니다.
top makefile 에서는 0 이 되고
첫 번째 sub-make 에서는 1 이 되는데 여기서 또 sub-make 이 실행되면 2 가 됩니다.</p>
<pre><code class="lang-makefile"><span class="hljs-comment"># '[1]' 안의 숫자는 MAKELEVEL 을 나타냄</span>
make[1]: Entering directory '/home/mug896/tmp/foo'
. . .
make[2]: Entering directory '/home/mug896/tmp/foo/bar'
. . .
make[2]: Leaving directory '/home/mug896/tmp/foo/bar'
. . .
make[1]: Leaving directory '/home/mug896/tmp/foo'
</code></pre>
<p><a name="makeoverrides"></a></p>
<h4 id="makeoverrides">MAKEOVERRIDES</h4>
<p>make 명령 라인에서 설정한 변수값은 기본적으로 makefile 에서 설정한 변수값에 우선해서 사용되는데
MAKEOVERRIDES 변수는 이와 같은 기능이 sub-make 에도 동일하게 적용되게 합니다.
따라서 만약에 sub-make 에서는 명령 라인에서 설정한 변수값이 사용되지 않게 하려면
다음과 같이 하면 됩니다.</p>
<pre><code class="lang-makefile"><span class="hljs-constant">MAKEOVERRIDES</span> =
<span class="hljs-comment"># 이 변수는 다음과 같이 사용할 수는 없습니다.</span>
foo : foo :
@$(MAKE) -C subdir @$(MAKE) -C subdir MAKEOVERRIDES=
</code></pre>
<h4 id="makerestarts">MAKE_RESTARTS</h4>
<p><a href="include.html">remake</a> 에의해 make 이 재실행될 경우 값이 설정됩니다.</p>
<pre><code class="lang-makefile">ifdef MAKE_RESTARTS
$(info defined !!!)
else
$(info not defined)
endif
$(info top MAKE_RESTARTS: $(MAKE_RESTARTS))
include mod_1.mk
mod_1.mk :
@echo '$$(info $@ MAKE_RESTARTS: $$(MAKE_RESTARTS))' > $@
@echo include mod_2.mk >> $@
mod_2.mk :
@echo '$$(info $@ MAKE_RESTARTS: $$(MAKE_RESTARTS))' > $@
$(info --------------------------- )
<span class="hljs-comment">################ 실행 결과 ###############</span>
sh$ ls <span class="hljs-comment"># 현재 include 파일은 존재하지 않는 상태.</span>
Makefile
sh$ make <span class="hljs-comment"># remake 에의해 make 이 3 번 실행된다.</span>
not defined <span class="hljs-comment"># 첫 번째 실행</span>
top MAKE_RESTARTS:
---------------------------
defined !!! <span class="hljs-comment"># 두 번째 실행</span>
top MAKE_RESTARTS: 1
mod_1.mk MAKE_RESTARTS: 1
---------------------------
defined !!! <span class="hljs-comment"># 세 번째 실행</span>
top MAKE_RESTARTS: 2
mod_1.mk MAKE_RESTARTS: 2
mod_2.mk MAKE_RESTARTS: 2
---------------------------
sh$ ls <span class="hljs-comment"># remake 에의해 include 파일이 새로 생성됨.</span>
Makefile mod_1.mk mod_2.mk
sh$ make <span class="hljs-comment"># include 파일이 존재하므로 다시 remake 이 발생하지 않는다.</span>
not defined
top MAKE_RESTARTS:
mod_1.mk MAKE_RESTARTS:
mod_2.mk MAKE_RESTARTS:
---------------------------
</code></pre>
<p><a name="make_term"></a></p>
<h4 id="maketermout--maketermerr">MAKE_TERMOUT , MAKE_TERMERR</h4>
<p>make 명령 실행시 <code>stdout</code>, <code>stderr</code> 가 터미널에 연결되어 있는지 아닌지
이 변수를 통해서 알 수 있습니다.
터미널에 연결되어 있지 않으면 empty 가 반환됩니다.</p>
<blockquote>
<p>이 변수는 make 4.1 버전에서 추가된 변수 입니다.</p>
</blockquote>
<pre><code class="lang-makefile">$(warning stdout: $(MAKE_TERMOUT)) <span class="hljs-comment"># stderr 로 출력하기 위해 warning 함수를 사용</span>
$(warning stderr: $(MAKE_TERMERR))
$(if $(MAKE_TERMOUT),,$(warning stdout is not terminal))
<span class="hljs-comment">############ 실행 결과 ############</span>
sh$ make
Makefile:1: stdout: /dev/pts/7
Makefile:2: stderr: /dev/pts/7
sh$ make | cat <span class="hljs-comment"># stdout 이 터미널이 아닌 파이프에 연결되어 있으므로</span>
Makefile:1: stdout: <span class="hljs-comment"># 변수 $(MAKE_TERMOUT) 값은 empty 이다.</span>
Makefile:2: stderr: /dev/pts/7
Makefile:4: stdout is not terminal
</code></pre>
<h4 id="makeversion">MAKE_VERSION</h4>
<p>make 버전 넘버</p>
<pre><code>$(info $(MAKE_VERSION))
결과: 4.1
</code></pre><h4 id="recipeprefix">.RECIPEPREFIX</h4>
<p>기본적으로 recipe 라인의 시작을 알리는 문자는 <code>tab</code> 문자인데
변경하고 싶으면 이 변수를 설정하면 됩니다.
global 영역에서 순서에 따라 여러번 변경해 사용할 수 있으나 target-specific 변수로는
사용할 수 없습니다.</p>
<pre><code class="lang-sh">.RECIPEPREFIX := > <span class="hljs-comment"># foo 룰에는 '>' 문자를 사용</span>
foo: bar
> @<span class="hljs-built_in">echo</span> fooooo
.RECIPEPREFIX := ! <span class="hljs-comment"># bar 룰에는 '!' 문자를 사용</span>
bar:
! @<span class="hljs-built_in">echo</span> barrrr
<span class="hljs-comment">#### 실행 결과 ####</span>
fooooo
barrrr
</code></pre>
<p><a name="shell"></a></p>
<h4 id="shell">SHELL</h4>
<p>SHELL 변수를 이용하면 recipe 실행시 사용되는 shell 프로그램을 변경할 수 있습니다.
global 영역에서 설정하면 모든 rule 에 적용되고
target-specific 변수로도 사용할 수 있습니다.</p>
<pre><code class="lang-makefile">foo : bar foo : bar
@cat <( echo $@ : $$0 ) @<span class="hljs-comment">#cat <( echo $@ : $$0 )</span>
@echo $@ : $$0
bar :
@cat <( echo $@ : $$0 ) bar : SHELL := /bin/bash
bar :
<span class="hljs-constant">SHELL</span> := /bin/bash @cat <( echo $@ : $$0 )
<span class="hljs-comment">###### 실행 결과 ###### ###### 실행 결과 ######</span>
bar : /bin/bash bar : /bin/bash
foo : /bin/bash foo : /bin/sh
</code></pre>
<p><a name="shellflags"></a></p>
<h4 id="shellflags">.SHELLFLAGS</h4>
<p>recipe 실행시 사용되는 shell 프로그램에 전달되는 옵션을 설정합니다.
.SHELLFLAGS 의 기본값은 <code>-c</code> 이므로 shell 이 실행될때 <code>sh -c</code> 형태로 실행됩니다.
옵션을 추가할 때는 <code>+=</code> 연산자를 사용해서 append 합니다.
SHELL 변수와 마찬가지로 target-specific 변수로도 사용이 가능합니다.</p>
<pre><code>foo : SHELL := /usr/bash
foo : .SHELLFLAGS += -e
foo :
command ....
</code></pre><h4 id="shellstatus">.SHELLSTATUS</h4>
<p><code>!=</code> 대입 연산자나 <code>$(shell ...)</code> 함수에 의해 shell 명령이 실행됐을 때
<code>sh -c</code> 의 종료 상태 값이 저장됩니다.</p>
<pre><code class="lang-makefile"><span class="hljs-constant">res</span> != date -@ 2> /dev/null # 'date -@' 는 오류를 위한 명령
$(info status : $(.SHELLSTATUS))
<span class="hljs-constant">res</span> != date -@ 2> /dev/null; date # 마지막 명령은 정상 종료
$(info status : $(.SHELLSTATUS))
$(info ----------)
<span class="hljs-constant">res</span> := <span class="hljs-variable">$(shell date -@ 2> /dev/null )</span>
$(info status : $(.SHELLSTATUS))
<span class="hljs-constant">res</span> := <span class="hljs-variable">$(shell date -@ 2> /dev/null; date )</span>