-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
executable file
·148 lines (116 loc) · 3.36 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
SYSNAME=MYOS
SYSBIN=MYOS.BIN
SBINS=$(OUTPUT_DIR)/$(SYSBIN)
IMG_NAME=bos.img
OUTPUT_DIR=.
# defines for global use
include ./mk.defines
ARCH=i386
include mk.$(ARCH)
KERN_INCS = $(ARCH_INCS)
KERN_INCS +=-Iinclude
# source files
USER_SRC= $(shell ls user/*.c)
KERN_SRC = $(wildcard kernel/*.c)
SHELL_SRC= $(shell ls lib/*.c) $(shell ls lib/errno/*.c) $(shell ls blibc/*.c) $(shell ls apps/*.c)
HW_DEP_ASM_SRC=kernel/main.s kernel/osfunc.s
# object files
KERN_OBJS += $(KERN_SRC:.c=.o)
KERN_OBJS += $(ARCH_OBJS)
KERN_OBJS += $(SHELL_SRC:.c=.o)
KERN_OBJS += $(USER_SRC:.c=.o)
HW_DEP_ASM_OBJ = $(HW_DEP_ASM_SRC:.s=.o)
NASMW = nasm
LDSCRIPT := ld-script.lds
ifeq ($(KNAME),$(KNAME_OSX))
NASMW_LDFLAGS = -f elf
EXTRA_CFLAGS=-m32
else
EXTRA_CFLAGS=-m32
NASMW_LDFLAGS = -f elf32
endif
COMM_FLAGS=-nostdlib
COMM_LDFLAGS=--no-undefined -T $(LDSCRIPT) -Map $(SYSNAME).map
CFLAGS =$(EXTRA_CFLAGS) -I. $(KERN_INCS) -Iapps \
-Wall -fno-builtin -O0 -g
ifeq ($(KNAME),$(KNAME_CYGWIN))
# add some code for cygwin environment
textAddr=1000
LDFLAGS = $(COMM_FLAGS) -static -e _start -s -Ttext $(textAddr) -Map $(SYSNAME).map
else
LDFLAGS = \
$(COMM_FLAGS) -static -e _start \
$(COMM_LDFLAGS) -X
endif
COMM_OBJCOPYFLAGS=-R .pdr
OBJCOPYFLAGS = \
-I elf32-i386 \
-O binary $(COMM_OBJCOPYFLAGS) \
-R .note -R .note.gnu.build-id -R .comment -S
BOOT_LOADER=boot/boot.bin
OS_LOADER=LOADER.BIN
all: $(BOOT_LOADER) $(SYSBIN)
########################
# boot loader
########################
$(BOOT_LOADER):
make -C boot
$(OS_LOADER): loader/loader.s
nasm -o $@ $< -I include
########################
# bootable floppy image
########################
$(IMG_NAME): $(BOOT_LOADER)
$(DD) if=$(BOOT_LOADER) of=$@ seek=0 count=1
$(DD) if=/dev/zero of="$@" skip=1 seek=1 bs=512 count=$$((2880 - 1))
########################
# System binary
########################
# this needs the root permission to execute
package_by_mount: $(IMG_NAME) $(SYSBIN)
ls -la $(SYSBIN)
mkdir -p fda;\
mount -o loop $(IMG_NAME) fda -o fat=12;\
cp $(SYSBIN) fda;\
umount fda;\
rm -rf fda;
# I like this because use mcopy from mtools without root permission for packaging
package: $(OS_LOADER) $(IMG_NAME) $(SYSBIN)
mcopy -n -o -i "$(IMG_NAME)" "$(OS_LOADER)" ::
mcopy -n -o -i "$(IMG_NAME)" "$(SYSBIN)" ::
mdir -i "$(IMG_NAME)"
run: package
@#only support in well-setup Ubuntu and OSX(only tried 10.6.8)
make -C test IMG_NAME="../$(IMG_NAME)" QEMUEXTRA=$(QEMUEXTRA) \
QEMUMODEL=$(QEMUMODEL)
update: $(SYSBIN)
mcopy -n -o -i "$(IMG_NAME)" "$(SYSBIN)" ::
mdir -i "$(IMG_NAME)"
bin: $(SYSBIN)
hex:
hexdump -C $(IMG_NAME)
.c.o:
@if [ "$<" = "init.c" ] ; then \
echo $< with -save-temps || exit 1 ; \
$(CC) -c $(CFLAGS) $< -o $@ -save-temps || exit 1 ; \
else \
echo "building [$@]" ; \
$(CC) -c $(CFLAGS) $< -o $@ || exit 1 ; \
fi
# NASM + LD to ELF, objcopy to fat binary (Not working, it seems to be incompatible.)
MYOS.BIN: %.BIN: myos.elf ld-script.lds
@echo "convert $< to $@" ; \
$(OBJCOPY) $(OBJCOPYFLAGS) $< $@
myos.elf: $(HW_DEP_ASM_OBJ) $(KERN_OBJS)
@echo link [$@] ; $(LD) $(LDFLAGS) -o $@ $^
$(HW_DEP_ASM_OBJ) : %.o : %.s
@echo "building asm [$@]" ; \
$(NASMW) $(NASMW_LDFLAGS) $< -o $@ -Iinclude/
info:
@echo "PLATFORM=[$(KNAME)]"
clean:
@make -C boot clean
@rm -f $(IMG_NAME) *.elf *.img $(SYSBIN) *.o *.lst *.map $(KERN_OBJS) $(HW_DEP_ASM_OBJ) $(OS_LOADER)
@make -C test clean
ctags:
ctags -R .