]> 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 TARGET  += $(TARGET_$(OSYSTEM)) $(TARGET_PROFILE)
54
55 L4LIBDIR_PROG_NOEXC-y = $(L4LIBDIR_NOEXC)
56 L4LIBDIR_PROG_NOEXC-n = $(L4LIBDIR_R-$(L4_MULTITHREADED))
57
58 LDFLAGS_DYNAMIC_LINKER     := --dynamic-linker=rom/libld-l4.so
59 LDFLAGS_DYNAMIC_LINKER_GCC := $(addprefix -Wl$(BID_COMMA),$(LDFLAGS_DYNAMIC_LINKER))
60
61 # define some variables different for lib.mk and prog.mk
62 ifeq ($(MODE),shared)
63 LDFLAGS += $(LDFLAGS_DYNAMIC_LINKER)
64 endif
65 ifeq ($(CONFIG_BID_GENERATE_MAPFILE),y)
66 LDFLAGS += -Map $(strip $@).map
67 endif
68 LDFLAGS += $(addprefix -L, $(PRIVATE_LIBDIR) $(PRIVATE_LIBDIR_$(OSYSTEM)) $(PRIVATE_LIBDIR_$@) $(PRIVATE_LIBDIR_$@_$(OSYSTEM)))
69
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
77 else
78 ifneq ($(HOST_LINK),1)
79   LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4_KIP_ADDR) \
80              --defsym __L4_STACK_ADDR__=$(L4_STACK_ADDR)
81 endif
82 endif
83
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
90 else
91   # linking for some POSIX platform
92   ifeq ($(MODE),host)
93     # linking for the build-platform
94     LDFLAGS += -L$(OBJ_BASE)/lib/host
95     LDFLAGS += $(LIBS)
96   else
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
104   endif
105 endif
106
107 LDFLAGS += $(LDFLAGS_$@)
108
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
113 endif
114 endif
115
116
117 include $(L4DIR)/mk/install.inc
118
119 #VPATHEX = $(foreach obj, $(OBJS), $(firstword $(foreach dir, \
120 #          . $(VPATH),$(wildcard $(dir)/$(obj)))))
121
122 # target-rule:
123
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
130 # output.
131
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
136 # if we have ld.so.
137
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, \
143                            $(patsubst -L%,%,\
144                            $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
145                       $(wildcard $(dir)/$(file)))))
146 endif
147
148 DEPS    += $(foreach file,$(TARGET), $(dir $(file)).$(notdir $(file)).d)
149
150 LINK_PROGRAM-C-host-1   := $(CC)
151 LINK_PROGRAM-CXX-host-1 := $(CXX)
152
153 LINK_PROGRAM  := $(LINK_PROGRAM-C-host-$(HOST_LINK))
154 ifneq ($(SRC_CC),)
155 LINK_PROGRAM  := $(LINK_PROGRAM-CXX-host-$(HOST_LINK))
156 endif
157
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)
162
163 ifeq ($(LINK_PROGRAM),)
164 LINK_PROGRAM  := $(LD) -m $(LD_EMULATION)
165 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_LD)
166 else
167 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_GCC)
168 endif
169
170 $(TARGET): $(OBJS) $(LIBDEPS) $(CRT0) $(CRTN)
171         @$(LINK_MESSAGE)
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_$@))
176         @$(BUILT_MESSAGE)
177
178 endif   # architecture is defined, really build
179
180 -include $(DEPSVAR)
181 .PHONY: all clean cleanall config help install oldconfig txtconfig
182 help::
183         @echo "  all            - compile and install the binaries"
184 ifneq ($(SYSTEM),)
185         @echo "                   to $(INSTALLDIR_LOCAL)"
186 endif
187         @echo "  install        - compile and install the binaries"
188 ifneq ($(SYSTEM),)
189         @echo "                   to $(INSTALLDIR)"
190 endif
191         @echo "  relink         - relink and install the binaries"
192 ifneq ($(SYSTEM),)
193         @echo "                   to $(INSTALLDIR_LOCAL)"
194 endif
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"
200         @echo
201 ifneq ($(SYSTEM),)
202         @echo "  binaries are: $(TARGET)"
203 else
204         @echo "  build for architectures: $(TARGET_SYSTEMS)"
205 endif
206
207 endif   # _L4DIR_MK_PROG_MK undefined