-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtarget_specific_variables.html
More file actions
970 lines (535 loc) · 40.3 KB
/
target_specific_variables.html
File metadata and controls
970 lines (535 loc) · 40.3 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
<!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>Target-Specific 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="./automatic_variables.html" />
<link rel="prev" href="./multiline_variables.html" />
</head>
<body>
<div class="book"
data-level="2.2"
data-chapter-title="Target-Specific Variables"
data-filepath="target_specific_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 active" 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 " 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="targetspecific-variables">Target-Specific Variables</h1>
<p>make 을 사용하는 분들 중에는 global 변수와 recipe 에서 사용되는 automatic 변수는
알고 있는데 특정 타겟과 관련해서 변수를 설정해 사용할 수 있는 것은 모르는 경우가 많습니다.
타겟 변수를 설정하면 이후에 실행되는 모든 recipe 에서 해당 변수값이 사용됩니다.</p>
<p>먼저 타겟 라인은 global 영역에서 대입 연산과 동일하게 작성 순서에따라 처리됩니다.
이것은 변수가 recursive 이던 simple 이던 상관없습니다.
다음을 보면 중간에 <code>BUILD_DIR</code> 값을 release 로 변경하면 이후에는 타겟 라인 변수값이
모두 release 로 변경되는 것을 볼 수 있습니다.</p>
<pre><code class="lang-makefile">all : debug/foo release/bar
<span class="hljs-constant">BUILD_DIR</span> = debug
$(BUILD_DIR)/foo : $(BUILD_DIR)/foo.o <span class="hljs-comment"># $(BUILD_DIR) 변수값은 debug 가 된다.</span>
@echo foo : $@ : $^
<span class="hljs-constant">BUILD_DIR</span> = release
$(BUILD_DIR)/bar : $(BUILD_DIR)/bar.o <span class="hljs-comment"># $(BUILD_DIR) 변수값은 release 가 된다.</span>
@echo bar : $@ : $^
.DEFAULT: ;
<span class="hljs-comment">############## 실행 결과 ###############</span>
foo : debug/foo : debug/foo.o
bar : release/bar : release/bar.o
</code></pre>
<p>타겟 변수는 global 변수를 override 해서 타겟 전용 변수로 사용할 수 있게 해줍니다.
타겟 변수는 타겟 라인의 prerequisites 부분에서 설정을 합니다.
다음 첫 번째 예제를 보면 bar 타겟의 변수 AA 의값은 global 변수와 동일하게 100 으로 나오지만
foo 타겟의 값은 타겟 변수 설정에 따라 200 이 되는 것을 볼 수 있습니다.
또한 타겟 변수는 prerequisites 에게 상속이 됩니다.
따라서 오른쪽 예제에서처럼 foo 타겟의 prerequisite 으로 bar 를 추가하면 bar 타겟의 AA 값도
200 으로 나오게 됩니다.</p>
<pre><code class="lang-makefile">all : foo bar all : foo
<span class="hljs-constant">AA</span> := 100 AA := 100
foo : AA := 200 foo : AA := 200 <span class="hljs-comment"># 타겟 변수</span>
foo : foo : bar <span class="hljs-comment"># bar prerequisite 추가</span>
@echo foo : $(AA) @echo foo : $(AA)
bar : bar :
@echo bar : $(AA) @echo bar : $(AA)
<span class="hljs-comment">######## 실행 결과 ####### ######## 실행 결과 #######</span>
foo : 200 foo : 200
bar : 100 bar : 200
</code></pre>
<p>타겟 변수값이 prerequisites 에게 상속되는 것은 변수값이 recipe 에서 사용될 때 입니다.
다음을 보면 bar 는 foo 의 prerequisite 이지만 bar 타겟 라인 변수 CC 가 설정될 때는
global 변수 AA 의 값이 적용됩니다.
반면에 recipe 에서 변수 AA 값이 사용될 때는 foo 로 부터 상속되어 200 이됩니다.</p>
<pre><code class="lang-makefile"><span class="hljs-constant">AA</span> := 100
foo : AA := 200
foo : BB := $(AA) <span class="hljs-comment"># foo 타겟 변수값이 사용되어 BB 값은 200 이 된다.</span>
foo : bar <span class="hljs-comment"># bar prerequisite 추가</span>
@echo foo : $(AA) $(BB) <span class="hljs-comment"># AA : 200, BB : 200</span>
bar : CC := $(AA) <span class="hljs-comment"># global 영역에서 타겟 라인이 처리될때 AA 값은 100 이된다.</span>
bar :
@echo bar : $(CC) $(AA) <span class="hljs-comment"># CC 는 100, AA 는 foo 로부터 상속되어 200 이 된다.</span>
<span class="hljs-comment">######### 실행 결과 #########</span>
bar : 100 200
foo : 200 200
</code></pre>
<h4 id="recipe-는-global-영역-처리가-완료된-후에-실행된다">recipe 는 global 영역 처리가 완료된 후에 실행된다.</h4>
<p>따라서 recipe 가 실행될 때는 global 영역에서 마지막으로 설정된 변수값이 사용됩니다.</p>
<pre><code class="lang-makefile"><span class="hljs-constant">CFLAGS</span> := aaaaaa
foo :
@echo foo : $(CFLAGS)
<span class="hljs-constant">CFLAGS</span> := bbbbbb
bar :
@echo bar : $(CFLAGS)
<span class="hljs-comment">######## 실행 결과 ########</span>
foo : bbbbbb
</code></pre>
<h4 id="타겟-변수는-global-영역과-별도의-flavor-를-갖는다">타겟 변수는 global 영역과 별도의 flavor 를 갖는다.</h4>
<p>이것은 타겟 변수를 사용할 때 주의해야 될 사항입니다.
global 영역에 동일한 이름의 변수가 존재하더라도 타겟 변수에서는
별도의 <a href="builtin_functions/flavor_function.html">flavor</a> 를 갖습니다.
다음 두 예제를 보면 CFLAGS 변수가 처음에는 둘 다 simple 변수로 초기화되어 있는데
왼쪽은 예상대로 foo 값으로 100 이 출력되지만 <code>+=</code> 연산자를 사용하는 오른쪽은 bbbbbb 와함께 200 이
출력되는 것을 볼 수 있습니다.
이것은 CFLAGS 변수가 global 설정과 달리 처음 변수에 <code>+=</code> 연산자를 사용할때 처럼 recusive 변수가 된다는 의미인데요.
만약에 위쪽의 주석 처리한 라인의 주석을 해제하여 simple 변수로 만들면 동일하게 값으로 100 이 출력되는 것을 볼 수 있습니다.</p>
<pre><code class="lang-makefile"><span class="hljs-constant">CFLAGS</span> := aaaaaa CFLAGS := aaaaaa
<span class="hljs-constant">AA</span> := 100 AA := 100
foo : CFLAGS := $(AA) <span class="hljs-comment"># foo : CFLAGS := </span>
foo : foo : CFLAGS += $(AA)$(info $(flavor CFLAGS))
@echo foo : $(CFLAGS) foo :
@echo foo : $(CFLAGS)
<span class="hljs-constant">CFLAGS</span> := bbbbbb
<span class="hljs-constant">AA</span> := 200 CFLAGS := bbbbbb
AA := 200
bar :
@echo bar : $(CFLAGS) bar :
@echo bar : $(CFLAGS)
<span class="hljs-comment">######## 실행 결과 ######## ######## 실행 결과 ########</span>
foo : 100 recursive
foo : bbbbbb 200
</code></pre>
<h3 id="variable-scopes">Variable scopes</h3>
<p>make 에서 사용되는 variable scopes 에는 실질적으로 3 가지 종류가 있는 것과 같습니다.<br>( foreach 함수에서 사용되는 함수 scope 은 제외했습니다. )</p>
<ol>
<li>global 변수</li>
<li>target ( pattern, static pattern ) specific 변수</li>
<li>recipe 실행시 설정되는 automatic 변수</li>
</ol>
<p>다음 예제에서 <code>LDFLAGS</code>, <code>LDLIBS</code> 변수는 global 변수가 되고,
debug, release 타겟 라인에서 설정한 <code>CFLAGS</code>, <code>CPPFLAGS</code> 변수는 target specific 변수가 됩니다.
recipe 에서 shell 명령을 작성할 때 사용된 <code>$@</code> 변수는 automatic 변수입니다.
실행 결과를 보면 각각의 타겟 라인에서 설정한 변수값들이 적용되는 것을 볼 수 있습니다.</p>
<pre><code class="lang-makefile"><span class="hljs-constant">LDFLAGS</span> := -L/usr/local/lib # global 변수
<span class="hljs-constant">LDLIBS</span> := -lzoo
debug : CFLAGS := -g <span class="hljs-comment"># target-specific 변수</span>
debug : CPPFLAGS := -DDEBUG
release : CFLAGS := -O2 <span class="hljs-comment"># target-specific 변수</span>
release : CPPFLAGS := -DNDEBUG
debug release : foo.o bar.o
@echo $@ : $(LDFLAGS) $(LDLIBS) <span class="hljs-comment"># '$@' 는 automatic 변수</span>
%.o :
@echo $@ : $(CFLAGS) $(CPPFLAGS)
<span class="hljs-comment">########### 실행 결과 ############</span>
sh$ make debug
foo.o : -g -DDEBUG
bar.o : -g -DDEBUG
debug : -L/usr/local/lib -lzoo
sh$ make release
foo.o : -O2 -DNDEBUG
bar.o : -O2 -DNDEBUG
release : -L/usr/local/lib -lzoo
</code></pre>
<h4 id="makefile-이-처리되는-순서">makefile 이 처리되는 순서</h4>
<p>다음은 makefile 실행시 처리되는 순서를 info 함수를 이용해 조회해본 것입니다.
출력 결과를 보면 111 ~ 777 까지 순서대로 출력이 되고 마지막으로 recipe 가 실행되는 것을 볼 수 있습니다.
따라서 변수를 이용해 타겟 라인 값을 설정할 경우에는 변수 정의가 뒤에 오지
않도록 주의해야 합니다.
다음 오른쪽 예제를 보면 foo 타겟의 prerequisite 을 설정할 때 DEP 변수를 사용하고 있는데
변수 정의가 뒷부분에 위치하여 정상적으로 설정이 되지 않고 있습니다.</p>
<pre><code class="lang-makefile">$(info 11111) $(info 11111)
<span class="hljs-constant">DEP</span> := bar foo : <span class="hljs-variable">$(DEP)</span> <span class="hljs-variable">$(info 22222)</span>
foo $(info 33333) : $(info 44444)
foo : $(DEP) $(info 22222) $(info AAAAA)
foo $(info 33333) : $(info 44444) @echo target foo
$(info AAAAA)
@echo target foo bar $(info 55555) : $(info 66666)
$(info BBBBB)
bar $(info 55555) : $(info 66666) @echo target bar
$(info BBBBB)
@echo target bar $(info 77777)
$(info 77777) DEP := bar <----- 끝으로 이동
<span class="hljs-comment">########## 실행 결과 ########## ########## 실행 결과 ##########</span>
11111 11111
22222 22222
33333 33333
44444 44444
55555 55555
66666 66666
77777 77777
BBBBB AAAAA <span class="hljs-comment"># bar 타겟 등록이 안된다.</span>
target bar target foo
AAAAA
target foo
</code></pre>
<h4 id="변수값-설정이-중복될-경우-마지막-값이-사용된다">변수값 설정이 중복될 경우 마지막 값이 사용된다.</h4>
<p>global 영역에서 마지막으로 설정된 값이 recipe 에서 사용됩니다.</p>
<pre><code class="lang-makefile">foo.o bar.o : foo.o bar.o :
@echo $@ : $(CFLAGS) @echo $@ : $(CFLAGS)
foo.o bar.o : CFLAGS := -g bar.o : CFLAGS := -O2
bar.o : CFLAGS := -O2 foo.o bar.o : CFLAGS := -g
<span class="hljs-comment">####### 실행 결과 ####### ####### 실행 결과 #######</span>
sh$ make foo.o sh$ make foo.o
foo.o : -g foo.o : -g
sh$ make bar.o sh$ make bar.o
bar.o : -O2 bar.o : -g
</code></pre>
<p><a name="private"></a></p>
<h4 id="private-지시자">private 지시자</h4>
<p>아래 예제의 <code>foo : bar</code> 룰 정의에서 foo 는 상위 타겟이 되고 prerequisite 에 해당하는
bar 는 하위 타겟이 됩니다.
상위 타겟에서 설정한 변수는 하위 타겟에 상속되기 때문에 bar 에서도 사용할 수가 있는데요.
만약에 foo 타겟 전용으로 변수를 사용하고 하위 타겟으로는 상속되지 않게 하려면
<code>private</code> 지시자를 사용하면 됩니다.</p>
<blockquote>
<p>private 지시자는 GNU make 3.82 버전에서 추가된 기능입니다.</p>
</blockquote>
<pre><code class="lang-makefile"><span class="hljs-comment"># foo 타겟에서 private 지시자를 사용하여 하위 타겟에 상속되지 않아 </span>
<span class="hljs-comment"># bar 타겟 에서는 global 변수값이 사용된다.</span>
<span class="hljs-constant">AA</span> := 100
foo : private AA := 200
foo : bar
@echo foo $(AA)
bar :
@echo bar $(AA)
<span class="hljs-comment">###### 실행 결과 ###### </span>
bar 100
foo 200
</code></pre>
</section>
</div>
</div>
</div>
<a href="./multiline_variables.html" class="navigation navigation-prev " aria-label="Previous page: Multi-Line Variables"><i class="fa fa-angle-left"></i></a>
<a href="./automatic_variables.html" class="navigation navigation-next " aria-label="Next page: Automatic Variables"><i class="fa fa-angle-right"></i></a>
</div>
</div>
<script src="gitbook/app.js"></script>
<script src="gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
<script src="gitbook/plugins/gitbook-plugin-search/search.js"></script>
<script src="gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
<script src="gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
<script>
require(["gitbook"], function(gitbook) {
var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
gitbook.start(config);
});
</script>
</body>
</html>