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