]> 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 LDFLAGS_DYNAMIC_LINKER     := --dynamic-linker=rom/libld-l4.so
56 LDFLAGS_DYNAMIC_LINKER_GCC := $(addprefix -Wl$(BID_COMMA),$(LDFLAGS_DYNAMIC_LINKER))
57
58 # define some variables different for lib.mk and prog.mk
59 ifeq ($(MODE),shared)
60 LDFLAGS += $(LDFLAGS_DYNAMIC_LINKER)
61 endif
62 ifeq ($(CONFIG_BID_GENERATE_MAPFILE),y)
63 LDFLAGS += -Map $(strip $@).map
64 endif
65 LDFLAGS += $(addprefix -L, $(PRIVATE_LIBDIR) $(PRIVATE_LIBDIR_$(OSYSTEM)) $(PRIVATE_LIBDIR_$@) $(PRIVATE_LIBDIR_$@_$(OSYSTEM)))
66
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
74 else
75 ifneq ($(HOST_LINK),1)
76   LDFLAGS += --defsym __L4_KIP_ADDR__=$(L4_KIP_ADDR) \
77              --defsym __L4_STACK_ADDR__=$(L4_STACK_ADDR)
78 endif
79 endif
80
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
87 else
88   # linking for some POSIX platform
89   ifeq ($(MODE),host)
90     # linking for the build-platform
91     LDFLAGS += -L$(OBJ_BASE)/lib/host
92     LDFLAGS += $(LIBS)
93   else
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
101   endif
102 endif
103
104 LDFLAGS += $(LDFLAGS_$@)
105
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
110 endif
111 endif
112
113
114 include $(L4DIR)/mk/install.inc
115
116 #VPATHEX = $(foreach obj, $(OBJS), $(firstword $(foreach dir, \
117 #          . $(VPATH),$(wildcard $(dir)/$(obj)))))
118
119 # target-rule:
120
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
127 # output.
128
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
133 # if we have ld.so.
134
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, \
140                            $(patsubst -L%,%,\
141                            $(filter -L%,$(LDFLAGS) $(L4ALL_LIBDIR))),\
142                       $(wildcard $(dir)/$(file)))))
143 endif
144
145 DEPS    += $(foreach file,$(TARGET), $(dir $(file)).$(notdir $(file)).d)
146
147 LINK_PROGRAM-C-host-1   := $(CC)
148 LINK_PROGRAM-CXX-host-1 := $(CXX)
149
150 LINK_PROGRAM  := $(LINK_PROGRAM-C-host-$(HOST_LINK))
151 ifneq ($(SRC_CC),)
152 LINK_PROGRAM  := $(LINK_PROGRAM-CXX-host-$(HOST_LINK))
153 endif
154
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)
159
160 ifeq ($(LINK_PROGRAM),)
161 LINK_PROGRAM  := $(LD) -m $(LD_EMULATION)
162 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_LD)
163 else
164 BID_LDFLAGS_FOR_LINKING = $(BID_LDFLAGS_FOR_LINKING_GCC)
165 endif
166
167 $(TARGET): $(OBJS) $(LIBDEPS) $(CRT0) $(CRTN)
168         @$(LINK_MESSAGE)
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_$@))
173         @$(BUILT_MESSAGE)
174
175 endif   # architecture is defined, really build
176
177 -include $(DEPSVAR)
178 .PHONY: all clean cleanall config help install oldconfig txtconfig
179 help::
180         @echo "  all            - compile and install the binaries"
181 ifneq ($(SYSTEM),)
182         @echo "                   to $(INSTALLDIR_LOCAL)"
183 endif
184         @echo "  install        - compile and install the binaries"
185 ifneq ($(SYSTEM),)
186         @echo "                   to $(INSTALLDIR)"
187 endif
188         @echo "  relink         - relink and install the binaries"
189 ifneq ($(SYSTEM),)
190         @echo "                   to $(INSTALLDIR_LOCAL)"
191 endif
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"
197         @echo
198 ifneq ($(SYSTEM),)
199         @echo "  binaries are: $(TARGET)"
200 else
201         @echo "  build for architectures: $(TARGET_SYSTEMS)"
202 endif
203
204 endif   # _L4DIR_MK_PROG_MK undefined