Created new subtree for groups of related test programs.
[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 $(OBJDIR)/$(TARGET)/setupldr.sys
111 $(CP) $(OBJDIR)/$(TARGET)/setupldr.sys $(BOOTCD_DIR)/disk/reactos/setupldr.sys
112
113
114 .PHONY : bootcd_dirs
115 bootcd_dirs:
116 $(MKDIR) $(BOOTCD_DIR)
117 $(MKDIR) $(BOOTCD_DIR)/disk
118 $(MKDIR) $(BOOTCD_DIR)/disk/reactos
119 $(MKDIR) $(BOOTCD_DIR)/disk/install
120 $(MKDIR) $(BOOTCD_DIR)/disk/bootdisk
121
122
123 #############################################
124
125 #-----------------------------------------------------------------------------------------------------
126 # END MAGIC TARGET DIRECTORY CHANGE STUFF
127 #-----------------------------------------------------------------------------------------------------
128 else
129
130 #############################################
131 # COMPILER COMMAND LINE OPTIONS
132 #
133 COMPILER_OPTIONS = -Wall -nostdlib -nostdinc -ffreestanding -fno-builtin -fno-inline -O1 -MD
134 # FreeLoader does not use any of the standard libraries, includes, or built-in functions
135
136 #############################################
137 # COMPILER DEFINES
138 #
139 ifeq ($(DEBUG),yes)
140 COMPILER_DEBUG_DEFINES = -DDEBUG
141 else
142 COMPILER_DEBUG_DEFINES =
143 endif
144
145 COMPILER_DEFINES = -D__$(TARGET)__ $(COMPILER_DEBUG_DEFINES)
146
147 #############################################
148 # INCLUDE DIRECTORY OPTIONS
149 #
150 COMPILER_INCLUDES = -I$(SRCDIR)/include
151
152 #############################################
153 # COMPILER FLAGS
154 #
155 CFLAGS = $(COMPILER_OPTIONS) \
156 $(COMPILER_DEFINES) \
157 $(COMPILER_INCLUDES)
158
159 #############################################
160 # LINKER COMMAND LINE OPTIONS
161 #
162 #LINKER_OPTIONS = -N -Ttext=0x8000 --oformat=binary -s
163 LINKER_OPTIONS = -N -Ttext=0x8000
164
165 #############################################
166 # LINKER FLAGS
167 #
168 LFLAGS = $(LINKER_OPTIONS)
169
170 #############################################
171 # NASM FLAGS
172 #
173 ifeq ($(HOST), dos)
174 NASMFLAGS = -f coff
175 else
176 ifeq ($(HOST), win32)
177 NASMFLAGS = -f win32
178 else
179 NASMFLAGS = -f elf
180 endif
181 endif
182
183 #############################################
184 # LIST ALL THE OBJECT FILE GROUPS
185 #
186 # fathelp.o must come first in the link line because it contains bootsector helper code
187 # arch.o must come second in the link line because it contains the startup code
188 ARCH_OBJS = fathelp.o \
189 arch.o \
190 i386idt.o \
191 i386trap.o \
192 boot.o \
193 linux.o \
194 mb.o \
195 mem.o \
196 biosdisk.o \
197 rtlcode.o \
198 biosvid.o \
199 drvmap.o
200
201 RTL_OBJS = memory.o \
202 print.o \
203 stdlib.o \
204 string.o \
205 list.o
206
207 FS_OBJS = fs.o \
208 fat.o \
209 iso.o \
210 ext2.o
211
212 UI_OBJS = tui.o \
213 tuimenu.o \
214 ui.o \
215 gui.o
216
217 REACTOS_OBJS= reactos.o \
218 arcname.o \
219 hwdetect.o \
220 reghive.o \
221 registry.o
222
223 COMM_OBJS = rs232.o \
224 portio.o
225
226 DISK_OBJS = disk.o \
227 geometry.o \
228 partition.o
229
230 MM_OBJS = mm.o \
231 meminit.o
232
233 CACHE_OBJS = cache.o \
234 blocklist.o
235
236 INIFILE_OBJS= inifile.o \
237 ini_init.o \
238 parse.o
239
240 VIDEO_OBJS = video.o \
241 vidmode.o
242
243 # libgcc2.o contains code (__udivdi3, __umoddi3) necessary to do
244 # 64-bit division on the i386 (and other 32-bit) architectures
245 # This code was taken from the GCC v3.1 source
246 MATH_OBJS = libgcc2.o
247
248 BASE_OBJS = freeldr.o \
249 debug.o \
250 drivemap.o \
251 multiboot.o \
252 version.o
253
254 FREELDR_OBJS= bootmgr.o \
255 miscboot.o \
256 options.o \
257 linuxboot.o \
258 oslist.o
259
260 SETUPLDR_OBJS= setupldr.o
261
262 COMMON_OBJS = $(ARCH_OBJS) \
263 $(RTL_OBJS) \
264 $(FS_OBJS) \
265 $(UI_OBJS) \
266 $(REACTOS_OBJS) \
267 $(COMM_OBJS) \
268 $(DISK_OBJS) \
269 $(MM_OBJS) \
270 $(CACHE_OBJS) \
271 $(INIFILE_OBJS) \
272 $(VIDEO_OBJS) \
273 $(MATH_OBJS) \
274 $(BASE_OBJS)
275
276 F_OBJS = $(COMMON_OBJS) \
277 $(FREELDR_OBJS)
278
279 S_OBJS = $(COMMON_OBJS) \
280 $(SETUPLDR_OBJS)
281
282 #############################################
283 # ALL THE OBJECTS
284 #
285 ALL_OBJS = $(COMMON_OBJS) \
286 $(FREELDR_OBJS) \
287 $(SETUPLDR_OBJS)
288
289
290 #############################################
291 # SET THE VPATH SO MAKE CAN FIND THE SOURCE FILES
292 #
293 VPATH = $(SRCDIR)/ \
294 $(SRCDIR)/arch/$(TARGET) \
295 $(SRCDIR)/rtl \
296 $(SRCDIR)/fs \
297 $(SRCDIR)/ui \
298 $(SRCDIR)/reactos \
299 $(SRCDIR)/comm \
300 $(SRCDIR)/disk \
301 $(SRCDIR)/mm \
302 $(SRCDIR)/cache \
303 $(SRCDIR)/inifile \
304 $(SRCDIR)/video \
305 $(SRCDIR)/math \
306 $(SRCDIR)/include
307
308 #############################################
309
310 all : freeldr.sys setupldr.sys
311 @echo Make ALL done.
312
313 #############################################
314
315 freeldr.sys : $(ALL_OBJS)
316 @echo ===================================================== LINKING $@
317 # @$(LD) -N -Ttext=0x8000 --oformat=binary -s -o freeldr.sys $(F_OBJS)
318 @$(LD) $(LFLAGS) -Map freeldr.map -o freeldr.exe $(F_OBJS)
319 # @$(CC) -Wl,-Ttext=0x8000,-N,-Map,freeldr.map -o freeldr.exe $(F_OBJS)
320 @$(NM) --numeric-sort freeldr.exe > freeldr.sym
321 @$(OBJCOPY) -O binary freeldr.exe freeldr.sys
322
323 #############################################
324
325 setupldr.sys : $(ALL_OBJS)
326 @echo ===================================================== LINKING $@
327 # @$(LD) -N -Ttext=0x8000 --oformat=binary -s -o setupldr.sys $(S_OBJS)
328 @$(LD) $(LFLAGS) -Map setupldr.map -o setupldr.exe $(S_OBJS)
329 @$(NM) --numeric-sort setupldr.exe > setupldr.sym
330 @$(OBJCOPY) -O binary setupldr.exe setupldr.sys
331
332 #############################################
333
334 %.o :: %.c
335 @echo ===================================================== Compiling $*
336 @$(CC) $(CFLAGS) -o $@ -c $<
337 @$(DEPTOOL) $*.d
338
339 %.o :: %.S
340 @echo ===================================================== Assembling $*
341 @$(CC) $(CFLAGS) -o $@ -c $<
342 @$(DEPTOOL) $*.d
343
344 %.o :: %.asm
345 @echo ===================================================== Assembling $*
346 @$(NASM_CMD) $(NASMFLAGS) -o $@ $<
347
348 #############################################
349
350 # Include the automagically generated dependencies
351 -include $(ALL_OBJS:%.o=%.d)
352
353 #############################################
354
355 endif