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)))
53 TARGET += $(TARGET_$(OSYSTEM)) $(TARGET_PROFILE)
55 L4LIBDIR_PROG_NOEXC-y = $(L4LIBDIR_NOEXC)
56 L4LIBDIR_PROG_NOEXC-n = $(L4LIBDIR_R-$(L4_MULTITHREADED))
58 LDFLAGS_DYNAMIC_LINKER := --dynamic-linker=rom/libld-l4.so
59 LDFLAGS_DYNAMIC_LINKER_GCC := $(addprefix -Wl$(BID_COMMA),$(LDFLAGS_DYNAMIC_LINKER))
61 # define some variables different for lib.mk and prog.mk
63 LDFLAGS += $(LDFLAGS_DYNAMIC_LINKER)
65 ifeq ($(CONFIG_BID_GENERATE_MAPFILE),y)
66 LDFLAGS += -Map $(strip $@).map
68 LDFLAGS += $(addprefix -L, $(PRIVATE_LIBDIR) $(PRIVATE_LIBDIR_$(OSYSTEM)) $(PRIVATE_LIBDIR_$@) $(PRIVATE_LIBDIR_$@_$(OSYSTEM)))
70 # here because order of --defsym's is important
71 ifeq ($(MODE),l4linux)
72 L4LX_USER_KIP_ADDR = 0xbfdfd000
73 LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4LX_USER_KIP_ADDR) \
74 --defsym __l4sys_invoke_direct=$(L4LX_USER_KIP_ADDR)+$(L4_KIP_OFFS_SYS_INVOKE) \
75 --defsym __l4sys_debugger_direct=$(L4LX_USER_KIP_ADDR)+$(L4_KIP_OFFS_SYS_DEBUGGER)
76 CPPFLAGS += -DL4SYS_USE_UTCB_WRAP=1
78 ifneq ($(HOST_LINK),1)
79 LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4_KIP_ADDR) \
80 --defsym __L4_STACK_ADDR__=$(L4_STACK_ADDR)
84 ifneq ($(HOST_LINK),1)
85 # linking for our L4 platform
86 LDFLAGS += $(addprefix -L, $(L4LIBDIR_PROG_NOEXC-$(BID_INT_NOEXC)))
87 LDFLAGS += $(addprefix -T, $(LDSCRIPT))
88 LDFLAGS += --start-group $(LIBS) $(L4_LIBS) --end-group
89 LDFLAGS += --warn-common
91 # linking for some POSIX platform
93 # linking for the build-platform
94 LDFLAGS += -L$(OBJ_BASE)/lib/host
97 # linking for L4Linux, we want to look for Linux-libs before the L4-libs
98 LDFLAGS += $(GCCSYSLIBDIRS)
99 LDFLAGS += $(addprefix -L, $(L4LIBDIR_PROG_NOEXC-$(BID_INT_NOEXC)))
100 LDFLAGS += $(LIBS) -Wl,-Bstatic $(L4_LIBS)
101 # -Wl,-Bdynamic is only applicable for dynamically linked programs,
102 # we need a static/dynamic flag for the l4linux mode...
103 LDFLAGS += -Wl,-Bdynamic
107 LDFLAGS += $(LDFLAGS_$@)
109 ifeq ($(notdir $(LDSCRIPT)),main_stat.ld)
110 # ld denies -gc-section when linking against shared libraries
111 ifeq ($(findstring FOO,$(patsubst -l%.s,FOO,$(LIBS) $(L4_LIBS))),)
112 LDFLAGS += -gc-sections
117 include $(L4DIR)/mk/install.inc
119 #VPATHEX = $(foreach obj, $(OBJS), $(firstword $(foreach dir, \
120 # . $(VPATH),$(wildcard $(dir)/$(obj)))))
124 # Make looks for obj-files using VPATH only when looking for dependencies
125 # and applying implicit rules. Though make adapts its automatic variables,
126 # we cannot use them: The dependencies contain files which have not to be
127 # linked to the binary. Therefore the foreach searches the obj-files like
128 # make does, using the VPATH variable.
129 # Use a surrounding strip call to avoid ugly linebreaks in the commands
132 # Dependencies: When we have ld.so, we use MAKEDEP to build our
133 # library dependencies. If not, we fall back to LIBDEPS, an
134 # approximation of the correct dependencies for the binary. Note, that
135 # MAKEDEP will be empty if we dont have ld.so, LIBDEPS will be empty
138 ifeq ($(CONFIG_HAVE_LDSO),)
139 LIBDEPS = $(foreach file, \
140 $(patsubst -l%,lib%.a,$(filter-out -L%,$(LDFLAGS))) \
141 $(patsubst -l%,lib%.so,$(filter-out -L%,$(LDFLAGS))),\
142 $(word 1, $(foreach dir, \
144 $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
145 $(wildcard $(dir)/$(file)))))
148 DEPS += $(foreach file,$(TARGET), $(dir $(file)).$(notdir $(file)).d)
150 LINK_PROGRAM-C-host-1 := $(CC)
151 LINK_PROGRAM-CXX-host-1 := $(CXX)
153 LINK_PROGRAM := $(LINK_PROGRAM-C-host-$(HOST_LINK))
155 LINK_PROGRAM := $(LINK_PROGRAM-CXX-host-$(HOST_LINK))
158 BID_LDFLAGS_FOR_LINKING_LD = $(LDFLAGS)
159 BID_LDFLAGS_FOR_GCC = $(filter -static -shared -nostdlib -Wl$(BID_COMMA)% -L% -l%,$(LDFLAGS))
160 BID_LDFLAGS_FOR_LD = $(filter-out -static -shared -nostdlib -Wl$(BID_COMMA)% -L% -l%,$(LDFLAGS))
161 BID_LDFLAGS_FOR_LINKING_GCC = $(addprefix -Wl$(BID_COMMA),$(BID_LDFLAGS_FOR_LD)) $(BID_LDFLAGS_FOR_GCC)
163 ifeq ($(LINK_PROGRAM),)
164 LINK_PROGRAM := $(LD) -m $(LD_EMULATION)
165 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_LD)
167 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_GCC)
170 $(TARGET): $(OBJS) $(LIBDEPS) $(CRT0) $(CRTN)
172 $(VERBOSE)$(call MAKEDEP,$(INT_LD_NAME),,,ld) $(LINK_PROGRAM) -o $@ $(CRT0) $(OBJS) $(BID_LDFLAGS_FOR_LINKING) $(CRTN)
173 $(if $(BID_GEN_CONTROL),$(VERBOSE)echo "Requires: $(REQUIRES_LIBS)" >> $(PKGDIR)/Control)
174 $(if $(BID_POST_PROG_LINK_MSG_$@),@$(BID_POST_PROG_LINK_MSG_$@))
175 $(if $(BID_POST_PROG_LINK_$@),$(BID_POST_PROG_LINK_$@))
178 endif # architecture is defined, really build
181 .PHONY: all clean cleanall config help install oldconfig txtconfig
183 @echo " all - compile and install the binaries"
185 @echo " to $(INSTALLDIR_LOCAL)"
187 @echo " install - compile and install the binaries"
189 @echo " to $(INSTALLDIR)"
191 @echo " relink - relink and install the binaries"
193 @echo " to $(INSTALLDIR_LOCAL)"
195 @echo " disasm - disassemble first target"
196 @echo " scrub - delete backup and temporary files"
197 @echo " clean - delete generated object files"
198 @echo " cleanall - delete all generated, backup and temporary files"
199 @echo " help - this help"
202 @echo " binaries are: $(TARGET)"
204 @echo " build for architectures: $(TARGET_SYSTEMS)"
207 endif # _L4DIR_MK_PROG_MK undefined