]> rtime.felk.cvut.cz Git - l4.git/blob - l4/mk/prog.mk
Update
[l4.git] / l4 / mk / prog.mk
1 # -*- Makefile -*-
2 #
3 # DROPS (Dresden Realtime OPerating System) Component
4 #
5 # Makefile-Template for binary directories
6 #
7 # Makeconf is used, see there for further documentation
8 # install.inc is used, see there for further documentation
9 # binary.inc is used, see there for further documentation
10
11 ifeq ($(origin _L4DIR_MK_PROG_MK),undefined)
12 _L4DIR_MK_PROG_MK=y
13
14 ROLE = prog.mk
15
16 include $(L4DIR)/mk/Makeconf
17 $(GENERAL_D_LOC): $(L4DIR)/mk/prog.mk
18
19 # define INSTALLDIRs prior to including install.inc, where the install-
20 # rules are defined.
21 ifeq ($(MODE),host)
22 INSTALLDIR_BIN          ?= $(DROPS_STDDIR)/bin/host
23 INSTALLDIR_BIN_LOCAL    ?= $(OBJ_BASE)/bin/host
24 else
25 INSTALLDIR_BIN          ?= $(DROPS_STDDIR)/bin/$(subst -,/,$(SYSTEM))
26 INSTALLDIR_BIN_LOCAL    ?= $(OBJ_BASE)/bin/$(subst -,/,$(SYSTEM))
27 endif
28 ifeq ($(CONFIG_BID_STRIP_PROGS),y)
29 INSTALLFILE_BIN         ?= $(STRIP) --strip-unneeded $(1) -o $(2) && \
30                            chmod 755 $(2)
31 INSTALLFILE_BIN_LOCAL   ?= $(STRIP) --strip-unneeded $(1) -o $(2) && \
32                            chmod 755 $(2)
33 else
34 INSTALLFILE_BIN         ?= $(INSTALL) -m 755 $(1) $(2)
35 INSTALLFILE_BIN_LOCAL   ?= $(INSTALL) -m 755 $(1) $(2)
36 endif
37
38 INSTALLFILE             = $(INSTALLFILE_BIN)
39 INSTALLDIR              = $(INSTALLDIR_BIN)
40 INSTALLFILE_LOCAL       = $(INSTALLFILE_BIN_LOCAL)
41 INSTALLDIR_LOCAL        = $(INSTALLDIR_BIN_LOCAL)
42
43 # our mode
44 MODE                    ?= static
45
46 # include all Makeconf.locals, define common rules/variables
47 include $(L4DIR)/mk/binary.inc
48
49 ifneq ($(SYSTEM),) # if we have a system, really build
50
51 TARGET_STANDARD := $(TARGET) $(TARGET_$(OSYSTEM))
52 TARGET_PROFILE := $(addsuffix .pr,$(filter $(BUILD_PROFILE),$(TARGET)))
53
54 $(call GENERATE_PER_TARGET_RULES,$(TARGET_STANDARD))
55 $(call GENERATE_PER_TARGET_RULES,$(TARGET_PROFILE),.pr)
56
57 TARGET  += $(TARGET_$(OSYSTEM)) $(TARGET_PROFILE)
58
59 LDFLAGS_DYNAMIC_LINKER     := --dynamic-linker=rom/libld-l4.so
60 LDFLAGS_DYNAMIC_LINKER_GCC := $(addprefix -Wl$(BID_COMMA),$(LDFLAGS_DYNAMIC_LINKER))
61
62 # define some variables different for lib.mk and prog.mk
63 ifeq ($(MODE),shared)
64 LDFLAGS += $(LDFLAGS_DYNAMIC_LINKER)
65 endif
66 ifeq ($(CONFIG_BID_GENERATE_MAPFILE),y)
67 LDFLAGS += -Map $(strip $@).map
68 endif
69 LDFLAGS += $(addprefix -L, $(PRIVATE_LIBDIR) $(PRIVATE_LIBDIR_$(OSYSTEM)) $(PRIVATE_LIBDIR_$@) $(PRIVATE_LIBDIR_$@_$(OSYSTEM)))
70
71 # here because order of --defsym's is important
72 ifeq ($(MODE),l4linux)
73   L4LX_USER_KIP_ADDR = 0xbfdfd000
74   LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4LX_USER_KIP_ADDR) \
75              --defsym __l4sys_invoke_direct=$(L4LX_USER_KIP_ADDR)+$(L4_KIP_OFFS_SYS_INVOKE) \
76              --defsym __l4sys_debugger_direct=$(L4LX_USER_KIP_ADDR)+$(L4_KIP_OFFS_SYS_DEBUGGER)
77   CPPFLAGS += -DL4SYS_USE_UTCB_WRAP=1
78 else
79 ifneq ($(HOST_LINK),1)
80   LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4_KIP_ADDR) \
81              --defsym __L4_STACK_ADDR__=$(L4_STACK_ADDR)
82 endif
83 endif
84
85 ifneq ($(HOST_LINK),1)
86   # linking for our L4 platform
87   LDFLAGS += $(addprefix -L, $(L4LIBDIR))
88   LDFLAGS += $(addprefix -T, $(LDSCRIPT))
89   LDFLAGS += --start-group $(LIBS) $(L4_LIBS) --end-group
90   LDFLAGS += --warn-common
91 else
92   # linking for some POSIX platform
93   ifeq ($(MODE),host)
94     # linking for the build-platform
95     LDFLAGS += -L$(OBJ_BASE)/lib/host
96     LDFLAGS += $(LIBS)
97   else
98     # linking for L4Linux, we want to look for Linux-libs before the L4-libs
99     LDFLAGS += $(GCCSYSLIBDIRS)
100     LDFLAGS += $(addprefix -L, $(L4LIBDIR))
101     LDFLAGS += $(LIBS) -Wl,-Bstatic $(L4_LIBS)
102     # -Wl,-Bdynamic is only applicable for dynamically linked programs,
103     ifeq ($(filter -static, $(LDFLAGS)),)
104       LDFLAGS += -Wl,-Bdynamic
105     endif
106   endif
107 endif
108
109 LDFLAGS += $(LDFLAGS_$@)
110
111 ifeq ($(notdir $(LDSCRIPT)),main_stat.ld)
112 # ld denies -gc-section when linking against shared libraries
113 ifeq ($(findstring FOO,$(patsubst -l%.s,FOO,$(LIBS) $(L4_LIBS))),)
114 LDFLAGS += -gc-sections
115 endif
116 endif
117
118
119 include $(L4DIR)/mk/install.inc
120
121 #VPATHEX = $(foreach obj, $(OBJS), $(firstword $(foreach dir, \
122 #          . $(VPATH),$(wildcard $(dir)/$(obj)))))
123
124 # target-rule:
125
126 # Make looks for obj-files using VPATH only when looking for dependencies
127 # and applying implicit rules. Though make adapts its automatic variables,
128 # we cannot use them: The dependencies contain files which have not to be
129 # linked to the binary. Therefore the foreach searches the obj-files like
130 # make does, using the VPATH variable.
131 # Use a surrounding strip call to avoid ugly linebreaks in the commands
132 # output.
133
134 # Dependencies: When we have ld.so, we use MAKEDEP to build our
135 # library dependencies. If not, we fall back to LIBDEPS, an
136 # approximation of the correct dependencies for the binary. Note, that
137 # MAKEDEP will be empty if we dont have ld.so, LIBDEPS will be empty
138 # if we have ld.so.
139
140 ifeq ($(CONFIG_HAVE_LDSO),)
141 LIBDEPS = $(foreach file, \
142                     $(patsubst -l%,lib%.a,$(filter-out -L%,$(LDFLAGS))) \
143                     $(patsubst -l%,lib%.so,$(filter-out -L%,$(LDFLAGS))),\
144                     $(word 1, $(foreach dir, \
145                            $(patsubst -L%,%,\
146                            $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
147                       $(wildcard $(dir)/$(file)))))
148 endif
149
150 DEPS    += $(foreach file,$(TARGET), $(dir $(file)).$(notdir $(file)).d)
151
152 LINK_PROGRAM-C-host-1   := $(CC)
153 LINK_PROGRAM-CXX-host-1 := $(CXX)
154
155 LINK_PROGRAM  := $(LINK_PROGRAM-C-host-$(HOST_LINK))
156 ifneq ($(SRC_CC),)
157 LINK_PROGRAM  := $(LINK_PROGRAM-CXX-host-$(HOST_LINK))
158 endif
159
160 BID_LDFLAGS_FOR_LINKING_LD  = $(LDFLAGS)
161 BID_LDFLAGS_FOR_GCC         = $(filter     -static -shared -nostdlib -Wl$(BID_COMMA)% -L% -l%,$(LDFLAGS))
162 BID_LDFLAGS_FOR_LD          = $(filter-out -static -shared -nostdlib -Wl$(BID_COMMA)% -L% -l%,$(LDFLAGS))
163 BID_LDFLAGS_FOR_LINKING_GCC = $(addprefix -Wl$(BID_COMMA),$(BID_LDFLAGS_FOR_LD)) $(BID_LDFLAGS_FOR_GCC)
164
165 ifeq ($(LINK_PROGRAM),)
166 LINK_PROGRAM  := $(LD)
167 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_LD)
168 BID_LD_WHOLE_ARCHIVE = --whole-archive $1 --no-whole-archive
169 else
170 BID_LDFLAGS_FOR_LINKING = $(if $(HOST_LINK_TARGET),$(CCXX_FLAGS)) $(BID_LDFLAGS_FOR_LINKING_GCC)
171 BID_LD_WHOLE_ARCHIVE = -Wl,--whole-archive $1 -Wl,--no-whole-archive
172 endif
173
174 $(TARGET): $(OBJS) $(LIBDEPS) $(CRT0) $(CRTN)
175         @$(LINK_MESSAGE)
176         $(VERBOSE)$(call MAKEDEP,$(INT_LD_NAME),,,ld) $(LINK_PROGRAM) -o $@ $(CRT0) \
177                     $(call BID_LD_WHOLE_ARCHIVE, $(OBJS)) \
178                     $(BID_LDFLAGS_FOR_LINKING) $(CRTN)
179         $(if $(BID_GEN_CONTROL),$(VERBOSE)echo "Requires: $(REQUIRES_LIBS)" >> $(PKGDIR)/Control)
180         $(if $(BID_POST_PROG_LINK_MSG_$@),@$(BID_POST_PROG_LINK_MSG_$@))
181         $(if $(BID_POST_PROG_LINK_$@),$(BID_POST_PROG_LINK_$@))
182         @$(BUILT_MESSAGE)
183
184 endif   # architecture is defined, really build
185
186 -include $(DEPSVAR)
187 .PHONY: all clean cleanall config help install oldconfig txtconfig
188 help::
189         @echo "  all            - compile and install the binaries"
190 ifneq ($(SYSTEM),)
191         @echo "                   to $(INSTALLDIR_LOCAL)"
192 endif
193         @echo "  install        - compile and install the binaries"
194 ifneq ($(SYSTEM),)
195         @echo "                   to $(INSTALLDIR)"
196 endif
197         @echo "  relink         - relink and install the binaries"
198 ifneq ($(SYSTEM),)
199         @echo "                   to $(INSTALLDIR_LOCAL)"
200 endif
201         @echo "  disasm         - disassemble first target"
202         @echo "  scrub          - delete backup and temporary files"
203         @echo "  clean          - delete generated object files"
204         @echo "  cleanall       - delete all generated, backup and temporary files"
205         @echo "  help           - this help"
206         @echo
207 ifneq ($(SYSTEM),)
208         @echo "  binaries are: $(TARGET)"
209 else
210         @echo "  build for architectures: $(TARGET_SYSTEMS)"
211 endif
212
213 endif   # _L4DIR_MK_PROG_MK undefined