- Fixed some compiler warnings.
[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 # CHANGE THESE FOR YOUR OUTPUT
22 #
23 TARGET = i386
24 # Debugging information on (bigger binary)
25 #DEBUG = yes
26 # Debugging information off (smaller binary)
27 DEBUG = no
28
29 OBJDIR = obj
30 OUTPUT_DIR = $(OBJDIR)/$(TARGET)
31
32 BOOTCD_DIR = ../../bootcd
33
34 #############################################
35 # COMPILER AND LINKER PROGRAMS
36 #
37 TOOLSDIR = $(SRCDIR)/../tools
38
39 RM = $(subst /,$(SEP),$(TOOLSDIR))$(SEP)rdel
40 CP = $(subst /,$(SEP),$(TOOLSDIR))$(SEP)rcopy
41 MKDIR = $(subst /,$(SEP),$(TOOLSDIR))$(SEP)rmkdir
42 RMDIR = $(subst /,$(SEP),$(TOOLSDIR))$(SEP)rrmdir
43 OBJCOPY = objcopy
44 DEPTOOL = $(subst /,$(SEP),$(TOOLSDIR))$(SEP)deptool
45 HOSTTOOL = $(subst /,$(SEP),$(TOOLSDIR))$(SEP)hosttype
46 TOOLS = $(DEPTOOL) $(HOSTTOOL)
47
48 HOSTTYPE = $(shell $(HOSTTOOL))
49
50 #-----------------------------------------------------------------------------------------------------
51 # TEST IF WE ARE IN THE TARGET DIRECTORY
52 # IF NOT WE WILL CHANGE TO THE TARGET DIRECTORY AND RUN MAKE FROM THERE
53 #-----------------------------------------------------------------------------------------------------
54 #ifeq (,$(filter $(CURDIR)/$(OUTPUT_DIR),$(notdir $(CURDIR))))
55 ifneq ($(CURDIR), $(SRCDIR)/$(OUTPUT_DIR))
56
57 SRCDIR = $(CURDIR)
58
59 .SUFFIXES:
60
61 #############################################
62 # VARIABLE TO CHANGE TO TARGET DIRECTORY AND INVOKE MAKE FROM THERE
63 #
64 MAKETARGET = $(MAKE) --no-print-directory -C $(OUTPUT_DIR) \
65 -f ../../Makefile SRCDIR=$(CURDIR) $(MAKECMDGOALS)
66
67 .PHONY: CHANGE_TO_TARGET
68 CHANGE_TO_TARGET setupldr : BUILD_TOOLS $(OBJDIR) $(OBJDIR)/$(TARGET)
69 @echo Calculating source file dependencies...
70 +@$(MAKETARGET)
71
72 .PHONY: BUILD_TOOLS
73 BUILD_TOOLS:
74 @$(MAKE) --no-print-directory -C $(TOOLSDIR)
75
76 $(OBJDIR):
77 @echo Creating directory: $(OBJDIR)
78 @$(MKDIR) $(OBJDIR)
79
80 $(OBJDIR)/$(TARGET): $(OBJDIR)
81 @echo Creating directory: $(OBJDIR)/$(TARGET)
82 @$(MKDIR) $(OBJDIR)/$(TARGET)
83
84
85 Makefile : ;
86
87 % :: CHANGE_TO_TARGET
88
89 #############################################
90
91 .PHONY : clean
92 clean:
93 @$(MAKE) --no-print-directory -C $(TOOLSDIR)
94 @echo Cleaning directory $(OBJDIR)/$(TARGET)
95 @-$(RM) $(OBJDIR)/$(TARGET)/*
96 @echo Removing directory $(OBJDIR)/$(TARGET)
97 @-$(RMDIR) $(OBJDIR)/$(TARGET)
98 @-$(RMDIR) $(OBJDIR)
99 @echo Clean ALL done.
100
101 #############################################
102
103 .PHONY : bootcd
104 bootcd : bootcd_dirs setup_loader boot_loader
105
106 .PHONY : bootcd_dirs
107 bootcd_dirs:
108 $(MKDIR) $(BOOTCD_DIR)
109 $(MKDIR) $(BOOTCD_DIR)/disk
110 $(MKDIR) $(BOOTCD_DIR)/disk/reactos
111 $(MKDIR) $(BOOTCD_DIR)/disk/install
112 $(MKDIR) $(BOOTCD_DIR)/disk/bootdisk
113 $(MKDIR) $(BOOTCD_DIR)/disk/loader
114
115 .PHONY : boot_loader
116 boot_loader : $(OBJDIR)/$(TARGET)/freeldr.sys
117 $(CP) $(OBJDIR)/$(TARGET)/freeldr.sys $(BOOTCD_DIR)/disk/loader/freeldr.sys
118 $(CP) ../freeldr.ini $(BOOTCD_DIR)/disk/loader/freeldr.ini
119
120 .PHONY : setup_loader
121 setup_loader : $(OBJDIR)/$(TARGET)/setupldr.sys
122 $(CP) $(OBJDIR)/$(TARGET)/setupldr.sys $(BOOTCD_DIR)/disk/loader/setupldr.sys
123
124 #############################################
125
126 #-----------------------------------------------------------------------------------------------------
127 # END MAGIC TARGET DIRECTORY CHANGE STUFF
128 #-----------------------------------------------------------------------------------------------------
129 else
130
131 #############################################
132 # COMPILER COMMAND LINE OPTIONS
133 #
134 COMPILER_OPTIONS = -Wall -nostdlib -nostdinc -ffreestanding -fno-builtin -fno-inline \
135 -fno-zero-initialized-in-bss -O1 -MD
136 # FreeLoader does not use any of the standard libraries, includes, or built-in functions
137
138 #############################################
139 # COMPILER DEFINES
140 #
141 ifeq ($(DEBUG),yes)
142 COMPILER_DEBUG_DEFINES = -DDEBUG
143 else
144 COMPILER_DEBUG_DEFINES =
145 endif
146
147 COMPILER_DEFINES = -D__$(TARGET)__ $(COMPILER_DEBUG_DEFINES)
148
149 #############################################
150 # INCLUDE DIRECTORY OPTIONS
151 #
152 COMPILER_INCLUDES = -I$(SRCDIR)/include
153
154 #############################################
155 # COMPILER FLAGS
156 #
157 CFLAGS = $(COMPILER_OPTIONS) \
158 $(COMPILER_DEFINES) \
159 $(COMPILER_INCLUDES)
160
161 #############################################
162 # LINKER COMMAND LINE OPTIONS
163 #
164 #LINKER_OPTIONS = -N -Ttext=0x8000 --oformat=binary -s
165 LINKER_OPTIONS = -N -Ttext=0x8000
166
167 #############################################
168 # LINKER FLAGS
169 #
170 LFLAGS = $(LINKER_OPTIONS)
171
172 #############################################
173 # NASM FLAGS
174 #
175 ifeq ($(HOSTTYPE), dos)
176 NASMFLAGS = -f coff
177 else
178 ifeq ($(HOSTTYPE), win32)
179 NASMFLAGS = -f win32
180 else
181 NASMFLAGS = -f elf
182 endif
183 endif
184
185 #############################################
186 # LIST ALL THE OBJECT FILE GROUPS
187 #
188 # fathelp.o must come first in the link line because it contains bootsector helper code
189 # arch.o must come second in the link line because it contains the startup code
190 ARCH_OBJS = fathelp.o \
191 arch.o \
192 i386idt.o \
193 i386trap.o \
194 i386cpu.o \
195 i386pnp.o \
196 boot.o \
197 linux.o \
198 mb.o \
199 i386mem.o \
200 i386rtl.o \
201 i386vid.o \
202 drvmap.o \
203 int386.o \
204 i386disk.o \
205 portio.o \
206 hardware.o \
207 hwcpu.o \
208 hwpci.o \
209 _alloca.o # For Mingw32 builds
210
211
212 RTL_OBJS = print.o \
213 stdlib.o \
214 string.o \
215 list.o \
216 memcmp.o \
217 memcpy.o \
218 memmove.o \
219 memset.o
220
221 FS_OBJS = fs.o \
222 fat.o \
223 iso.o \
224 ext2.o \
225 ntfs.o \
226 fsrec.o
227
228 UI_OBJS = tui.o \
229 tuimenu.o \
230 ui.o \
231 gui.o
232
233 REACTOS_OBJS= arcname.o \
234 binhive.o \
235 registry.o
236
237 COMM_OBJS = rs232.o
238
239 DISK_OBJS = disk.o \
240 geometry.o \
241 partition.o
242
243 MM_OBJS = mm.o \
244 meminit.o
245
246 CACHE_OBJS = cache.o \
247 blocklist.o
248
249 INIFILE_OBJS= inifile.o \
250 ini_init.o \
251 parse.o
252
253 INFFILE_OBJS= inffile.o
254
255 VIDEO_OBJS = video.o \
256 vidmode.o \
257 fade.o \
258 palette.o \
259 pixel.o \
260 bank.o
261
262 # libgcc2.o contains code (__udivdi3, __umoddi3) necessary to do
263 # 64-bit division on the i386 (and other 32-bit) architectures
264 # This code was taken from the GCC v3.1 source
265 MATH_OBJS = libgcc2.o
266
267 BASE_OBJS = freeldr.o \
268 debug.o \
269 multiboot.o \
270 version.o
271
272 FREELDR_OBJS= bootmgr.o \
273 drivemap.o \
274 miscboot.o \
275 options.o \
276 linuxboot.o \
277 oslist.o \
278 custom.o
279
280 ROSLDR_OBJS = reactos.o
281
282 SETUPLDR_OBJS= setupldr.o
283
284 COMMON_OBJS = $(ARCH_OBJS) \
285 $(RTL_OBJS) \
286 $(FS_OBJS) \
287 $(UI_OBJS) \
288 $(REACTOS_OBJS) \
289 $(COMM_OBJS) \
290 $(DISK_OBJS) \
291 $(MM_OBJS) \
292 $(CACHE_OBJS) \
293 $(VIDEO_OBJS) \
294 $(MATH_OBJS) \
295 $(BASE_OBJS)
296
297 SPECIAL_OBJS = $(INIFILE_OBJS) \
298 $(INFFILE_OBJS) \
299 $(FREELDR_OBJS) \
300 $(ROSLDR_OBJS) \
301 $(SETUPLDR_OBJS)
302
303
304 F_OBJS = $(COMMON_OBJS) \
305 $(INIFILE_OBJS) \
306 $(ROSLDR_OBJS) \
307 $(FREELDR_OBJS)
308
309 S_OBJS = $(COMMON_OBJS) \
310 $(INIFILE_OBJS) \
311 $(INFFILE_OBJS) \
312 $(SETUPLDR_OBJS)
313
314
315 #############################################
316 # ALL THE OBJECTS
317 #
318 ALL_OBJS = $(COMMON_OBJS) \
319 $(SPECIAL_OBJS)
320
321
322 #############################################
323 # SET THE VPATH SO MAKE CAN FIND THE SOURCE FILES
324 #
325 VPATH = $(SRCDIR)/ \
326 $(SRCDIR)/arch/$(TARGET) \
327 $(SRCDIR)/rtl \
328 $(SRCDIR)/fs \
329 $(SRCDIR)/ui \
330 $(SRCDIR)/reactos \
331 $(SRCDIR)/comm \
332 $(SRCDIR)/disk \
333 $(SRCDIR)/mm \
334 $(SRCDIR)/cache \
335 $(SRCDIR)/inifile \
336 $(SRCDIR)/inffile \
337 $(SRCDIR)/video \
338 $(SRCDIR)/math \
339 $(SRCDIR)/include
340
341 #############################################
342
343 all : freeldr.sys setupldr.sys
344 @echo Make ALL done.
345
346 #############################################
347
348 freeldr.sys : $(ALL_OBJS)
349 @echo ===================================================== LINKING $@
350 # @$(LD) -N -Ttext=0x8000 --oformat=binary -s -o freeldr.sys $(F_OBJS)
351 @$(LD) $(LFLAGS) -Map freeldr.map -o freeldr.exe $(F_OBJS)
352 # @$(CC) -Wl,-Ttext=0x8000,-N,-Map,freeldr.map -o freeldr.exe $(F_OBJS)
353 @$(NM) --numeric-sort freeldr.exe > freeldr.sym
354 @$(OBJCOPY) -O binary freeldr.exe freeldr.sys
355
356 #############################################
357
358 setupldr.sys : $(ALL_OBJS)
359 @echo ===================================================== LINKING $@
360 @$(LD) $(LFLAGS) -Map setupldr.map -o setupldr.exe $(S_OBJS)
361 @$(NM) --numeric-sort setupldr.exe > setupldr.sym
362 @$(OBJCOPY) -O binary setupldr.exe setupldr.sys
363
364 #############################################
365
366 %.o :: %.c
367 @echo ===================================================== Compiling $*
368 @$(CC) $(CFLAGS) -o $@ -c $<
369 @$(DEPTOOL) $*.d
370
371 %.o :: %.S
372 @echo ===================================================== Assembling $*
373 @$(CC) $(CFLAGS) -o $@ -c $<
374 @$(DEPTOOL) $*.d
375
376 %.o :: %.asm
377 @echo ===================================================== Assembling $*
378 @$(NASM_CMD) $(NASMFLAGS) -o $@ $<
379
380 #############################################
381
382 # Include the automagically generated dependencies
383 -include $(ALL_OBJS:%.o=%.d)
384
385 #############################################
386
387 endif