This repository has been archived by the owner on Feb 6, 2019. It is now read-only.
/
makefile
226 lines (135 loc) · 7.05 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Makefile for Orion-X3/Orion-X4/mx and derivatives
# Written in 2011
# This makefile is licensed under the WTFPL
X_BUILD_FILE = .build.h
export QEMU := qemu-system-x86_64
export SYSROOT := $(shell pwd)/build/sysroot
export TOOLCHAIN := $(shell pwd)/build/toolchain
export CC := $(shell pwd)/build/toolchain/bin/x86_64-orionx-gcc
export CXX := $(shell pwd)/build/toolchain/bin/x86_64-orionx-g++
export AS := $(shell pwd)/build/toolchain/bin/x86_64-orionx-as
export LD := $(shell pwd)/build/toolchain/bin/x86_64-orionx-ld
export OBJCOPY := $(shell pwd)/build/toolchain/bin/x86_64-orionx-objcopy
export READELF := $(shell pwd)/build/toolchain/bin/x86_64-orionx-readelf
export STRIP := $(shell pwd)/build/toolchain/bin/x86_64-orionx-strip
export AR := $(shell pwd)/build/toolchain/bin/x86_64-orionx-ar
export RANLIB := $(shell pwd)/build/toolchain/bin/x86_64-orionx-ranlib
export MOUNTPATH := $(shell tools/getpath.sh)
export COMPRESS_UTIL := $(shell pwd)/tools/heatshrink
# we use clang only for the kernel, don't pollute makefiles
CXX_ = clang++
GXX_ = $(CXX)
FLXC = $(SYSROOT)/usr/local/bin/flaxc
GCCVERSION = 4.9.1
WARNINGS = -Wno-padded -Wno-c++98-compat-pedantic -Wno-c++98-compat -Wno-cast-align -Wno-unreachable-code -Wno-gnu -Wno-missing-prototypes -Wno-switch-enum -Wno-packed -Wno-missing-noreturn -Wno-float-equal -Wno-old-style-cast -Wno-exit-time-destructors -Wno-unused-macros -Wno-global-constructors -Wno-documentation-unknown-command -Wno-reserved-id-macro -Wno-c99-extensions
GWARNINGS = -Wno-padded -Wno-cast-align -Wno-unreachable-code -Wno-switch-enum -Wno-packed -Wno-missing-noreturn -Wno-float-equal -Wno-old-style-cast -Wno-unused-macros -Wno-unknown-pragmas -Wno-attributes
CXXFLAGS = -m64 -g -Weverything -msse3 -integrated-as -O2 -fno-omit-frame-pointer -fno-strict-aliasing -std=gnu++14 -ffreestanding -mno-red-zone -fno-exceptions -fno-rtti -I./source/Kernel/include -I./Libraries/Iris/HeaderFiles -I./Libraries/ -I$(SYSROOT)/usr/include -I$(SYSROOT)/usr/include/c++ -DORION_KERNEL=1 -target x86_64-elf -mcmodel=kernel -c
GXXFLAGS = -m64 -g -Wall -msse3 -O2 -fno-omit-frame-pointer -fno-strict-aliasing -std=gnu++14 -ffreestanding -mno-red-zone -fno-exceptions -fno-rtti -I./source/Kernel/include -I./Libraries/Iris/HeaderFiles -I./Libraries/ -I$(SYSROOT)/usr/include -I$(SYSROOT)/usr/include/c++ -DORION_KERNEL=1 -mcmodel=kernel -c
LDFLAGS = -z max-page-size=0x1000 -L$(SYSROOT)/usr/lib
MEMORY = 1024
SSRC = $(shell find source -iname "*.s")
CXXSRC = $(shell find source -iname "*.cpp")
SOBJ = $(SSRC:.s=.s.o)
CXXOBJ = $(CXXSRC:.cpp=.cpp.o)
CXXDEPS = $(CXXOBJ:.o=.d)
.DEFAULT_GOAL = all
-include $(CXXDEPS)
NUMFILES = $$(($(words $(CXXSRC)) + $(words $(SSRC))))
LIBRARIES = -liris -lrdestl -lkstl
OUTPUT = build/kernel64.elf
QEMU_FLAGS = -s -vga std -no-reboot -m $(MEMORY) -rtc base=utc -net nic,model=rtl8139 -net user -net dump,file=build/netdump.wcap -drive file=build/disk.img,format=raw
.PHONY: builduserspace buildlib mountdisk clean all cleandisk copyheader
run: build
@$(QEMU) -serial file:"build/serialout.log" $(QEMU_FLAGS) -monitor stdio
all: $(OUTPUT)
@# unmount??
@tools/unmountdisk.sh
@echo "# Starting QEMU"
@$(QEMU) -serial stdio $(QEMU_FLAGS) | tee build/serialout.log
-@rm -f build/.dmf
@# mount the disk again for inspection.
@tools/mountdisk.sh
debug: $(OUTPUT)
@# unmount??
@tools/unmountdisk.sh
@echo "# Starting QEMU"
@$(QEMU) -serial stdio -S $(QEMU_FLAGS) | tee build/serialout.log
-@rm -f build/.dmf
@# mount the disk again for inspection.
@tools/mountdisk.sh
build: $(OUTPUT)
# built
$(OUTPUT): mountdisk copyheader $(SYSROOT)/usr/lib/%.a $(SOBJ) $(CXXOBJ) $(FLAXMAINOBJ) builduserspace
@echo "\n# Linking [mx] object files"
@$(LD) $(LDFLAGS) -T kernel.ld -o build/kernel64.elf $(shell find source/Kernel -name "*.o") $(LIBRARIES)
@echo "# Building [fx] loader"
@$(LD) $(LDFLAGS) -T loader.ld -o build/fxloader64.elf source/Loader/Start.s.o $(shell find source/Loader -name "*.o" ! -name "Start.s.o")
@echo # Performing objcopy
@$(OBJCOPY) -g -O elf32-i386 build/fxloader64.elf build/fxloader.oxf
@cp build/fxloader.oxf $(shell tools/getpath.sh)/boot/fxloader.oxf
@echo # Copying any extra files
@cp -R build/diskroot/* $(shell tools/getpath.sh)/ || :
@# use objcopy to strip debug symbols from the final executable -- saves about 1.3mb
@$(OBJCOPY) -g $(OUTPUT) build/kernel64.uncompressed
@# @cp $(OUTPUT) build/kernel64.uncompressed
@echo "# Compressing kernel"
@$(COMPRESS_UTIL) -e -w 14 -l 6 build/kernel64.uncompressed build/kernel64
@# @cp build/kernel64.uncompressed build/kernel64
@printf "0: %.16x" $(shell cat build/kernel64.uncompressed | wc -c) | xxd -r -g 0 >> .size_file
@cat build/kernel64 >> .size_file
@mv .size_file build/kernel64
@echo "# Compressed"
@cp build/kernel64.uncompressed $(shell tools/getpath.sh)/System/Library/CoreServices/kernel64.uncompressed
@cp build/kernel64 $(shell tools/getpath.sh)/System/Library/CoreServices/kernel64
%.s.o: %.s
@if [ ! -a build.dmf ]; then tools/updatebuild.sh; fi;
@touch build/.dmf
@$(AS) $< -o $@
@$(eval DONEFILES += "S")
@printf "\r \r$(words $(DONEFILES)) / $(NUMFILES) ($(notdir $<))"
%.cpp.o: %.cpp
@if [ ! -a build.dmf ]; then tools/updatebuild.sh; fi;
@touch build/.dmf
@$(CXX_) $(CXXFLAGS) $(WARNINGS) -MMD -MP -o $@ $<
@# $(GXX_) $(GXXFLAGS) $(GWARNINGS) -MMD -MP -o $@ $<
@$(eval DONEFILES += "CPP")
@printf "\r \r$(words $(DONEFILES)) / $(NUMFILES) ($(notdir $<))"
builduserspace:
@printf "\n# Building userspace applications\n"
@$(MAKE) -C applications/
copyheader:
@mkdir -p $(SYSROOT)/usr/lib
@mkdir -p $(SYSROOT)/usr/include/c++
@rsync -cmar Libraries/libc/include/* $(SYSROOT)/usr/include/
@rsync -cmar Libraries/libm/include/* $(SYSROOT)/usr/include/
@rsync -cmar Libraries/Iris/HeaderFiles/* $(SYSROOT)/usr/include/iris/
@rsync -cmar Libraries/libsyscall/*.h $(SYSROOT)/usr/include/sys/
@rsync -cmar $(TOOLCHAIN)/x86_64-orionx/include/c++/$(GCCVERSION)/* $(SYSROOT)/usr/include/c++/
@rsync -cmar $(SYSROOT)/usr/include/c++/x86_64-orionx/bits/* $(SYSROOT)/usr/include/c++/bits/
@cp $(TOOLCHAIN)/x86_64-orionx/lib/*.a $(SYSROOT)/usr/lib/
@cp $(TOOLCHAIN)/lib/gcc/x86_64-orionx/4.9.1/libgcc.a $(SYSROOT)/usr/lib/
buildlib: $(SYSROOT)/usr/lib/%.a
@:
$(SYSROOT)/usr/lib/%.a:
@echo "# Building Libraries"
@$(MAKE) -C Libraries/
mountdisk:
@tools/mountdisk.sh
cleandisk:
@find $(MOUNTPATH) -name "*.mxa" | xargs rm -f
@find $(MOUNTPATH) -name "*.x" | xargs rm -f
cleanlib:
@find Libraries -name "*.a" | xargs rm -f
@find Libraries -name "*.o" | xargs rm -f
@find Libraries -name "*.cpp.d" | xargs rm -f
cleanall: cleandisk clean
@echo "# Cleaning directory tree"
@find Libraries -name "*.o" | xargs rm -f
@find Libraries -name "*.cpp.d" | xargs rm -f
@find Libraries -name "*.a" | xargs rm -f
@find applications -name "*.o" | xargs rm -f
# haha
clena: clean
clean:
@find source -name "*.o" | xargs rm -f
@find source -name "*.cpp.d" | xargs rm -f