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