]> rtime.felk.cvut.cz Git - l4.git/blob - l4/mk/lib.mk
Some minor fixes.
[l4.git] / l4 / mk / lib.mk
1 # -*- Makefile -*-
2 #
3 # DROPS (Dresden Realtime OPerating System) Component
4 #
5 # Makefile-Template for library directories
6 #
7 # install.inc is used, see there for further documentation
8 # binary.inc is used, see there for further documentation
9
10
11 ifeq ($(origin _L4DIR_MK_LIB_MK),undefined)
12 _L4DIR_MK_LIB_MK=y
13
14 ROLE = lib.mk
15
16 # define INSTALLDIRs prior to including install.inc, where the install-
17 # rules are defined. Same for INSTALLDIR.
18 ifeq ($(MODE),host)
19 INSTALLDIR_LIB          ?= $(DROPS_STDDIR)/lib/host
20 INSTALLDIR_LIB_LOCAL    ?= $(OBJ_BASE)/lib/host
21 else
22 INSTALLDIR_LIB          ?= $(DROPS_STDDIR)/lib/$(subst -,/,$(SYSTEM))
23 INSTALLDIR_LIB_LOCAL    ?= $(OBJ_BASE)/lib/$(subst -,/,$(SYSTEM))
24 endif
25 INSTALLFILE_LIB         ?= $(INSTALL) -m 644 $(1) $(2)
26 INSTALLFILE_LIB_LOCAL   ?= $(LN) -sf $(call absfilename,$(1)) $(2)
27
28 INSTALLFILE             = $(INSTALLFILE_LIB)
29 INSTALLDIR              = $(INSTALLDIR_LIB)
30 INSTALLFILE_LOCAL       = $(INSTALLFILE_LIB_LOCAL)
31 INSTALLDIR_LOCAL        = $(INSTALLDIR_LIB_LOCAL)
32
33 # our mode
34 MODE                    ?= lib
35
36 # sanity check for proper mode
37 ifneq ($(filter-out lib host,$(MODE)),)
38 $(error MODE=$(MODE) not possible when building libraries)
39 endif
40
41 # removed 2014/02
42 ifneq ($(BUILD_PIC),)
43 $(error BUILD_PIC=$(BUILD_PIC) is obsolete, use <xxx>.p.a as extra TARGET instead)
44 endif
45
46 # all libraries are built using the wraped utcb-getter
47 CPPFLAGS          += -DL4SYS_USE_UTCB_WRAP=1
48
49 # include all Makeconf.locals, define common rules/variables
50 include $(L4DIR)/mk/Makeconf
51 include $(L4DIR)/mk/binary.inc
52 $(GENERAL_D_LOC): $(L4DIR)/mk/lib.mk
53
54 ifneq ($(SYSTEM),) # if we are a system, really build
55
56 TARGET_LIB        := $(TARGET) $(TARGET_$(OSYSTEM))
57 TARGET_SHARED     := $(filter     %.so,$(TARGET_LIB))
58 TARGET_PIC        := $(filter     %.p.a,$(TARGET_LIB))
59
60 TARGET_STANDARD   := $(filter-out $(TARGET_SHARED) $(TARGET_PIC), $(TARGET_LIB))
61
62 $(call GENERATE_PER_TARGET_RULES,$(TARGET_STANDARD))
63 $(call GENERATE_PER_TARGET_RULES,$(TARGET_PIC) $(TARGET_SHARED),.s)
64
65 TARGET_PROFILE  := $(patsubst %.a,%.pr.a,\
66                         $(filter $(BUILD_PROFILE),$(TARGET_STANDARD)))
67 TARGET_PROFILE_SHARED := $(filter %.so,$(TARGET_PROFILE))
68 TARGET_PROFILE_PIC := $(patsubst %.a,%.p.a,\
69                         $(filter $(BUILD_PIC),$(TARGET_PROFILE)))
70
71 $(call GENERATE_PER_TARGET_RULES,$(TARGET_PROFILE),.pr)
72 $(call GENERATE_PER_TARGET_RULES,$(TARGET_PROFILE_PIC) $(TARGET_PROFILE_SHARED),.pr)
73
74 TARGET  += $(TARGET_$(OSYSTEM))
75 TARGET  += $(TARGET_PROFILE) $(TARGET_PROFILE_SHARED) $(TARGET_PROFILE_PIC)
76
77 # define some variables different for lib.mk and prog.mk
78 LDFLAGS += $(addprefix -L, $(PRIVATE_LIBDIR) $(PRIVATE_LIBDIR_$(OSYSTEM)) $(PRIVATE_LIBDIR_$@) $(PRIVATE_LIBDIR_$@_$(OSYSTEM)))
79 LDFLAGS += $(addprefix -L, $(L4LIBDIR))
80 LDFLAGS += $(LIBCLIBDIR)
81 LDFLAGS_SO ?= -shared -nostdlib
82
83 BID_LDFLAGS_FOR_LINKING_DYN_LD  = $(LDFLAGS)
84 BID_LDFLAGS_FOR_GCC_DYN         = $(filter     -static -shared -nostdlib -Wl$(BID_COMMA)% -L% -l%,$(LDFLAGS))
85 BID_LDFLAGS_FOR_LD_DYN          = $(filter-out -static -shared -nostdlib -Wl$(BID_COMMA)% -L% -l%,$(LDFLAGS))
86 BID_LDFLAGS_FOR_LINKING_DYN_GCC = $(addprefix -Wl$(BID_COMMA),$(BID_LDFLAGS_FOR_LD_DYN)) $(BID_LDFLAGS_FOR_GCC_DYN)
87
88
89 LDSCRIPT       = $(LDS_so)
90 LDSCRIPT_INCR ?= /dev/null
91 CRT0           = $(CRTI_so) $(CRTBEGIN_so) $(CRT1_so)
92 CRTN           = $(CRTN_so)
93
94 # install.inc eventually defines rules for every target
95 include $(L4DIR)/mk/install.inc
96
97 ifeq ($(NOTARGETSTOINSTALL),)
98 PC_LIBS     ?= $(patsubst lib%.so,-l%,$(TARGET_SHARED) \
99                $(patsubst lib%.a,-l%,$(TARGET_STANDARD)))
100
101 PC_FILENAME  ?= $(PKGNAME)
102 PC_FILENAMES ?= $(PC_FILENAME)
103 PC_FILES     := $(foreach pcfile,$(PC_FILENAMES),$(OBJ_BASE)/pc/$(pcfile).pc)
104
105 # 1: basename
106 # 2: pcfilename
107 get_cont = $(if $($(1)_$(2)),$($(1)_$(2)),$($(1)))
108
109 # Ths must contain all the contents of all possible PC files as used in
110 # below generate_pcfile
111 PC_FILES_CONTENTS := $(strip $(foreach pcfile,$(PC_FILENAMES),\
112   $(call get_cont,CONTRIB_INCDIR,$(pcfile)) \
113   $(call get_cont,PC_LIBS,$(pcfile)) \
114   $(call get_cont,REQUIRES_LIBS,$(pcfile)) \
115   $(call get_cont,PC_CFLAGS,$(pcfile))))
116
117 ifneq ($(PC_FILES_CONTENTS),)
118
119 # when adding something to generate_pcfile it must also be added to the
120 # PC_FILES_CONTENTS above, otherwise PC files may not be generated
121 $(OBJ_BASE)/pc/%.pc: $(GENERAL_D_LOC)
122         $(VERBOSE)$(call generate_pcfile,$*,$@,$(call get_cont,CONTRIB_INCDIR,$*),$(call get_cont,PC_LIBS,$*),$(call get_cont,REQUIRES_LIBS,$*),$(call get_cont,PC_CFLAGS,$*))
123
124 all:: $(PC_FILES)
125
126 endif
127 endif
128
129 DEPS    += $(foreach file,$(TARGET), $(dir $(file)).$(notdir $(file)).d)
130
131 $(filter-out $(LINK_INCR) %.so %.o.a %.o.pr.a, $(TARGET)):%.a: $(OBJS)
132         @$(AR_MESSAGE)
133         $(VERBOSE)[ -d "$(dir $@)" ] || $(MKDIR) $(dir $@)
134         $(VERBOSE)$(RM) $@
135         $(VERBOSE)$(AR) crs$(if $(filter %.thin.a,$@),T) $@ $(OBJS)
136         @$(BUILT_MESSAGE)
137
138 # shared lib
139 $(filter %.so, $(TARGET)):%.so: $(OBJS) $(CRTN) $(CRT0) $(CRTP) $(LIBDEPS)
140         @$(LINK_SHARED_MESSAGE)
141         $(VERBOSE)[ -d "$(dir $@)" ] || $(MKDIR) $(dir $@)
142         $(VERBOSE)$(call MAKEDEP,$(LD)) $(LD) \
143            -o $@ $(LDFLAGS_SO) $(addprefix -T,$(LDSCRIPT)) $(CRTP) \
144            $(OBJS) $(REQUIRES_LIBS_LIST) $(LDFLAGS) \
145            $(GCCLIB_SO) $(GCCLIB_EH) $(CRTN)
146         @$(BUILT_MESSAGE)
147
148 # build an object file (which looks like a lib to a later link-call), which
149 # is either later included as a whole or not at all (important for static
150 # constructors)
151 LINK_INCR_TARGETS = $(filter $(LINK_INCR) %.o.a %.o.pr.a, $(TARGET))
152 $(LINK_INCR_TARGETS):%.a: $(OBJS) $(LIBDEPS) $(foreach x,$(LINK_INCR_TARGETS),$(LINK_INCR_ONLYGLOBSYMFILE_$(x)))
153         @$(LINK_PARTIAL_MESSAGE)
154         $(VERBOSE)[ -d "$(dir $@)" ] || $(MKDIR) $(dir $@)
155         $(VERBOSE)$(call MAKEDEP,$(LD)) $(LD) \
156            -T$(LDSCRIPT_INCR) \
157            -o $@ -r $(OBJS) $(LDFLAGS)
158         $(if $(LINK_INCR_ONLYGLOBSYM_$@)$(LINK_INCR_ONLYGLOBSYMFILE_$@), \
159            $(VERBOSE)$(OBJCOPY) \
160            $(foreach f,$(LINK_INCR_ONLYGLOBSYMFILE_$@),--keep-global-symbols=$(f)) \
161            $(foreach f,$(LINK_INCR_ONLYGLOBSYM_$@),-G $(f)) \
162            $@)
163         @$(BUILT_MESSAGE)
164
165 endif   # architecture is defined, really build
166
167 .PHONY: all clean cleanall config help install oldconfig txtconfig
168 -include $(DEPSVAR)
169 help::
170         @echo "  all            - compile and install the libraries locally"
171 ifneq ($(SYSTEM),)
172         @echo "                   to $(INSTALLDIR_LOCAL)"
173 endif
174         @echo "  install        - compile and install the libraries globally"
175 ifneq ($(SYSTEM),)
176         @echo "                   to $(INSTALLDIR)"
177 endif
178         @echo "  scrub          - delete backup and temporary files"
179         @echo "  clean          - delete generated object files"
180         @echo "  cleanall       - delete all generated, backup and temporary files"
181         @echo "  help           - this help"
182         @echo
183 ifneq ($(SYSTEM),)
184         @echo "  libraries are: $(TARGET)"
185 else
186         @echo "  build for architectures: $(TARGET_SYSTEMS)"
187 endif
188
189 endif   # _L4DIR_MK_LIB_MK undefined