forked from haileys/doslinux
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
176 lines (139 loc) · 5.3 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
CPU ?= i386
ARCH ?= $(CPU)-linux-musl
CC = $(ARCH)-gcc
CFLAGS ?= -m32 -static -Os -Wall -Wextra
NASM ?= nasm
CORES ?= $(shell nproc)
LINUX ?= 5.8.9
BUSYBOX ?= 1.35.0
DOSLINUX = 0.0.2
DSL_ZIP = DSL$(subst .,,$(DOSLINUX))B.ZIP
HDD_BASE ?= hdd.base.img
LINUX_BZIMAGE = deps/linux-$(LINUX)/arch/x86/boot/bzImage
BUSYBOX_BIN = deps/busybox
LINUX_URL = https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$(LINUX).tar.gz
#BUSYBOX_URL = https://www.busybox.net/downloads/binaries/$(BUSYBOX)-i686-linux-musl/busybox
BUSYBOX_URL = https://www.busybox.net/downloads/busybox-$(BUSYBOX).tar.bz2
SHELL := $(shell which bash)
.PHONY: all
all: ## Default target which builds a DSLxxxB.ZIP file with doslinux
all: dist
# beep when done
@for Z in {1..3} ; do ( echo -en "\a" && sleep 0.1 ) ; done
.PHONY: clean
clean: ## Remove any doslinux binaries, object files, ZIP file prep
clean:
rm -rfv hdd.img doslinux.com init/init init/*.o deps/* \
$(DSL_ZIP) DOSLINUX/BZIMAGE DOSLINUX/INIT DOSLINUX/BUSYBOX \
DOSLINUX/DSL.COM
ultraclean: clean
sudo rm -rfv /usr/local/bin/$(ARCH)-* /usr/local/lib/gcc/$(ARCH) /usr/local/$(ARCH)
$(HDD_BASE):
dd if=/dev/zero of=$@ bs=1M count=500 status=progress
hdd.img: ## Old default target which requires an input HDD image $(HDD_BASE) and then modifies with mtools to include doslinux
hdd.img: $(HDD_BASE) doslinux.com init/init $(LINUX_BZIMAGE) $(BUSYBOX_BIN)
cp -v $(HDD_BASE) hdd.img
MTOOLSRC=mtoolsrc mmd C:/doslinux
MTOOLSRC=mtoolsrc mcopy doslinux.com C:/doslinux/dsl.com
MTOOLSRC=mtoolsrc mcopy init/init C:/doslinux/init
MTOOLSRC=mtoolsrc mcopy $(LINUX_BZIMAGE) C:/doslinux/bzimage
MTOOLSRC=mtoolsrc mcopy $(BUSYBOX_BIN) C:/doslinux/busybox
MTOOLSRC=mtoolsrc mmd C:/doslinux/rootfs
doslinux.com: doslinux.asm
$(NASM) -o $@ -f bin $<
init/init: init/init.o init/vm86.o init/panic.o init/kbd.o init/term.o
$(CC) $(CFLAGS) -o $@ $^
init/%.o: init/%.c init/*.h /usr/local/bin/$(CC)
$(CC) $(CFLAGS) -o $@ -c $<
deps/:
mkdir -pv $@
#deps/musl-cross-make: deps/
deps/musl-cross-make deps/musl-cross-make/Makefile: deps/
cd deps && \
git clone --depth=1 https://github.com/richfelker/musl-cross-make.git
musl-cross-make-config-doslinux: Makefile
echo "TARGET = $(ARCH)" > $@
echo "OUTPUT = /usr/local" >> $@
# FIXME: This doesn't work the way musl-cross-make docs say it should
# echo "COMMON_CONFIG += CC=\"$(ARCH)-linux-musl-gcc -static --static\"" >> $@
# echo "COMMON_CONFIG += CXX=\"$(ARCH)-linux-musl-g++ -static --static\"" >> $@
echo "COMMON_CONFIG += CFLAGS=\"-g0 -Os -static --static\"" >> $@
echo "COMMON_CONFIG += CXXFLAGS=\"-g0 -Os -static --static\"" >> $@
echo "COMMON_CONFIG += LDFLAGS=\"-s\"" >> $@
deps/musl-cross-make/config.mak: musl-cross-make-config-doslinux deps/musl-cross-make/Makefile
cp -v musl-cross-make-config-doslinux $@
deps/musl-cross-make/build/local/$(ARCH)/obj_gcc/gcc/xgcc: deps/musl-cross-make/config.mak
cd deps/musl-cross-make && \
make -j$(CORES)
/usr/local/bin/$(CC): deps/musl-cross-make/build/local/$(ARCH)/obj_gcc/gcc/xgcc
@echo " ## # # ## ###"
@echo "# # # # # # #"
@echo " # # # # # # #"
@echo " # # # # # # #"
@echo "## ### ## ###"
@echo
@for Z in {1..3} ; do ( echo -en "\a" && sleep 0.1 ) ; done
cd deps/musl-cross-make && \
sudo make -j$(CORES) install
deps/linux-$(LINUX).tar.gz:
wget -O $@ $(LINUX_URL)
deps/linux-$(LINUX)/Makefile: deps/linux-$(LINUX).tar.gz
tar zxvf $< -C deps/
deps/linux-$(LINUX)/.config: deps/linux-$(LINUX)/Makefile linux-config-doslinux
cp -v linux-config-doslinux $@
$(LINUX_BZIMAGE): deps/linux-$(LINUX)/.config
cd deps/linux-$(LINUX) && \
make -j$(CORES) ARCH=x86 CROSS_COMPILE=$(ARCH)-
deps/busybox-$(BUSYBOX).tar.bz2:
wget -O $@ $(BUSYBOX_URL)
deps/busybox-$(BUSYBOX): deps/busybox-$(BUSYBOX).tar.bz2
tar jxvf $< -C deps/
deps/busybox-$(BUSYBOX)/.config: deps/busybox-$(BUSYBOX)
cp -v busybox-config $@
#$(BUSYBOX_BIN):
# wget -O $@ $(BUSYBOX_URL)
$(BUSYBOX_BIN): deps/busybox-$(BUSYBOX)/.config
cd deps/busybox-$(BUSYBOX) && \
make -j$(CORES) ARCH=x86 CROSS_COMPILE=$(ARCH)-
cp -v deps/busybox-$(BUSYBOX)/busybox $@
.PHONY: dist
dist: $(DSL_ZIP)
DOSLINUX.VER: Makefile
echo $(DOSLINUX) > $@
DOSLINUX/ROOTFS/DOSLINUX.VER: DOSLINUX.VER
cp -v $< $@
DOSLINUX/DSL.COM: doslinux.com
cp -v $< $@
DOSLINUX/INIT: init/init
cp -v $< $@
DOSLINUX/BZIMAGE: $(LINUX_BZIMAGE)
cp -v $< $@
DOSLINUX/BUSYBOX: $(BUSYBOX_BIN)
cp -v $< $@
$(DSL_ZIP): DOSLINUX/ROOTFS/DOSLINUX.VER DOSLINUX/BUSYBOX
$(DSL_ZIP): DOSLINUX/INIT DOSLINUX/DSL.COM DOSLINUX/BZIMAGE
zip -9vvr $@ DOSLINUX/
######################################################################
.PHONY: showconfig
showconfig: ## Shows the configuration variables for this Makefile and their current values
showconfig: p-DOSLINUX p-DSL_ZIP p-CORES p-CPU p-ARCH p-CC p-NASM
showconfig: p-LINUX p-LINUX_BZIMAGE p-LINUX_URL p-BUSYBOX
showconfig: p-BUSYBOX_BIN p-BUSYBOX_URL p-HDD_BASE p-SHELL
.PHONY: gstat
gstat:
git status
.PHONY: gpush
gpush:
git commit
git push
define newline # a literal \n
endef
# Makefile debugging trick:
# call print-VARIABLE to see the runtime value of any variable
# (hardened a bit against some special characters appearing in the output)
p-%:
@echo '$*=$(subst ','\'',$(subst $(newline),\n,$($*)))'
.PHONY: p-*
.PHONY: help
help: ## This help target
@RE='^[a-zA-Z0-9 .-_+]*:.*##' ; while read line ; do [[ "$$line" =~ $$RE ]] && echo "$$line" ; done <Makefile ; RE=''