-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile.rules
1462 lines (1169 loc) · 53.7 KB
/
Makefile.rules
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
# Makefile.rules - OCERA make framework common project rules -*- makefile-gmake -*- #OMK:base.omk
#
# (C) Copyright 2003, 2006, 2007, 2008, 2009 by Pavel Pisa - OCERA team member
# (C) Copyright 2006, 2007, 2008, 2009, 2010, 2011 by Michal Sojka - Czech Technical University, FEE, DCE
#
# Homepage: http://rtime.felk.cvut.cz/omk/
# Version: 0.2-111-g8f9236e
#
# The OMK build system is distributed under the GNU General Public
# License. See file COPYING for details.
#
#
# Version for Linux/RTLinux builds. #OMK:linux.omk
#
#
# input variables #OMK:base.omk
# V .. if set to 1, full command text is shown else short form is used
# W .. whole tree - if set to 1, make is always called from the top-level directory
# SUBDIRS .. list of subdirectories intended for make from actual directory
# default_CONFIG .. list of default config assignments CONFIG_XXX=y/n ...
# wvtest_SCRIPTS .. list of scripts producing wvtest output #OMK:wvtest.omk
# wvtest_PROGRAMS .. list of the testing programs producing wvtest output
# LN_HEADERS .. if "y", header files are symbolicaly linked instead of copied. #OMK:include.omk
# input variables #OMK:linux.omk
# lib_LIBRARIES .. list of the user-space libraries
# shared_LIBRARIES .. list of the user-space shared libraries
# kernel_LIBRARIES .. list of the kernel-space libraries
# rtlinux_LIBRARIES.. list of the RT-Linux kernel-space libraries
# include_HEADERS .. list of the user-space public header files
# nobase_include_HEADERS .. public headers copied even with directory part
# renamed_include_HEADERS .. public headers copied to the different target name
# kernel_HEADERS .. list of the kernel-space public header files
# rtlinux_HEADERS .. list of the RT-Linux kernel-space public header files
# bin_PROGRAMS .. list of the require binary programs
# utils_PROGRAMS .. list of the development utility programs
# test_PROGRAMS .. list of the testing programs
# bin_SCRIPTS .. list of scripts to be copied to _compiled/bin
# kernel_MODULES .. list of the kernel side modules/applications
# rtlinux_MODULES .. list of RT-Linux the kernel side modules/applications
# xxx_SOURCES .. list of specific target sources
# xxx_LIBS .. list of specific target libraries (-l prefix is automatically added)
# xxx_LDFLAGS .. list of specific target LDFLAGS
# lib_LOADLIBES .. list of libraries linked to each executable
# INCLUDES .. additional include directories and defines for user-space
# kernel_INCLUDES .. additional include directories and defines for kernel-space
# rtlinux_INCLUDES .. additional include directories and defines for RT-Linux
# OMIT_KERNEL_PASSES if defined, all kernel passes are omited
#
# LINUX_DIR .. location of Linux kernel sources
# RTL_DIR .. location of RT-Linux sources
# CFLAGS .. C compiler flags
# CXXFLAGS .. C++ compiler flags
# CPPFLAGS .. C preprocessor flags
# LDFLAGS .. linker flags for programs linking
# LOCAL_CONFIG_H .. name of local config.h file generated from values #OMK:config_h.omk
# of options defined in the current directory
# config_include_HEADERS .. names of global config files (possibly
# with subdirectories)
# xxx_DEFINES .. list of config directives to be included in
# config header file of the name <somedir>/xxx.h
# DOXYGEN .. if non-empty, generated headers includes Doxygen's @file
# command, so it is possible to document config
# variables.
# QT_PROJECTS .. list of QT .pro file to use for compilation #OMK:qt.omk
# QT_SUBDIRS .. subdirectories where to build QT applications using qmake (depricated)
# QTDIR .. where QT resides
OMK_RULES_TYPE=linux #OMK:Makefile.rules.linux@
#OMK:[email protected]
# If we are not called by OMK leaf Makefile...
ifndef MAKERULES_DIR
MAKERULES_DIR := $(abspath $(dir $(filter %Makefile.rules,$(MAKEFILE_LIST))))
endif
# The $(SED4OMK) command for BSD based systems requires -E option to allow
# extended regular expressions
SED4OMK ?= sed
ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
SED4OMK := $(SED4OMK) -E
ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
SED4OMK := gsed
endif
ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
SED4OMK := gsed -E
endif
ifneq ($(shell ( echo A | $(SED4OMK) -n -e 's/A\|B/y/p' )),y)
$(error No SED program suitable for OMK found)
endif
endif
# OUTPUT_DIR is the place where _compiled, _build and possible other
# files/directories are created. By default is the same as
# $(MAKERULES_DIR).
ifndef OUTPUT_DIR
OUTPUT_DIR := $(MAKERULES_DIR)
endif
# We need to ensure definition of sources directory first
ifndef SOURCES_DIR
# Only shell built-in pwd understands -L
SOURCES_DIR := $(shell ( pwd -L ) )
INVOCATION_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
INVOCATION_DIR := $(INVOCATION_DIR:/%=%)
INVOCATION_DIR := $(INVOCATION_DIR:\\%=%)
endif
.PHONY: all default check-make-ver print-hints omkize
ifdef W
ifeq ("$(origin W)", "command line")
OMK_WHOLE_TREE:=$(W)
endif
endif
ifndef OMK_WHOLE_TREE
OMK_WHOLE_TREE:=0
endif
ifneq ($(OMK_WHOLE_TREE),1)
all: check-make-ver print-hints default
@echo "Compilation finished"
else
# Run make in the top-level directory
all:
@$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
endif
# omk-get-var target allows external scripts/programs to determine the
# values of OMK variables such as RELATIVE_DIR etc.
.PHONY: omk-get-var
omk-get-var:
@$(foreach var,$(VAR),echo $(var)=$($(var));)
#=========================
# Include the config file
ifndef CONFIG_FILE
CONFIG_FILE := $(OUTPUT_DIR)/config.omk
endif
$(CONFIG_FILE)-default:
$(MAKE) default-config
ifeq ($(MAKECMDGOALS),default-config)
export DEFAULT_CONFIG_PASS=1
endif
ifneq ($(DEFAULT_CONFIG_PASS),1)
include $(CONFIG_FILE)-default
endif
-include $(OUTPUT_DIR)/config.target
ifneq ($(wildcard $(CONFIG_FILE)),)
-include $(CONFIG_FILE)
endif
CONFIG_FILES ?= $(wildcard $(CONFIG_FILE)-default) $(wildcard $(OUTPUT_DIR)/config.target) $(wildcard $(CONFIG_FILE))
export SED4OMK SOURCES_DIR MAKERULES_DIR RELATIVE_DIR INVOCATION_DIR
export CONFIG_FILE CONFIG_FILES OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
# OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
# must to be serialized only in the toplevel make.
ifndef RELATIVE_DIR
RELATIVE_DIR := $(SOURCES_DIR:$(OUTPUT_DIR)%=%)
endif
#$(warning === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
#$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
#override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | $(SED4OMK) -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g' -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
#$(warning BACK2TOP_DIR = "$(BACK2TOP_DIR)")
#$(warning SOURCES_DIR = "$(SOURCES_DIR)")
#$(warning MAKERULES_DIR = "$(OUTPUT_DIR)")
#$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
# We have to use RELATIVE_PREFIX because of mingw
override RELATIVE_PREFIX := $(RELATIVE_DIR)/
override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
#vpath %.c $(SOURCES_DIR)
#vpath %.cc $(SOURCES_DIR)
#vpath %.cxx $(SOURCES_DIR)
# Define srcdir for Automake compatibility
srcdir = $(SOURCES_DIR)
# Defines for quiet compilation
ifdef V
ifeq ("$(origin V)", "command line")
OMK_VERBOSE = $(V)
endif
endif
ifndef OMK_VERBOSE
OMK_VERBOSE = 0
endif
ifneq ($(OMK_VERBOSE),0)
Q =
else
Q = @
endif
ifneq ($(findstring s,$(MAKEFLAGS)),)
QUIET_CMD_ECHO = true
OMK_SILENT = 1
else
QUIET_CMD_ECHO = echo
endif
MAKEFILE_OMK=Makefile.omk
# All subdirectories (even linked ones) containing Makefile.omk
# Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
# ===================================================================
# We have set up all important variables, so we can check and include
# real OCERA style Makefile.omk now
ifndef OMK_INCLUDED
include $(SOURCES_DIR)/$(MAKEFILE_OMK)
ifeq ($(AUTOMATIC_SUBDIRS),y)
SUBDIRS?=$(ALL_OMK_SUBDIRS)
endif
OMK_INCLUDED := 1
endif
print-hints:
@echo 'Use "make V=1" to see the verbose compile lines.'
check-make-ver:
@GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | $(SED4OMK) -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
echo "Your make program version ($(MAKE_VERSION)) is too old and does not support OMK system." ; \
echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
fi
distclean dist-clean:
@$(QUIET_CMD_ECHO) " RM $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
@rm -fr $(OUTPUT_DIR)/$(COMPILED_DIR_NAME) $(OUTPUT_DIR)/$(BUILD_DIR_NAME)
# Common OMK templates
# ====================
# Syntax: $(call mkdir,<dir name>)
define mkdir_def
[ -d $(1) ] || mkdir -p $(1) || exit 1
endef
ifneq ($(OMK_VERBOSE),2)
NO_PRINT_DIRECTORY := --no-print-directory
endif
ifeq ($(USE_LEAF_MAKEFILES),n)
export USE_LEAF_MAKEFILES
SUBDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
SOURCESDIR_MAKEFILE=$(MAKERULES_DIR)/Makefile.rules
else
SUBDIR_MAKEFILE=$(SOURCES_DIR)/$(3)/Makefile
SOURCESDIR_MAKEFILE=$(SOURCES_DIR)/Makefile
endif
pass = $(strip $(1))
unexport SUBDIRS
# Call a pass in a subdirectory
# Usage: $(call omk_pass_subdir_template,<pass name>,<build dir>,<subdir>)
define omk_pass_subdir_template
.PHONY: $(pass)-$(3)-subdir
$(pass)-submakes: $(pass)-$(3)-subdir
$(pass)-$(3)-subdir: MAKEOVERRIDES:=$(filter-out SUBDIRS=%,$(MAKEOVERRIDES))
$(pass)-$(3)-subdir:
@$(call mkdir_def,$(2)/$(3))
+@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR)/$(3) $(NO_PRINT_DIRECTORY) \
RELATIVE_DIR=$(RELATIVE_PREFIX)$(3) -C $(2)/$(3) \
-f $(SUBDIR_MAKEFILE) $(pass)-submakes
# In subdirectories we can call submakes directly since passes are
# already serialized on the toplevel make.
endef
ifdef OMK_TESTSROOT
check-target = $(1:%=%-check)
endif
# Call a pass in a subdirectory
# Usage: $(call extra_rules_subdir_template,<subdir>)
define extra_rules_subdir_template
extra-rules-subdirs: extra-rules-$(1)
extra-rules-$(1):
+@$(MAKE) OMK_SERIALIZE_INCLUDED=n MAKERULES_DIR=$(SOURCES_DIR)/$(1) OUTPUT_DIR=$(OUTPUT_DIR) \
SOURCES_DIR=$(SOURCES_DIR)/$(1) RELATIVE_DIR=$(RELATIVE_PREFIX)$(1) -C $(SOURCES_DIR)/$(1)
endef
.PHONY: extra-rules-subdirs
extra-rules-subdirs:
$(foreach subdir,$(EXTRA_RULES_SUBDIRS),$(eval $(call extra_rules_subdir_template,$(subdir))))
# Usage: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local enable condition>])
define omk_pass_template
.PHONY: $(pass) $(pass)-local $(pass)-check $(pass)-submakes
$(foreach subdir,$(SUBDIRS),$(eval $(call omk_pass_subdir_template,$(pass),$(2),$(subdir))))
$(pass):
# Submakes have to be called this way and not as dependecies for pass
# serialization to work
+@$(MAKE) --no-builtin-rules SOURCES_DIR=$(SOURCES_DIR) $(NO_PRINT_DIRECTORY) \
RELATIVE_DIR=$(RELATIVE_DIR) \
-f $(SOURCESDIR_MAKEFILE) $(pass)-submakes
$(pass)-submakes:
@true # Do not emit "nothing to be done" messages
ifneq ($(4)$($(pass)_HOOKS),)
$(pass)-submakes: $(pass)-this-dir
$(pass)-this-dir: $(foreach subdir,$(SUBDIRS),$(pass)-$(subdir)-subdir)
+@echo "make[omk]: $(pass) in $(RELATIVE_DIR)"
@$(call mkdir_def,$(2))
+@$(MAKE) --no-builtin-rules $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
-f $(SOURCESDIR_MAKEFILE) $(3) $(check-target) $(1:%=%-local)
$(pass)-local: $($(pass)_HOOKS)
endif
endef
# =======================
# DEFAULT CONFIG PASS
default-config:
@echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
@echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
@echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
@echo >> "$(CONFIG_FILE)-default"
@$(MAKE) $(NO_PRINT_DIRECTORY) -C $(OUTPUT_DIR) \
RELATIVE_DIR="" SOURCES_DIR=$(OUTPUT_DIR) \
-f $(OUTPUT_DIR)/Makefile default-config-pass
$(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
default-config-pass-local:
# @echo Default config for $(RELATIVE_DIR)
@echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
@$(foreach x, $(default_CONFIG), echo '$(x)' | \
$(SED4OMK) -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
omkize:
$(Q)if ! grep -q MAKERULES_DIR Makefile; then \
echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
fi
$(Q)for i in `find -L . -name Makefile.omk` ; do \
d=`dirname $${i}`; \
if ! test -f "$${d}/Makefile.rules" && ( test -f "$${d}/Makefile" && ! cmp -s Makefile "$${d}/Makefile" ); then \
rm -f "$${d}/Makefile"; \
cp -v Makefile "$${d}/Makefile"; \
fi \
done
#OMK:[email protected]
ifndef WVTEST_LIBRARY
WVTEST_LIBRARY = wvtest
endif
# Documentation: wvtest_PROGRAMS is amost equivalent to test_PROGRAMS.
# The two differences are that the program is automatically linked
# with $(WVTEST_LIBRARY) and it is run during "make wvtest".
test_PROGRAMS += $(wvtest_PROGRAMS)
# Documentation: If your project uses wvtest, it is recomended to put
# the "test: wvtest" rule to config.target.
wvtest:
$(Q)$(MAKERULES_DIR)/wvtestrun $(MAKE) wvtest-pass
.PHONY: wvtest
$(eval $(call omk_pass_template,wvtest-pass,$$(LOCAL_BUILD_DIR),,$(wvtest_SCRIPTS)$(wvtest_PROGRAMS)))
# Usage: $(call wvtest_template,<shell command>)
define wvtest_template
wvtest-pass-local: wvtest-run-$(1)
.PHONY: wvtest-run-$(1)
wvtest-run-$(1):
$(Q)echo "Testing \"Run $(1)\" in Makefile.rules:"
$(Q)mkdir -p $(1).wvtest
$(Q)cd $(1).wvtest && \
PATH=$$(USER_BIN_DIR):$$$$PATH LD_LIBRARY_PATH=$$(USER_LIB_DIR):$$$$LD_LIBRARY_PATH \
$(1)
$(notdir $(1))_LIBS += $$(WVTEST_LIBRARY)
endef
# Documentation: Write the test so, that it can be run from arbitrary
# directory, i.e. in case of a script ensure that the wvtest library
# is sourced like this:
#
# . $(dirname $0)/wvtest.sh
$(foreach script,$(wvtest_SCRIPTS),$(eval $(call wvtest_template,$(SOURCES_DIR)/$(script))))
# Hack!!!
USER_TESTS_DIR := $(OUTPUT_DIR)/_compiled/bin-tests
$(foreach prog,$(wvtest_PROGRAMS),$(eval $(call wvtest_template,$(USER_TESTS_DIR)/$(prog))))
ifeq ($(OMK_VERBOSE),1) #OMK:[email protected]
CPHEADER_FLAGS += -v
LNHEADER_FLAGS += -v
endif
ifneq ($(LN_HEADERS),y)
define cp_cmd
if ! cmp -s $(1) $(2); then \
echo " CP $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
install -d $(CPHEADER_FLAGS) `dirname $(2)` && \
install $(CPHEADER_FLAGS) $(1) $(2) || exit 1; \
fi
endef
else
define cp_cmd
if ! cmp -s $(1) $(2); then \
echo " LN $(1:$(OUTPUT_DIR)/%=%) -> $(2:$(OUTPUT_DIR)/%=%)"; \
if [ -f $(1) ]; then d=$(2); mkdir -p $${d%/*} && ln -sf $(LNHEADER_FLAGS) $(1) $(2) || exit 1; else exit 1; fi; \
fi
endef
endif
# TODO: Check modification date of changed header files. If it is
# newer that in source dir, show a warning.
# Syntax: $(call include-pass-template,<include dir>,<keyword>)
define include-pass-template
include-pass-local: include-pass-local-$(2)
include-pass-local-$(2): $$($(2)_GEN_HEADERS) $$(foreach f,$$(renamed_$(2)_GEN_HEADERS),$$(shell f='$$(f)'; echo $$$${f%->*}))
@$$(foreach f, $$($(2)_HEADERS),$$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
# FIXME: Use correct build dir, then document it (in the line bellow)
@$$(foreach f, $$($(2)_GEN_HEADERS),$$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$(f),$(1)/$$(notdir $$(f))); )
@$$(foreach f, $$(nobase_$(2)_HEADERS), $$(call cp_cmd,$$(SOURCES_DIR)/$$(f),$(1)/$$(f)); )
@$$(foreach f, $$(renamed_$(2)_HEADERS), \
f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
$$(call cp_cmd,$$(SOURCES_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
@$$(foreach f, $$(renamed_$(2)_GEN_HEADERS), \
f='$$(f)'; srcfname=$$$${f%->*}; destfname=$$$${f#*->}; \
$$(call cp_cmd,$$(LOCAL_BUILD_DIR)/$$$${srcfname},$(1)/$$$${destfname}); )
# Suppress "Nothing to be done for `include-pass-local'" message if no headers are defined in Makefile.omk
@$$(if $$($(2)_HEADERS)$$($(2)_GEN_HEADERS)$$(nobase_$(2)_HEADERS)$$(renamed_$(2)_HEADERS)$$(renamed_$(2)_GEN_HEADERS),,true)
endef
#OMK:[email protected]
# Hack to check RT-Linux rules
#LINUX_DIR := /home/cvs/ocera/ocera-build/kernel/linux
#RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
#CONFIG_RTLINUX = y
#OCERA_DIR := $(shell ( cd -L $(OUTPUT_DIR)/../../.. ; pwd -L ) )
-include $(OUTPUT_DIR)/OCERA_TOP_DIR
BUILD_DIR_NAME = _build
COMPILED_DIR_NAME = _compiled
ifndef GROUP_DIR_NAME
GROUP_DIR_NAME = nogroup
endif
ifdef OCERA_DIR
ifeq ($(wildcard $(OCERA_DIR)/ocera.mk),)
$(warning "ocera.mk" file does not exist. Adapt Makefile.rules for standalone compilation)
$(warning (comment out definition of OCERA_DIR line and optionally select RTL_DIR) )
$(error or go to the ocera/ directory and do 'make' to generate the "ocera.mk" file first, please)
endif
include $(OCERA_DIR)/ocera.mk
KERN_INCLUDE_DIR := $(OCERA_KERNEL_INCLUDES_DIR)
KERN_LIB_DIR := $(OCERA_KERNEL_LIBRARIES_DIR)
KERN_MODULES_DIR := $(OCERA_MODULES_DIR)
KERN_BUILD_DIR := $(BUILD_DIR)/kern/$(GROUP_DIR_NAME)
KERN_MODPOST_DIR := $(BUILD_DIR)/kern-modpost
USER_INCLUDE_DIR := $(OCERA_USER_INCLUDES_DIR)
USER_LIB_DIR := $(OCERA_USER_LIBRARIES_DIR)
USER_UTILS_DIR := $(TARGET_DIR)/usr/bin
USER_TESTS_DIR := $(TARGET_DIR)/usr/bin
USER_BIN_DIR := $(TARGET_DIR)/usr/bin
USER_BUILD_DIR := $(BUILD_DIR)/user/$(GROUP_DIR_NAME)
#LINUX_DIR := $(OCERA_DIR)/kernel/linux
#RTL_DIR := $(OCERA_DIR)/kernel/rtlinux
#CONFIG_FILE := $(OCERA_DIR)/emdebsys/.config
ifneq ($(wildcard $(CONFIG_FILE)),)
CONFIG_FILE_OK = y
endif
else # OCERA_DIR
KERN_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include-kern
KERN_LIB_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib-kern
KERN_MODULES_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/modules
KERN_BUILD_DIR := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/kern
KERN_MODPOST_DIR := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/kern-modpost
USER_INCLUDE_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/include
USER_LIB_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/lib
USER_UTILS_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-utils
USER_TESTS_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin-tests
USER_BIN_DIR := $(OUTPUT_DIR)/$(COMPILED_DIR_NAME)/bin
USER_BUILD_DIR := $(OUTPUT_DIR)/$(BUILD_DIR_NAME)/user
ifndef LINUX_VERSION
LINUX_VERSION=$(shell uname -r)
endif
ifndef LINUX_DIR
LINUX_DIR=/lib/modules/$(LINUX_VERSION)/build
endif
endif # OCERA_DIR
ifeq ($(BUILD_OS),)
# Check for target
ifeq ($(OS),Windows_NT)
BUILD_OS := win32
else
BUILD_OS := $(shell uname | tr '[A-Z]' '[a-z]' )
#$(warning BUILD_OS=$(BUILD_OS))
endif
endif
ifeq ($(TARGET_OS),)
TARGET_OS := $(BUILD_OS)
endif
export TARGET_OS
export BUILD_OS
LOCAL_BUILD_DIR = $(USER_OBJS_DIR)
# Assign default values to CFLAGS variable. If the variable is defined
# earlier (i.g. in config.omk), it is not overriden here.
CFLAGS ?= -O2 -Wall
CXXFLAGS ?= -O2 -Wall
CPPFLAGS += -I $(USER_INCLUDE_DIR)
LOADLIBES += -L$(USER_LIB_DIR)
LOADLIBES += $(lib_LOADLIBES:%=-l%)
LIB_CPPFLAGS += $(CPPFLAGS)
LIB_CFLAGS += $(CFLAGS)
ifeq ($(TARGET_OS),win32)
EXE_SUFFIX = .exe
SOLIB_EXT = dll
else
SOLIB_EXT = so
SOLIB_PICFLAGS += -fpic
endif
#vpath %.c $(SOURCES_DIR)
#vpath %.cc $(SOURCES_DIR)
#vpath %.cxx $(SOURCES_DIR)
USER_OBJS_DIR = $(USER_BUILD_DIR)/$(RELATIVE_DIR)
KERN_OBJS_DIR = $(KERN_BUILD_DIR)/$(RELATIVE_DIR)
OMK_WORK_DIR = $(USER_OBJS_DIR)
.PHONY: dep subdirs clean clean-custom cleandepend check-dir
# Some support to serialize some targets for parallel make
ifneq ($(OMK_SERIALIZE_INCLUDED),y)
include-pass: check-dir
library-pass: include-pass
link-pseudo-pass: library-pass
binary-pass: link-pseudo-pass
kernel-lib-pass: include-pass
kernel-mod-pass: kernel-lib-pass
kernel-modpost-pass: kernel-mod-pass
kernel-pass: kernel-mod-pass kernel-modpost-pass
override OMK_SERIALIZE_INCLUDED = y
MAKEOVERRIDES := $(filter-out OMK_SERIALIZE_INCLUDED=n,$(MAKEOVERRIDES))
endif
#=====================================================================
# User-space rules and templates to compile programs, libraries etc.
ifdef USER_RULE_TEMPLATES
USER_SOURCES2OBJS = .o/.c .o/.cc .o/.cxx .o/.cpp .o/.S .o/.o
USER_SOURCES2OBJSLO = .lo/.c .lo/.cc .lo/.cxx .lo/.cpp .lo/.S .lo/.lo
#%.lo: %.c
# $(CC) -o $@ $(LCFLAGS) -c $<
c_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -DOMK_FOR_USER
cc_o_COMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(CXXFLAGS) -DOMK_FOR_USER
S_o_COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(ASFLAGS) -DOMK_FOR_USER
idl_COMPILE = $(IDL_COMPILER)
# Check GCC version for user build
ifndef CC_MAJOR_VERSION
CC_MAJOR_VERSION := $(shell $(CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
endif
# Prepare suitable define for dependency building
ifeq ($(CC_MAJOR_VERSION),2)
CC_DEPFLAGS = -Wp,-MD,"[email protected]"
else
CC_DEPFLAGS = -MT $@ -MD -MP -MF "[email protected]"
endif
# Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
define COMPILE_c_o_template
$(2): $(1) $$(GEN_HEADERS)
@$(QUIET_CMD_ECHO) " CC $$@"
$(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
then mv -f "[email protected]" "[email protected]" ; \
else rm -f "[email protected]" ; exit 1; \
fi
endef
# Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
define COMPILE_cc_o_template
$(2): $(1) $$(GEN_HEADERS)
@$(QUIET_CMD_ECHO) " CXX $$@"
$(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
then mv -f "[email protected]" "[email protected]" ; \
else rm -f "[email protected]" ; exit 1; \
fi
endef
# Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
define COMPILE_S_o_template
$(2): $(1) $$(GEN_HEADERS)
@$(QUIET_CMD_ECHO) " AS $$@"
$(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
then mv -f "[email protected]" "[email protected]" ; \
else rm -f "[email protected]" ; exit 1; \
fi
endef
NM ?= nm
# Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
define CMETRIC_o_h_template
$(2): $(1)
@$(QUIET_CMD_ECHO) " CMETRIC $$@"
$(Q)if [ -n `dirname $$@` ] ; then \
if [ ! -e `dirname $$@` ] ; then \
mkdir -p `dirname $$@` ; fi ; fi
$(Q)echo >[email protected] '/* Automatically generated from $$< */'
$(Q)echo >>[email protected] '/* Conditionals to control compilation */'
# Bellow, the tricks with redirection are for shells without set -o pipefail
# (see http://www.mail-archive.com/[email protected]/msg00149.html)
$(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
| $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
| sort >>[email protected]` && exit $$$$status
$(Q)echo >>[email protected] '/* Defines from the values defined to symbols in hexadecimal format */'
$(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
| $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
| sort >>[email protected]` && exit $$$$status
$(Q)echo >>[email protected] '/* Defines from the values defined to symbols in decimal format */'
$(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\
| $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
| sort >>[email protected]` && exit $$$$status
$(Q)mv [email protected] $$@
endef
define COMPILE_idl_template
$(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) $$(wildcard $$(firstword $$(idl_COMPILE)))
@$(QUIET_CMD_ECHO) " IDL $$@"
$(Q) $$(idl_COMPILE) $$($(2)_IDLFLAGS) $(1)
endef
# Syntax: $(call PROGRAM_template,<dir>,<executable-name>,<executable-suffix>,<linker-sript>)
# FIXME: ???????? asi je tu blbej komentar
define PROGRAM_template
USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
$(foreach x, $(USER_SOURCES2OBJS),
$(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
$$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
)
$(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
USER_OBJS += $$($(1)_OBJS)
USER_SOURCES += $$($(1)_SOURCES)
$(2)/$(1)$(3): $$($(1)_OBJS)
@$(QUIET_CMD_ECHO) " LINK $$@"
$(Q) $$(if $$(filter %.cc,$$($(1)_SOURCES))$$(filter %.cxx,$$($(1)_SOURCES))$$(filter %.cpp,$$($(1)_SOURCES)),$$(CXX),$$(CC)) \
$$($(1)_OBJS) $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(LDFLAGS) $$($(1)_LDFLAGS) -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$@
@echo "$(2)/$(1)$(3): \\" >$(USER_OBJS_DIR)/$(1).exe.d
@$(SED4OMK) -n -e 's|^LOAD \(.*\)$$$$| \1 \&|p' $(USER_OBJS_DIR)/$(1).exe.map|tr '&' '\134' >>$(USER_OBJS_DIR)/$(1).exe.d
@echo >>$(USER_OBJS_DIR)/$(1).exe.d
endef
# Usage: $(call SCRIPT_template,<target-directory>,<script-name>)
define SCRIPT_template
$(2)/$(1): $$(SOURCES_DIR)/$(1)
@$(QUIET_CMD_ECHO) " CP $$@"
$(Q)cp $$^ $$@
endef
# Syntax: $(call LIBRARY_template,<library-name>)
define LIBRARY_template
USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
USER_GEN_SOURCES += $$($(1)_GEN_SOURCES)
$(foreach x, $(USER_SOURCES2OBJS),
$(1)_OBJS += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
$$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
)
$(1)_OBJS := $$(sort $$($(1)_OBJS:%/=%))
USER_OBJS += $$($(1)_OBJS)
USER_SOURCES += $$($(1)_SOURCES)
$(USER_LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
@$(QUIET_CMD_ECHO) " AR $$@"
$(Q) $(AR) rcs $$@ $$^
endef
.PHONY: FORCE
# Syntax: $(call SOLIB_template,<library-name>)
define SOLIB_template
USER_IDLS += $$($(1)_SERVER_IDL) $$($(1)_CLIENT_IDL) $$($(1)_IDL)
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-skels.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_SERVER_IDL:%.idl=%-common.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-stubs.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_CLIENT_IDL:%.idl=%-common.c))
$(1)_GEN_SOURCES += $$(filter %.c,$$($(1)_IDL:%.idl=%.c))
SOLIB_GEN_SOURCES += $$($(1)_GEN_SOURCES)
$(foreach x, $(USER_SOURCES2OBJSLO),
$(1)_OBJSLO += $$(patsubst %$(notdir $(x)),%$(dir $(x)),$$(filter %$(notdir $(x)),\
$$($(1)_SOURCES) $$($(1)_GEN_SOURCES)))
)
$(1)_OBJSLO := $$(sort $$($(1)_OBJSLO:%/=%))
SOLIB_OBJS += $$($(1)_OBJSLO)
SOLIB_SOURCES += $$($(1)_SOURCES)
$(OMK_WORK_DIR)/lib$(1).$(SOLIB_EXT).omkvar: $$($(1)_OBJSLO) FORCE
$(Q)echo '$(1)_objslo += $$$$(addprefix $(USER_OBJS_DIR)/,$$($(1)_OBJSLO))' > [email protected]; \
echo '$(1)_libs += $$($(1)_LIBS) $$(lib_LOADLIBES)' >> [email protected]; \
echo '$(1)_ldflags += $$($(1)_LDFLAGS) $$(lib_LDFLAGS)' >> [email protected]; \
echo 'shared_libs := $$$$(sort $(1) $$$$(shared_libs))' >> [email protected]; \
endef
library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
$(lib_LIBRARIES:%=$(USER_LIB_DIR)/lib%.a) $(shared_LIBRARIES:%=$(OMK_WORK_DIR)/lib%.$(SOLIB_EXT).omkvar)
binary-pass-local: $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%$(EXE_SUFFIX)) \
$(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%$(EXE_SUFFIX)) \
$(test_PROGRAMS:%=$(USER_TESTS_DIR)/%$(EXE_SUFFIX)) \
$(bin_SCRIPTS:%=$(USER_BIN_DIR)/%)
# Special rules for CMETRIC generated headers
$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
$(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
$(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
GEN_HEADERS+=$(filter %.h,$(USER_IDLS:%.idl=%.h))
# Generate rules for compilation of programs and libraries
$(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),$(EXE_SUFFIX))))
$(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(EXE_SUFFIX))))
$(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(EXE_SUFFIX))))
$(foreach script,$(bin_SCRIPTS),$(eval $(call SCRIPT_template,$(script),$(USER_BIN_DIR))))
$(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
$(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
-include $(USER_OBJS_DIR)/*.d
#FIXME: This doesn't include dependencies of source files from
#subdirectories (i.s. *_SOURCES=dir/file.c. I'm currently not sure,
#how to handle this.
endif # USER_RULE_TEMPLATES
.PHONY: link-pseudo-pass
link-pseudo-pass:
$(Q)$(MAKE) $(NO_PRINT_DIRECTORY) -C $(USER_BUILD_DIR) -f $(SOURCESDIR_MAKEFILE) link-shared-libs
ifeq ($(MAKECMDGOALS),link-shared-libs)
# Syntax: $(call solib_link_template,<library-name>)
define solib_link_template
$(1)_shared_libs = $$(patsubst %,$(USER_LIB_DIR)/lib%.$(SOLIB_EXT),$$(filter $$(shared_libs),$$($(1)_libs)))
#$$(warning $(1)_shared_libs = $$($(1)_shared_libs))
$(USER_LIB_DIR)/lib$(1).$(SOLIB_EXT): $$($(1)_shared_libs) $$($(1)_objslo)
@$(QUIET_CMD_ECHO) " LINK $$@"
$(Q)$(CC) --shared -Xlinker -soname=lib$(1).$(SOLIB_EXT) -Wl,-Map,$(USER_OBJS_DIR)/lib$(1).$(SOLIB_EXT).map -o $$@ $$($(1)_objslo) $$(LOADLIBES) $$($(1)_libs:%=-l%) $$(lib_ldflags) $$($(1)_ldflags)
endef
-include $(shell true; find $(USER_BUILD_DIR) -name 'lib*.omkvar') # `true' is a hack for MinGW
#$(warning $(shared_libs))
$(foreach lib,$(shared_libs),$(eval $(call solib_link_template,$(lib))))
.PHONY: link-shared-libs
link-shared-libs: $(shared_libs:%=$(USER_LIB_DIR)/lib%.$(SOLIB_EXT))
endif # link-shared-libs
#=====================================================================
# Kernel-space rules and templates to compile modules, libraries etc.
ifdef KERN_RULE_TEMPLATES
$(KERN_LIB_DIR)/kernel.mk: $(LINUX_DIR)/.config $(MAKERULES_DIR)/kernelcfg2mk
@$(QUIET_CMD_ECHO) " KCFG2MK $@"
$(Q) $(MAKERULES_DIR)/kernelcfg2mk $(LINUX_DIR) $(KERN_LIB_DIR)
ifeq ($(CONFIG_RTLINUX),y)
include $(RTL_DIR)/rtl.mk
KERN_CC = $(CC)
kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(CC) -print-search-dirs | $(SED4OMK) -n -e 's/^install: \(.*\)$$/\1/p' )
INCLUDES := -I $(KERN_INCLUDE_DIR) $(INCLUDE) $(rtlinux_INCLUDES) $(kernel_INCLUDES)
#-DEXPORT_NO_SYMBOLS
c_o_kern_COMPILE = $(KERN_CC) -idirafter $(kern_GCCLIB_DIR)/include $(INCLUDES) $(CFLAGS) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
cc_o_kern_COMPILE = $(CXX) $(INCLUDES) $(CXXFLAGS) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB
KERN_EXE_SUFFIX := .o
KERN_ARCH = $(ARCH)
KERN_LD = $(LD)
KERN_AR = $(AR)
else # CONFIG_RTLINUX
include $(KERN_LIB_DIR)/kernel.mk
ifeq ($(LINUX_SRC),)
LINUX_SRC = $(LINUX_DIR)
endif
kernel_INCLUDES += -I $(KERN_INCLUDE_DIR) -I $(LINUX_DIR) -idirafter $(LINUX_SRC)/include/linux
ifdef LINUX_CC
KERN_CC = $(LINUX_CC)
kern_GCCLIB_DIR=$(shell LANG=C LC_ALL=C LC_MESSAGES=C $(LINUX_CC) -print-search-dirs | $(SED4OMK) -n -e 's/^install: \(.*\)$$/\1/p' )
else
KERN_CC = echo KERN_CC not defined - compilation skipped
endif
c_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_CFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
cc_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_CFLAGS) $(LINUX_CFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB
S_o_kern_COMPILE = $(KERN_CC) $(kernel_INCLUDES) -idirafter $(kern_GCCLIB_DIR)/include $(LINUX_CPPFLAGS) $(LINUX_AFLAGS) $(LINUX_AFLAGS_MODULE) -DOMK_FOR_KERNEL -DEXPORT_SYMTAB -nostdinc
KERN_EXE_SUFFIX := $(LINUX_MODULE_EXT)
KERN_LDFLAGS = $(LINUX_LDFLAGS) $(LINUX_LDFLAGS_MODULE)
ifdef LINUX_ARCH
KERN_ARCH = $(LINUX_ARCH)
else
KERN_ARCH = echo KERN_ARCH not defined - skipped
endif
ifdef LINUX_LD
KERN_LD = $(LINUX_LD)
else
KERN_LD = echo KERN_LD not defined - skipped
endif
ifneq ($(LINUX_AR),)
KERN_AR = $(LINUX_AR)
else
KERN_AR = $(AR)
endif
ifeq ($(LINUX_QUOTE_MODNAME),y)
KERN_MQ=\"
KERN_KBUILD_MODNAME=-D"KBUILD_MODNAME=((THIS_MODULE)!=NULL?(THIS_MODULE)->name:NULL)"
endif
endif # CONFIG_RTLINUX
KERN_LOADLIBES += -L$(KERN_LIB_DIR)
KERN_LOADLIBES += $(rtlinux_LOADLIBES:%=-l%)
KERN_LOADLIBES += $(kernel_LOADLIBES:%=-l%)
# Check GCC version for kernel part of build
ifndef kern_CC_MAJOR_VERSION
kern_CC_MAJOR_VERSION := $(shell $(KERN_CC) -dumpversion | $(SED4OMK) -e 's/\([^.]\)\..*/\1/')
endif
# Prepare suitable define for dependency building
ifeq ($(kern_CC_MAJOR_VERSION),2)
kern_CC_DEPFLAGS = -Wp,-MD,"[email protected]"
else
kern_CC_DEPFLAGS = -MT $@ -MD -MP -MF "[email protected]"
endif
ifeq ($(KERN_EXE_SUFFIX),.ko)
ifeq ($(wildcard $(LINUX_DIR)/scripts/mod/modpost),)
KERN_MODPOST = $(LINUX_DIR)/scripts/modpost
else
KERN_MODPOST = $(LINUX_DIR)/scripts/mod/modpost
endif
KERN_MODULES_LINK_DIR = $(KERN_MODPOST_DIR)
KERN_LINK_SUFFIX = .o
else
KERN_MODULES_LINK_DIR = $(KERN_MODULES_DIR)
KERN_LINK_SUFFIX = $(KERN_EXE_SUFFIX)
endif
ifeq ($(LINUX_CONFIG_MODVERSIONS),y)
MODPOST_OPTS += -m
MODPOST_OPTS += -i $(LINUX_DIR)/Module.symvers
ifneq ($(LINUX_BUILDHOST),) # this is not correct point, it should look for 2.6.17 kernel
MODPOST_OPTS += -I $(KERN_LIB_DIR)/Module.symvers
endif
MODPOST_OPTS += -o $(KERN_LIB_DIR)/Module.symvers
endif
ifeq ($(LINUX_CONFIG_DEBUG_SECTION_MISMATCH),y)
MODPOST_OPTS += -S
endif
ifeq ($(LINUX_CONFIG_MARKERS),y)
MODPOST_OPTS += -K $(LINUX_DIR)/Module.markers
MODPOST_OPTS += -M $(KERN_LIB_DIR)/Module.markers
endif
ifeq ($(LINUX_KBUILD_MODPOST_WARN),y)
MODPOST_OPTS += -w
endif
ifneq ($(LINUX_BUILDHOST),)
ifneq ($(LINUX_BUILDHOST),$(LINUX_ARCH))
MODPOST_OPTS += -c
endif
endif
define COMPILE_c_o_kern_template
$(2): $(1)
@$(QUIET_CMD_ECHO) " CC [K] $$@"
$(Q) if $$(c_o_kern_COMPILE) $$(kern_CC_DEPFLAGS) $(3) $(KERN_KBUILD_MODNAME) \
-D"KBUILD_BASENAME=$(KERN_MQ)$(notdir $(basename $(1)))$(KERN_MQ)" \
-o $$@ -c $$< ; \
then mv -f "[email protected]" "[email protected]" ; \
else rm -f "[email protected]" ; exit 1; \
fi
endef
define COMPILE_cc_o_kern_template
$(2): $(1)
@$(QUIET_CMD_ECHO) " CXX [K] $$@"
$(Q) if $$(cc_o_kern_COMPILE) $$(kern_CC_DEPFLAGS) $(3) $(KERN_KBUILD_MODNAME) \
-D"KBUILD_BASENAME=$(KERN_MQ)$(notdir $(basename $(1)))$(KERN_MQ)" \
-o $$@ -c $$< ; \
then mv -f "[email protected]" "[email protected]" ; \
else rm -f "[email protected]" ; exit 1; \
fi
endef
define COMPILE_S_o_kern_template
$(2): $(1)
@$(QUIET_CMD_ECHO) " AS [K] $$@"
$(Q) if $$(S_o_kern_COMPILE) $$(kern_CC_DEPFLAGS) $(3) $(KERN_KBUILD_MODNAME) \
-D"KBUILD_BASENAME=$(KERN_MQ)$(notdir $(basename $(1)))$(KERN_MQ)" \
-o $$@ -c $$< ; \
then mv -f "[email protected]" "[email protected]" ; \
else rm -f "[email protected]" ; exit 1; \
fi
endef
define MODULE_kern_template
$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cpp=%.o))
$(1)_OBJS := $$(sort $$($(1)_OBJS))