Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Support for lwIP switch on/off in Makefile
[palacios.git] / geekos / build / Makefile
1 # Makefile for GeekOS kernel, userspace, and tools
2 #
3 #  Northwestern University 
4 # (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
5 # (c) 2008, Peter Dinda <pdinda@northwestern.edu> 
6 # (c) 2008, Lei Xia <xiaxlei@gmail.com>
7 # (c) 2008, The V3VEE Project <http://www.v3vee.org> 
8 #
9 # Based on GeekOS Makefile:
10 # Copyright (c) 2004,2005 David H. Hovemeyer <daveho@cs.umd.edu>
11 # $Revision: 1.71 $
12
13
14 # This is free software.  You are permitted to use,
15 # redistribute, and modify it as specified in the file "COPYING".
16
17 # Required software to build GeekOS:
18 # - GNU Make (http://www.gnu.org/software/make)
19 # - gcc 2.95.2 generating code for target (i386/ELF) and host platforms
20 # - nasm (http://nasm.sourceforge.net)
21 # - Perl5, AWK (any version), egrep
22 #
23 # Cygwin (http://cygwin.com) may be used to build GeekOS.
24 # Make sure that gcc, binutils, nasm, and perl are installed.
25
26 # NOTES:
27 # - This makefile has been written carefully to work correctly
28 #   with the -j (parallel make) option.  I regularly use "make -j 2"
29 #   to speed the build process on 2 processor systems.
30
31
32 # Base address of kernel
33 #
34 # Note: at top of memory minus three pages (GDT/TSS/IDT) 
35 # minus maximum size
36 #
37 #
38 # Note that the code will initially load at 0x10000
39 #
40 # The setup code needs to copy it up to this address and jump there
41 #
42 KERNEL_BASE_ADDR := 0x00100000
43
44 # Kernel entry point function
45 KERNEL_ENTRY = $(SYM_PFX)Main
46
47
48 PROJECT_ROOT := ..
49 V3_ROOT := $(PROJECT_ROOT)/../palacios
50 VPATH := $(PROJECT_ROOT)/src
51
52
53
54
55 #
56 #uIP, ON -- used, OFF -- not used
57 #
58 UIP=OFF
59
60 #
61 #LWIP, ON -- used, OFF -- not used
62 #
63 LWIP=OFF
64
65
66 #
67 # This is wrong for current cygwin - no changes needed
68 #
69 # Figure out if we're compiling with cygwin, http://cygwin.com
70 #
71
72 #SYSTEM_NAME := $(shell uname -s)
73 #ifeq ($(findstring CYGWIN,$(SYSTEM_NAME)),CYGWIN)
74 #SYM_PFX            := _
75 #EXTRA_C_OPTS       := -DNEED_UNDERSCORE -DGNU_WIN32
76 #EXTRA_NASM_OPTS    := -DNEED_UNDERSCORE
77 #NON_ELF_SYSTEM     := yes
78 #EXTRA_CC_USER_OPTS := -Dmain=geekos_main
79 #endif
80
81
82
83
84 # ----------------------------------------------------------------------
85 # Configuration -
86 #   Various options specifying how GeekOS should be built,
87 #   what source files to build, which user programs to build,
88 #   etc.  This is generally the only section of the makefile
89 #   that will need to be modified.
90 # ----------------------------------------------------------------------
91
92 # List of targets to build by default.
93 # These targets encompass everything needed to boot
94 # and run GeekOS.
95 ALL_TARGETS := vmm.img
96
97
98 # Kernel source files
99 KERNEL_C_SRCS := idt.c int.c trap.c irq.c io.c \
100         blockdev.c ide.c ne2k.c \
101         keyboard.c screen.c timer.c \
102         mem.c crc32.c \
103         gdt.c tss.c segment.c \
104         bget.c malloc.c \
105         synch.c kthread.c \
106         serial.c  reboot.c \
107         paging.c \
108         debug.c vmm_stubs.c  vm.c  pci.c\
109         queue.c  socket.c net.c ring_buffer.c \
110         main.c
111
112
113 # Kernel object files built from C source files
114 KERNEL_C_OBJS := $(KERNEL_C_SRCS:%.c=geekos/%.o)
115
116 # Kernel assembly files
117 KERNEL_ASM_SRCS := lowlevel.asm
118
119 KERNEL_GAS_SRCS := 
120
121 # Kernel object files build from assembler source files
122 KERNEL_ASM_OBJS := $(KERNEL_ASM_SRCS:%.asm=geekos/%.o) 
123
124 KERNEL_GAS_OBJS := $(KERNEL_GAS_SRCS:%.s=geekos/%.o)
125
126
127 # All kernel object files
128 KERNEL_OBJS := $(KERNEL_C_OBJS) \
129   $(KERNEL_ASM_OBJS) $(KERNEL_GAS_OBJS)
130
131 # Common library source files.
132 # This library is linked into both the kernel and user programs.
133 # It provides string functions and generic printf()-style
134 # formatted output.
135 COMMON_C_SRCS := fmtout.c string.c memmove.c
136
137 # Common library object files.
138 COMMON_C_OBJS := $(COMMON_C_SRCS:%.c=common/%.o)
139
140
141 V3_LD_FLAGS := -L./palacios/
142 #V3_LIBS := -lxed -lv3vee
143 V3_LIBS := ./palacios/libxed.a ./palacios/libv3vee.a ./palacios/libxed.a ./palacios/libv3vee.a
144
145
146 ifeq ($(UIP),ON)
147         UIP_C_SRCS := psock.c timer.c uip_arp.c uip.c uip-fw.c uiplib.c uip-neighbor.c uip-split.c resolv.c
148         UIP_C_OBJS := $(UIP_C_SRCS:%.c=net/%.o)
149 else
150         UIP_C_SRCS :=
151         UIP_C_OBJS :=   
152 endif
153
154 ifeq ($(LWIP),ON)
155         LWIP_OBJS := lwip/*.o
156         CC_LWIP_OPTS := -I$(PROJECT_ROOT)/include/lwip  -I$(PROJECT_ROOT)/include/lwip/ipv4 -I$(PROJECT_ROOT)/include/libc -DLWIP_DEBUG -DLWIP
157 else
158         LWIP_OBJS := 
159         CC_LWIP_OPTS :=
160 endif
161
162 TCPSTACK_OBJS := $(UIP_C_OBJS) $(LWIP_OBJS)
163
164
165 # ----------------------------------------------------------------------
166 # Tools -
167 #   This section defines programs that are used to build GeekOS.
168 # ----------------------------------------------------------------------
169
170 # Uncomment if cross compiling
171 TARGET_CC_PREFIX :=  $(PROJECT_ROOT)/../devtools/i386/bin/i386-elf-
172 #TARGET_CC_PREFIX :=  i386-elf-
173
174 # Target C compiler.  gcc 2.95.2 or later should work.
175 TARGET_CC := $(TARGET_CC_PREFIX)gcc
176 #TARGET_CC := $(TARGET_CC_PREFIX)gcc34 -m32
177
178 # Host C compiler.  This is used to compile programs to execute on
179 # the host platform, not the target (x86) platform.  On x86/ELF
180 # systems, such as Linux and FreeBSD, it can generally be the same
181 # as the target C compiler.
182 HOST_CC := gcc
183
184 # Target linker.  GNU ld is probably to only one that will work.
185 TARGET_LD := $(TARGET_CC_PREFIX)ld -melf_i386
186
187 # Target archiver
188 TARGET_AR := $(TARGET_CC_PREFIX)ar
189
190 # Target ranlib
191 TARGET_RANLIB := $(TARGET_CC_PREFIX)ranlib
192
193 # Target nm
194 TARGET_NM := $(TARGET_CC_PREFIX)nm
195
196 # Target objcopy
197 TARGET_OBJCOPY := $(TARGET_CC_PREFIX)objcopy
198
199 # Nasm (http://nasm.sourceforge.net)
200 NASM := $(PROJECT_ROOT)/../devtools/bin/nasm
201 #NASM := /opt/vmm-tools/bin/nasm
202
203 AS = as --32
204
205 # Tool to build PFAT filesystem images.
206 BUILDFAT := tools/builtFat.exe
207
208 # Perl5 or later
209 PERL := perl
210
211 # Pad a file so its size is a multiple of some unit (i.e., sector size)
212 PAD := $(PERL) $(PROJECT_ROOT)/scripts/pad
213
214 # Create a file filled with zeroes.
215 ZEROFILE := $(PERL) $(PROJECT_ROOT)/scripts/zerofile
216
217 # Calculate size of file in sectors
218 NUMSECS := $(PERL) $(PROJECT_ROOT)/scripts/numsecs
219
220
221 FD_SECTORS_PER_TRACK := $(PERL) $(PROJECT_ROOT)/scripts/numsecs_per_track
222
223
224 # ----------------------------------------------------------------------
225 # Definitions -
226 #   Options passed to the tools.
227 # ----------------------------------------------------------------------
228
229 # Flags used for all C source files
230 GENERAL_OPTS := -O -Wall $(EXTRA_C_OPTS) $(BOOT_FLAGS) -fPIC
231 CC_GENERAL_OPTS := $(GENERAL_OPTS) -Werror 
232
233 # Flags used for kernel C source files
234 CC_KERNEL_OPTS := -g -DGEEKOS -I$(PROJECT_ROOT)/include -I$(V3_ROOT)/include
235
236
237 # Flags user for kernel assembly files
238 NASM_KERNEL_OPTS := -I$(PROJECT_ROOT)/src/geekos/ -f elf $(EXTRA_NASM_OPTS)
239
240 # Flags used for common library and libc source files
241 CC_USER_OPTS := -I$(PROJECT_ROOT)/include -I$(PROJECT_ROOT)/include/libc \
242         $(EXTRA_CC_USER_OPTS) -I$(V3_ROOT)/include
243
244 # Flags passed to objcopy program (strip unnecessary sections from kernel.exe)
245 OBJCOPY_FLAGS := -R .dynamic -R .note -R .comment
246
247 # ----------------------------------------------------------------------
248 # Rules -
249 #   Describes how to compile the source files.
250 # ----------------------------------------------------------------------
251
252 # Compilation of kernel C source files
253
254 geekos/%.o : geekos/%.c
255         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS)  $(CC_LWIP_OPTS) $< -o geekos/$*.o
256
257
258 # Compilation of kernel assembly source files
259 geekos/%.o : geekos/%.asm
260         $(NASM) $(NASM_KERNEL_OPTS) $< -o geekos/$*.o
261
262
263 # Compilation of common library C source files
264 common/%.o : common/%.c
265         $(TARGET_CC) -c $(CC_GENERAL_OPTS) $(CC_USER_OPTS) $< -o common/$*.o
266
267
268 net/%.o : net/%.c
269         $(TARGET_CC) -c $(CC_GENERAL_OPTS)  $(CC_USER_OPTS) $< -o net/$*.o
270
271 # ----------------------------------------------------------------------
272 # Targets -
273 #   Specifies files to be built
274 # ----------------------------------------------------------------------
275
276 # Default target - see definition of ALL_TARGETS in Configuration section
277 all : $(ALL_TARGETS)
278
279
280 force_lwip:
281         (cd ../src/lwip/build; make clean; make)
282
283
284 #geekos/vmx_lowlevel.o: $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm
285 #       $(NASM) -O99 \
286 #       -f elf \
287 #               -I$(PROJECT_ROOT)/src/geekos/ \
288 #               $(PROJECT_ROOT)/src/geekos/vmx_lowlevel.asm \
289 #       -o $@
290
291
292 #geekos/test: geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o 
293 #       $(CC) geekos/test.o geekos/vmcs.o geekos/vmx_lowlevel.o  -o geekos/test
294
295 # Standard floppy image - just boots the kernel
296 fd.img : geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin
297         cat geekos/fd_boot.bin geekos/setup.bin geekos/kernel.bin > _temp
298         $(PAD) _temp 512
299         cp _temp fd.img
300
301
302 vmm.img: fd.img
303         cp fd.img vmm.img
304         $(PAD) vmm.img 1474560
305
306
307
308
309
310
311 # Floppy boot sector (first stage boot loader).
312 geekos/fd_boot.bin : geekos/setup.bin geekos/kernel.bin $(PROJECT_ROOT)/src/geekos/fd_boot.asm
313         $(NASM) -f bin \
314                 -I$(PROJECT_ROOT)/src/geekos/ \
315                 -DNUM_SETUP_SECTORS=`$(NUMSECS) geekos/setup.bin` \
316                 -DNUM_KERN_SECTORS=`$(NUMSECS) geekos/kernel.bin` \
317                 -DSECTORS_PER_TRACK=`$(FD_SECTORS_PER_TRACK) geekos/kernel.bin geekos/setup.bin` \
318                 $(PROJECT_ROOT)/src/geekos/fd_boot.asm \
319                 -o $@
320
321 # Setup program (second stage boot loader).
322 geekos/setup.bin : geekos/kernel.bin $(PROJECT_ROOT)/src/geekos/setup.asm
323         $(NASM) -f bin \
324                 -I$(PROJECT_ROOT)/src/geekos/ \
325                 -DENTRY_POINT=0x`egrep 'Main$$' geekos/kernel.syms |awk '{print $$1}'` \
326                 -DVMM_SIZE=`$(NUMSECS) geekos/kernel.bin` \
327                 $(PROJECT_ROOT)/src/geekos/setup.asm \
328                 -o $@
329         $(PAD) $@ 2048
330
331 # Loadable (flat) kernel image.
332 geekos/kernel.bin : geekos/kernel.exe
333         $(TARGET_OBJCOPY) $(OBJCOPY_FLAGS) -S -O binary geekos/kernel.exe geekos/kernel.bin
334         $(PAD) $@ 512
335
336 # The kernel executable and symbol map.
337 geekos/kernel.exe : $(KERNEL_OBJS) $(COMMON_C_OBJS) force_lwip
338         $(TARGET_LD) -o geekos/kernel.exe -Ttext $(KERNEL_BASE_ADDR) -e $(KERNEL_ENTRY) \
339                 $(V3_LD_FLAGS) \
340                 $(KERNEL_OBJS) $(COMMON_C_OBJS) $(TCPSTACK_OBJS) $(V3_LIBS) -b binary ./palacios/vm_kernel
341         $(TARGET_NM) geekos/kernel.exe > geekos/kernel.syms
342
343
344 force:
345
346
347 #vm_kernel: force
348 #       $(PAD) vm_kernel 512
349 #       @echo "VM kernel lives at 0x100000 and is" `$(NUMSECS) vm_kernel` "sectors long"
350
351
352
353
354 # Clean build directories of generated files
355 clean :
356         for d in geekos common libc user tools net; do \
357                 (cd $$d && rm -f *); \
358         done
359
360
361 # Build header file dependencies, so source files are recompiled when
362 # header files they depend on are modified.
363 depend : $(GENERATED_LIBC_SRCS)
364         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_KERNEL_OPTS) \
365                 $(KERNEL_C_SRCS:%.c=$(PROJECT_ROOT)/src/geekos/%.c) \
366                 | $(PERL) -n -e 's,^(\S),geekos/$$1,;print' \
367                 > depend.mak
368         $(TARGET_CC) -M $(CC_GENERAL_OPTS) $(CC_USER_OPTS) \
369                 $(COMMON_C_SRCS:%.c=$(PROJECT_ROOT)/src/common/%.c) \
370                 | $(PERL) -n -e 's,^(\S),common/$$1,;print' \
371                 >> depend.mak
372
373
374 # By default, there are no header file dependencies.
375 depend.mak :
376         touch $@
377
378 include depend.mak