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