Build FREELDR.SYS and SETUPLDR.SYS in a single make run.
[reactos.git] / freeldr / freeldr / Makefile
1 #
2 # FreeLoader
3 # Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19
20
21 #############################################
22 # CHANGE THESE FOR YOUR OUTPUT
23 #
24 TARGET = i386
25 # Debugging information on (bigger binary)
26 DEBUG = yes
27 # Debugging information off (smaller binary)
28 #DEBUG = no
29
30 OBJDIR = obj
31 OUTPUT_DIR = $(OBJDIR)/$(TARGET)
32
33 #############################################
34 # COMPILER AND LINKER PROGRAMS
35 #
36 TOOLSDIR = $(SRCDIR)/../tools
37
38 CC = gcc
39 LD = ld
40 AR = ar
41 NM = nm
42 RM = $(TOOLSDIR)/rdel
43 CP = $(TOOLSDIR)/rcopy
44 MKDIR = $(TOOLSDIR)/rmkdir
45 RMDIR = $(TOOLSDIR)/rrmdir
46 NASM_CMD = nasm
47 OBJCOPY = objcopy
48 DEPTOOL = $(TOOLSDIR)/deptool
49 HOSTTOOL = $(TOOLSDIR)/hosttype
50 TOOLS = $(DEPTOOL) $(HOSTTOOL)
51
52 HOST = $(shell $(HOSTTOOL))
53
54 #-----------------------------------------------------------------------------------------------------
55 # TEST IF WE ARE IN THE TARGET DIRECTORY
56 # IF NOT WE WILL CHANGE TO THE TARGET DIRECTORY AND RUN MAKE FROM THERE
57 #-----------------------------------------------------------------------------------------------------
58 #ifeq (,$(filter $(CURDIR)/$(OUTPUT_DIR),$(notdir $(CURDIR))))
59 ifneq ($(CURDIR), $(SRCDIR)/$(OUTPUT_DIR))
60
61 SRCDIR = $(CURDIR)
62
63 .SUFFIXES:
64
65 #############################################
66 # VARIABLE TO CHANGE TO TARGET DIRECTORY AND INVOKE MAKE FROM THERE
67 #
68 MAKETARGET = $(MAKE) --no-print-directory -C $(OUTPUT_DIR) \
69 -f ../../Makefile SRCDIR=$(CURDIR) $(MAKECMDGOALS)
70
71 .PHONY: CHANGE_TO_TARGET
72 CHANGE_TO_TARGET setupldr : BUILD_TOOLS $(OBJDIR) $(OBJDIR)/$(TARGET)
73 @echo Calculating source file dependencies...
74 +@$(MAKETARGET)
75
76 .PHONY: BUILD_TOOLS
77 BUILD_TOOLS:
78 @$(MAKE) --no-print-directory -C $(TOOLSDIR)
79
80 $(OBJDIR):
81 @echo Creating directory: $(OBJDIR)
82 @$(MKDIR) $(OBJDIR)
83
84 $(OBJDIR)/$(TARGET): $(OBJDIR)
85 @echo Creating directory: $(OBJDIR)/$(TARGET)
86 @$(MKDIR) $(OBJDIR)/$(TARGET)
87
88
89 Makefile : ;
90
91 % :: CHANGE_TO_TARGET
92
93 #############################################
94
95 .PHONY : clean
96 clean:
97 @$(MAKE) --no-print-directory -C $(TOOLSDIR)
98 @echo Cleaning directory $(OBJDIR)/$(TARGET)
99 @-$(RM) $(OBJDIR)/$(TARGET)/*
100 @echo Removing directory $(OBJDIR)/$(TARGET)
101 @-$(RMDIR) $(OBJDIR)/$(TARGET)
102 @-$(RMDIR) $(OBJDIR)
103 @echo Clean ALL done.
104
105 #############################################
106
107 #-----------------------------------------------------------------------------------------------------
108 # END MAGIC TARGET DIRECTORY CHANGE STUFF
109 #-----------------------------------------------------------------------------------------------------
110 else
111
112 #############################################
113 # COMPILER COMMAND LINE OPTIONS
114 #
115 COMPILER_OPTIONS = -Wall -nostdlib -nostdinc -fno-builtin -O1 -MD
116 # FreeLoader does not use any of the standard libraries, includes, or built-in functions
117
118 #############################################
119 # COMPILER DEFINES
120 #
121 ifeq ($(DEBUG),yes)
122 COMPILER_DEBUG_DEFINES = -DDEBUG
123 else
124 COMPILER_DEBUG_DEFINES =
125 endif
126
127 COMPILER_DEFINES = -D__$(TARGET)__ $(COMPILER_DEBUG_DEFINES)
128
129 #############################################
130 # INCLUDE DIRECTORY OPTIONS
131 #
132 COMPILER_INCLUDES = -I$(SRCDIR)/include
133
134 #############################################
135 # COMPILER FLAGS
136 #
137 CFLAGS = $(COMPILER_OPTIONS) \
138 $(COMPILER_DEFINES) \
139 $(COMPILER_INCLUDES)
140
141 #############################################
142 # LINKER COMMAND LINE OPTIONS
143 #
144 #LINKER_OPTIONS = -N -Ttext=0x8000 --oformat=binary -s
145 LINKER_OPTIONS = -N -Ttext=0x8000
146
147 #############################################
148 # LINKER FLAGS
149 #
150 LFLAGS = $(LINKER_OPTIONS)
151
152 #############################################
153 # NASM FLAGS
154 #
155 ifeq ($(HOST), dos)
156 NASMFLAGS = -f coff
157 else
158 ifeq ($(HOST), win32)
159 NASMFLAGS = -f win32
160 else
161 NASMFLAGS = -f elf
162 endif
163 endif
164
165 #############################################
166 # LIST ALL THE OBJECT FILE GROUPS
167 #
168 # fathelp.o must come first in the link line because it contains bootsector helper code
169 # arch.o must come second in the link line because it contains the startup code
170 ARCH_OBJS = fathelp.o \
171 arch.o \
172 i386idt.o \
173 i386trap.o \
174 boot.o \
175 linux.o \
176 mb.o \
177 mem.o \
178 biosdisk.o \
179 rtlcode.o \
180 biosvid.o \
181 drvmap.o
182
183 RTL_OBJS = memory.o \
184 print.o \
185 stdlib.o \
186 string.o \
187 list.o
188
189 FS_OBJS = fs.o \
190 fat.o \
191 iso.o \
192 ext2.o
193
194 UI_OBJS = tui.o \
195 tuimenu.o \
196 ui.o \
197 gui.o
198
199 REACTOS_OBJS= reactos.o \
200 arcname.o \
201 hwdetect.o \
202 reghive.o \
203 registry.o
204
205 COMM_OBJS = rs232.o \
206 portio.o
207
208 DISK_OBJS = disk.o \
209 geometry.o \
210 partition.o
211
212 MM_OBJS = mm.o \
213 meminit.o
214
215 CACHE_OBJS = cache.o \
216 blocklist.o
217
218 INIFILE_OBJS= inifile.o \
219 ini_init.o \
220 parse.o
221
222 VIDEO_OBJS = video.o \
223 vidmode.o
224
225 # libgcc2.o contains code (__udivdi3, __umoddi3) necessary to do
226 # 64-bit division on the i386 (and other 32-bit) architectures
227 # This code was taken from the GCC v3.1 source
228 MATH_OBJS = libgcc2.o
229
230 BASE_OBJS = freeldr.o \
231 debug.o \
232 drivemap.o \
233 multiboot.o \
234 version.o
235
236 FREELDR_OBJS= bootmgr.o \
237 miscboot.o \
238 options.o \
239 linuxboot.o \
240 oslist.o
241
242 SETUPLDR_OBJS= setupldr.o
243
244 COMMON_OBJS = $(ARCH_OBJS) \
245 $(RTL_OBJS) \
246 $(FS_OBJS) \
247 $(UI_OBJS) \
248 $(REACTOS_OBJS) \
249 $(COMM_OBJS) \
250 $(DISK_OBJS) \
251 $(MM_OBJS) \
252 $(CACHE_OBJS) \
253 $(INIFILE_OBJS) \
254 $(VIDEO_OBJS) \
255 $(MATH_OBJS) \
256 $(BASE_OBJS)
257
258 F_OBJS = $(COMMON_OBJS) \
259 $(FREELDR_OBJS)
260
261 S_OBJS = $(COMMON_OBJS) \
262 $(SETUPLDR_OBJS)
263
264 #############################################
265 # ALL THE OBJECTS
266 #
267 ALL_OBJS = $(COMMON_OBJS) \
268 $(FREELDR_OBJS) \
269 $(SETUPLDR_OBJS)
270
271
272 #############################################
273 # SET THE VPATH SO MAKE CAN FIND THE SOURCE FILES
274 #
275 VPATH = $(SRCDIR)/ \
276 $(SRCDIR)/arch/$(TARGET) \
277 $(SRCDIR)/rtl \
278 $(SRCDIR)/fs \
279 $(SRCDIR)/ui \
280 $(SRCDIR)/reactos \
281 $(SRCDIR)/comm \
282 $(SRCDIR)/disk \
283 $(SRCDIR)/mm \
284 $(SRCDIR)/cache \
285 $(SRCDIR)/inifile \
286 $(SRCDIR)/video \
287 $(SRCDIR)/math \
288 $(SRCDIR)/include
289
290 #############################################
291
292 all : freeldr.sys setupldr.sys
293 @echo Make ALL done.
294
295 #############################################
296
297 freeldr.sys : $(ALL_OBJS)
298 @echo ===================================================== LINKING $@
299 # @$(LD) -N -Ttext=0x8000 --oformat=binary -s -o freeldr.sys $(F_OBJS)
300 @$(LD) $(LFLAGS) -Map freeldr.map -o freeldr.exe $(F_OBJS)
301 # @$(CC) -Wl,-Ttext=0x8000,-N,-Map,freeldr.map -o freeldr.exe $(F_OBJS)
302 @$(NM) --numeric-sort freeldr.exe > freeldr.sym
303 @$(OBJCOPY) -O binary freeldr.exe freeldr.sys
304
305 #############################################
306
307 setupldr.sys : $(ALL_OBJS)
308 @echo ===================================================== LINKING $@
309 # @$(LD) -N -Ttext=0x8000 --oformat=binary -s -o setupldr.sys $(S_OBJS)
310 @$(LD) $(LFLAGS) -Map setupldr.map -o setupldr.exe $(S_OBJS)
311 @$(NM) --numeric-sort setupldr.exe > setupldr.sym
312 @$(OBJCOPY) -O binary setupldr.exe setupldr.sys
313
314 #############################################
315
316 %.o :: %.c
317 @echo ===================================================== Compiling $*
318 @$(CC) $(CFLAGS) -o $@ -c $<
319 @$(DEPTOOL) $*.d
320
321 %.o :: %.S
322 @echo ===================================================== Assembling $*
323 @$(CC) $(CFLAGS) -o $@ -c $<
324 @$(DEPTOOL) $*.d
325
326 %.o :: %.asm
327 @echo ===================================================== Assembling $*
328 @$(NASM_CMD) $(NASMFLAGS) -o $@ $<
329
330 #############################################
331
332 # Include the automagically generated dependencies
333 -include $(ALL_OBJS:%.o=%.d)
334
335 #############################################
336
337 endif