3 # DROPS (Dresden Realtime OPerating System) Component
5 # Makefile-Template for binary directories
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
11 ifeq ($(origin _L4DIR_MK_PROG_MK),undefined)
16 include $(L4DIR)/mk/Makeconf
17 $(GENERAL_D_LOC): $(L4DIR)/mk/prog.mk
19 # define INSTALLDIRs prior to including install.inc, where the install-
22 INSTALLDIR_BIN ?= $(DROPS_STDDIR)/bin/host
23 INSTALLDIR_BIN_LOCAL ?= $(OBJ_BASE)/bin/host
25 INSTALLDIR_BIN ?= $(DROPS_STDDIR)/bin/$(subst -,/,$(SYSTEM))
26 INSTALLDIR_BIN_LOCAL ?= $(OBJ_BASE)/bin/$(subst -,/,$(SYSTEM))
28 ifeq ($(CONFIG_BID_STRIP_PROGS),y)
29 INSTALLFILE_BIN ?= $(STRIP) --strip-unneeded $(1) -o $(2) && \
31 INSTALLFILE_BIN_LOCAL ?= $(STRIP) --strip-unneeded $(1) -o $(2) && \
34 INSTALLFILE_BIN ?= $(INSTALL) -m 755 $(1) $(2)
35 INSTALLFILE_BIN_LOCAL ?= $(INSTALL) -m 755 $(1) $(2)
38 INSTALLFILE = $(INSTALLFILE_BIN)
39 INSTALLDIR = $(INSTALLDIR_BIN)
40 INSTALLFILE_LOCAL = $(INSTALLFILE_BIN_LOCAL)
41 INSTALLDIR_LOCAL = $(INSTALLDIR_BIN_LOCAL)
46 # include all Makeconf.locals, define common rules/variables
47 include $(L4DIR)/mk/binary.inc
49 ifneq ($(SYSTEM),) # if we have a system, really build
51 TARGET_STANDARD := $(TARGET) $(TARGET_$(OSYSTEM))
52 TARGET_PROFILE := $(addsuffix .pr,$(filter $(BUILD_PROFILE),$(TARGET)))
54 $(call GENERATE_PER_TARGET_RULES,$(TARGET_STANDARD))
55 $(call GENERATE_PER_TARGET_RULES,$(TARGET_PROFILE),.pr)
57 TARGET += $(TARGET_$(OSYSTEM)) $(TARGET_PROFILE)
59 LDFLAGS_DYNAMIC_LINKER := --dynamic-linker=rom/libld-l4.so
60 LDFLAGS_DYNAMIC_LINKER_GCC := $(addprefix -Wl$(BID_COMMA),$(LDFLAGS_DYNAMIC_LINKER))
62 # define some variables different for lib.mk and prog.mk
64 LDFLAGS += $(LDFLAGS_DYNAMIC_LINKER)
66 ifeq ($(CONFIG_BID_GENERATE_MAPFILE),y)
67 LDFLAGS += -Map $(strip $@).map
69 LDFLAGS += $(addprefix -L, $(PRIVATE_LIBDIR) $(PRIVATE_LIBDIR_$(OSYSTEM)) $(PRIVATE_LIBDIR_$@) $(PRIVATE_LIBDIR_$@_$(OSYSTEM)))
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
79 ifneq ($(HOST_LINK),1)
80 LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4_KIP_ADDR) \
81 --defsym __L4_STACK_ADDR__=$(L4_STACK_ADDR)
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
92 # linking for some POSIX platform
94 # linking for the build-platform
95 LDFLAGS += -L$(OBJ_BASE)/lib/host
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
109 LDFLAGS += $(LDFLAGS_$@)
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
119 include $(L4DIR)/mk/install.inc
121 #VPATHEX = $(foreach obj, $(OBJS), $(firstword $(foreach dir, \
122 # . $(VPATH),$(wildcard $(dir)/$(obj)))))
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
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
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, \
146 $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
147 $(wildcard $(dir)/$(file)))))
150 DEPS += $(foreach file,$(TARGET), $(dir $(file)).$(notdir $(file)).d)
152 LINK_PROGRAM-C-host-1 := $(CC)
153 LINK_PROGRAM-CXX-host-1 := $(CXX)
155 LINK_PROGRAM := $(LINK_PROGRAM-C-host-$(HOST_LINK))
157 LINK_PROGRAM := $(LINK_PROGRAM-CXX-host-$(HOST_LINK))
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)
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
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
174 $(TARGET): $(OBJS) $(LIBDEPS) $(CRT0) $(CRTN)
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_$@))
184 endif # architecture is defined, really build
187 .PHONY: all clean cleanall config help install oldconfig txtconfig
189 @echo " all - compile and install the binaries"
191 @echo " to $(INSTALLDIR_LOCAL)"
193 @echo " install - compile and install the binaries"
195 @echo " to $(INSTALLDIR)"
197 @echo " relink - relink and install the binaries"
199 @echo " to $(INSTALLDIR_LOCAL)"
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"
208 @echo " binaries are: $(TARGET)"
210 @echo " build for architectures: $(TARGET_SYSTEMS)"
213 endif # _L4DIR_MK_PROG_MK undefined