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 LDFLAGS_DYNAMIC_LINKER := --dynamic-linker=rom/libld-l4.so
56 LDFLAGS_DYNAMIC_LINKER_GCC := $(addprefix -Wl$(BID_COMMA),$(LDFLAGS_DYNAMIC_LINKER))
58 # define some variables different for lib.mk and prog.mk
60 LDFLAGS += $(LDFLAGS_DYNAMIC_LINKER)
62 ifeq ($(CONFIG_BID_GENERATE_MAPFILE),y)
63 LDFLAGS += -Map $(strip $@).map
65 LDFLAGS += $(addprefix -L, $(PRIVATE_LIBDIR) $(PRIVATE_LIBDIR_$(OSYSTEM)) $(PRIVATE_LIBDIR_$@) $(PRIVATE_LIBDIR_$@_$(OSYSTEM)))
67 # here because order of --defsym's is important
68 ifeq ($(MODE),l4linux)
69 L4LX_USER_KIP_ADDR = 0xbfdfd000
70 LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4LX_USER_KIP_ADDR) \
71 --defsym __l4sys_invoke_direct=$(L4LX_USER_KIP_ADDR)+$(L4_KIP_OFFS_SYS_INVOKE) \
72 --defsym __l4sys_debugger_direct=$(L4LX_USER_KIP_ADDR)+$(L4_KIP_OFFS_SYS_DEBUGGER)
73 CPPFLAGS += -DL4SYS_USE_UTCB_WRAP=1
75 ifneq ($(HOST_LINK),1)
76 LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4_KIP_ADDR) \
77 --defsym __L4_STACK_ADDR__=$(L4_STACK_ADDR)
81 ifneq ($(HOST_LINK),1)
82 # linking for our L4 platform
83 LDFLAGS += $(addprefix -L, $(L4LIBDIR))
84 LDFLAGS += $(addprefix -T, $(LDSCRIPT))
85 LDFLAGS += --start-group $(LIBS) $(L4_LIBS) --end-group
86 LDFLAGS += --warn-common
88 # linking for some POSIX platform
90 # linking for the build-platform
91 LDFLAGS += -L$(OBJ_BASE)/lib/host
94 # linking for L4Linux, we want to look for Linux-libs before the L4-libs
95 LDFLAGS += $(GCCSYSLIBDIRS)
96 LDFLAGS += $(addprefix -L, $(L4LIBDIR))
97 LDFLAGS += $(LIBS) -Wl,-Bstatic $(L4_LIBS)
98 # -Wl,-Bdynamic is only applicable for dynamically linked programs,
99 # we need a static/dynamic flag for the l4linux mode...
100 LDFLAGS += -Wl,-Bdynamic
104 LDFLAGS += $(LDFLAGS_$@)
106 ifeq ($(notdir $(LDSCRIPT)),main_stat.ld)
107 # ld denies -gc-section when linking against shared libraries
108 ifeq ($(findstring FOO,$(patsubst -l%.s,FOO,$(LIBS) $(L4_LIBS))),)
109 LDFLAGS += -gc-sections
114 include $(L4DIR)/mk/install.inc
116 #VPATHEX = $(foreach obj, $(OBJS), $(firstword $(foreach dir, \
117 # . $(VPATH),$(wildcard $(dir)/$(obj)))))
121 # Make looks for obj-files using VPATH only when looking for dependencies
122 # and applying implicit rules. Though make adapts its automatic variables,
123 # we cannot use them: The dependencies contain files which have not to be
124 # linked to the binary. Therefore the foreach searches the obj-files like
125 # make does, using the VPATH variable.
126 # Use a surrounding strip call to avoid ugly linebreaks in the commands
129 # Dependencies: When we have ld.so, we use MAKEDEP to build our
130 # library dependencies. If not, we fall back to LIBDEPS, an
131 # approximation of the correct dependencies for the binary. Note, that
132 # MAKEDEP will be empty if we dont have ld.so, LIBDEPS will be empty
135 ifeq ($(CONFIG_HAVE_LDSO),)
136 LIBDEPS = $(foreach file, \
137 $(patsubst -l%,lib%.a,$(filter-out -L%,$(LDFLAGS))) \
138 $(patsubst -l%,lib%.so,$(filter-out -L%,$(LDFLAGS))),\
139 $(word 1, $(foreach dir, \
141 $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
142 $(wildcard $(dir)/$(file)))))
145 DEPS += $(foreach file,$(TARGET), $(dir $(file)).$(notdir $(file)).d)
147 LINK_PROGRAM-C-host-1 := $(CC)
148 LINK_PROGRAM-CXX-host-1 := $(CXX)
150 LINK_PROGRAM := $(LINK_PROGRAM-C-host-$(HOST_LINK))
152 LINK_PROGRAM := $(LINK_PROGRAM-CXX-host-$(HOST_LINK))
155 BID_LDFLAGS_FOR_LINKING_LD = $(LDFLAGS)
156 BID_LDFLAGS_FOR_GCC = $(filter -static -shared -nostdlib -Wl$(BID_COMMA)% -L% -l%,$(LDFLAGS))
157 BID_LDFLAGS_FOR_LD = $(filter-out -static -shared -nostdlib -Wl$(BID_COMMA)% -L% -l%,$(LDFLAGS))
158 BID_LDFLAGS_FOR_LINKING_GCC = $(addprefix -Wl$(BID_COMMA),$(BID_LDFLAGS_FOR_LD)) $(BID_LDFLAGS_FOR_GCC)
160 ifeq ($(LINK_PROGRAM),)
161 LINK_PROGRAM := $(LD) -m $(LD_EMULATION)
162 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_LD)
164 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_GCC)
167 $(TARGET): $(OBJS) $(LIBDEPS) $(CRT0) $(CRTN)
169 $(VERBOSE)$(call MAKEDEP,$(INT_LD_NAME),,,ld) $(LINK_PROGRAM) -o $@ $(CRT0) $(OBJS) $(BID_LDFLAGS_FOR_LINKING) $(CRTN)
170 $(if $(BID_GEN_CONTROL),$(VERBOSE)echo "Requires: $(REQUIRES_LIBS)" >> $(PKGDIR)/Control)
171 $(if $(BID_POST_PROG_LINK_MSG_$@),@$(BID_POST_PROG_LINK_MSG_$@))
172 $(if $(BID_POST_PROG_LINK_$@),$(BID_POST_PROG_LINK_$@))
175 endif # architecture is defined, really build
178 .PHONY: all clean cleanall config help install oldconfig txtconfig
180 @echo " all - compile and install the binaries"
182 @echo " to $(INSTALLDIR_LOCAL)"
184 @echo " install - compile and install the binaries"
186 @echo " to $(INSTALLDIR)"
188 @echo " relink - relink and install the binaries"
190 @echo " to $(INSTALLDIR_LOCAL)"
192 @echo " disasm - disassemble first target"
193 @echo " scrub - delete backup and temporary files"
194 @echo " clean - delete generated object files"
195 @echo " cleanall - delete all generated, backup and temporary files"
196 @echo " help - this help"
199 @echo " binaries are: $(TARGET)"
201 @echo " build for architectures: $(TARGET_SYSTEMS)"
204 endif # _L4DIR_MK_PROG_MK undefined