summaryrefslogtreecommitdiffstats
path: root/qemu/roms/openhackware/Makefile
blob: 68ed7d2cf8f4a23f236345ba261fe4a86423f592 (plain)
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#
#  <Makefile>
#     
#  Makefile for Open Hack'Ware.
#  
#  Copyright (C) 2004-2005 Jocelyn Mayer (l_indien@magic.fr)
#  
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License V2
#   as published by the Free Software Foundation
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

#DEBUG=1

CROSS_COMPILE?=powerpc-linux-
CC:= $(CROSS_COMPILE)gcc -m32
LD:= $(CROSS_COMPILE)ld -m elf32ppc
OBJCOPY:= $(CROSS_COMPILE)objcopy
MKDIR:= mkdir
CAT:= cat
TAR:= tar
RM:= rm -rf --
ECHO:= echo
ifeq ("$(DEBUG)", "1")
DEBUG:= $(ECHO)
else
DEBUG:= \#
endif

BUILD_DATE:= $(shell date -u +%F)
BUILD_TIME:= $(shell date -u +%T)

OBJDIR:= .objs
DISTDIR:= .
SRCDIR:= src

CC_BASE:= $(shell $(CC) -print-search-dirs | grep install | sed -e 's/.*\ //')
CFLAGS= -Wall -W -Werror -O2 -g -fno-builtin -fno-common -nostdinc -mregnames
# Disable a few warnings that would just create needless code churn
CFLAGS+= -Wno-pointer-sign -Wno-unused-but-set-variable
CFLAGS+= -DBUILD_DATE=$(BUILD_DATE) -DBUILD_TIME=$(BUILD_TIME)
CFLAGS+= -I$(SRCDIR)/ -I$(SRCDIR)/libc/include -I$(CC_BASE)/include
CFLAGS+= -I$(SRCDIR)/dev -I$(SRCDIR)/dev/block -I$(SRCDIR)/dev/char
CFLAGS+= -I$(SRCDIR)/dev/bus
LDFLAGS= -O2 -g -nostdlib

BIOS_IMAGE_BITS:= 20
BIOS_IMAGE_SIZE:= $(shell echo $$(( 1 << $(BIOS_IMAGE_BITS) )) )

BOOT_SIZE      := 0x00000200
VECTORS_BASE   := 0x00000000
VECTORS_SIZE   := $(shell echo $$(( 0x00004000 - $(BOOT_SIZE) )) )
VECTORS_END    := $(shell echo $$(( $(VECTORS_BASE) + $(VECTORS_SIZE) )) )
BIOS_BASE      := 0x05800000
BIOS_SIZE      := $(shell echo $$(( $(BIOS_IMAGE_SIZE) - $(BOOT_SIZE) - $(VECTORS_SIZE) )) )
BIOS_END       := $(shell echo $$(( $(BIOS_BASE) + $(BIOS_SIZE) )) )

LOAD_IMAGE_BASE:= 0x04000000

# boot.bin build options
boot.o_CFLAGS:= -DBOOT_SIZE=$(BOOT_SIZE)
boot.o_CFLAGS+= -DVECTORS_BASE=$(VECTORS_BASE) -DVECTORS_SIZE=$(VECTORS_SIZE)
boot.o_CFLAGS+= -DBIOS_IMAGE_BITS=$(BIOS_IMAGE_BITS)
boot.out_LDFLAGS+= -T $(SRCDIR)/boot.ld
# vectors.bin build options
vectors.o_CFLAGS:= -DBIOS_BASE=$(BIOS_BASE) -DBIOS_SIZE=$(BIOS_SIZE)
vectors.out_LDFLAGS+= -T $(SRCDIR)/vectors.ld
vectors.bin_OPTIONS:= --pad-to $(VECTORS_END)
# main.bin build options
main.o_CFLAGS:= -DLOAD_IMAGE_BASE=$(LOAD_IMAGE_BASE)
main.out_LDFLAGS:= -T $(SRCDIR)/main.ld
main.out_OBJS:= main.o bootinfos.o bloc.o pci.o of.o start.o nvram.o vga.o mm.o char.o
main.out_OBJS:= $(addprefix $(OBJDIR)/, $(main.out_OBJS))
# Pseudo-libc objects
FORMAT_FUNCS:= _vprintf printf sprintf snprintf vprintf vsprintf vsnprintf
FORMAT_FUNCS+= dprintf vdprintf
MEM_FUNCS:= memcpy memccpy mempcpy memmove memcmove mempmove
MEM_FUNCS+= memset memcmp memchr rawmemchr memrchr memmem
STR_FUNCS:= strcpy strdup strndup stpcpy stpncpy strcat strncat
STR_FUNCS+= strcmp strcasecmp strncmp strncasecmp strchr strchrnul strrchr
STR_FUNCS+= basename dirname
STR_FUNCS+= strlen strnlen
MODULES:= format mem str
format_OBJS:=$(addsuffix .o, $(FORMAT_FUNCS))
mem_OBJS:=$(addsuffix .o, $(MEM_FUNCS))
str_OBJS:=$(addsuffix .o, $(STR_FUNCS))
pseudo_libc_OBJS:= malloc.o errno.o $(format_OBJS) $(mem_OBJS) $(str_OBJS)
#pseudo_libc_OBJS:= errno.o $(format_OBJS) $(mem_OBJS) $(str_OBJS)
main.out_OBJS+= $(addprefix $(OBJDIR)/, $(pseudo_libc_OBJS))
# libexec objects
libexec_OBJS:= core.o elf.o xcoff.o macho.o chrp.o prep.o pef.o
main.out_OBJS+= $(addprefix $(OBJDIR)/exec_, $(libexec_OBJS))
# libfs objects
libfs_OBJS:= core.o raw.o ext2.o isofs.o hfs.o
main.out_OBJS+= $(addprefix $(OBJDIR)/fs_, $(libfs_OBJS))
# libpart objects
libpart_OBJS:= core.o apple.o isofs.o prep.o
main.out_OBJS+= $(addprefix $(OBJDIR)/part_, $(libpart_OBJS))
# char devices drivers
chardev_OBJS:= pckbd.o kbdadb.o kbd.o
# bloc devices drivers
blocdev_OBJS:=
# devices drivers
dev_OBJS:= $(addprefix bloc_, $(blocdev_OBJS))
dev_OBJS+= $(addprefix char_, $(chardev_OBJS))
main.out_OBJS+= $(addprefix $(OBJDIR)/dev_, $(dev_OBJS))

CUR= $(notdir $@)
CFLAGS+= $($(CUR)_CFLAGS)
LDFLAGS+= $($(CUR)_LDFLAGS)

BIN_TARGETS:= $(OBJDIR)/vectors.bin $(OBJDIR)/main.bin $(OBJDIR)/boot.bin
TARGET:= ppc_rom.bin
main.bin_OPTIONS:= --gap-fill 0xFF --pad-to $(BIOS_END)

CURDIR:= $(shell basename `pwd`)
SOURCES:= boot.S vectors.S start.S main.c of.c
SOURCES+= vga.c vgafont.h bootinfos.c nvram.c file.c fs.c part.c bloc.c pci.c bios.h
LD_SCRIPTS:= boot.ld vectors.ld main.ld
MISC_FILES:= Makefile COPYING README Changelog Timestamp
SVN_DIRS:= $(shell find . -type d -name .svn)
TARBALL:= OpenHackWare.tar.bz2
TARFILES:= $(addprefix $(SRCDIR)/, $(SOURCES) $(LD_SCRIPTS)) $(MISC_FILES)
SVN_TARBALL:= OpenHackWare_svn.tar.bz2
DISTFILE:= OpenHackWare_bin.tar.bz2

#all: print
all: $(OBJDIR) $(DISTDIR) $(addprefix $(DISTDIR)/, $(TARGET))

dist: all $(CURDIR)/Timestamp
	cd $(DISTDIR) && $(TAR) -cjf $(DISTFILE) $(DISTDIR)/$(TARGET) Timestamp

print:
	@$(DEBUG) "BOOT_SIZE    = $(BOOT_SIZE)"
	@$(DEBUG) "VECTORS_BASE = $(VECTORS_BASE)"
	@$(DEBUG) "VECTORS_SIZE = $(VECTORS_SIZE)"
	@$(DEBUG) "VECTORS_END  = $(VECTORS_END)"
	@$(DEBUG) "BIOS_BASE    = $(BIOS_BASE)"
	@$(DEBUG) "BIOS_SIZE    = $(BIOS_SIZE)"
	@$(DEBUG) "BIOS_END     = $(BIOS_END)"

$(OBJDIR) $(DISTDIR):
	@$(MKDIR) $@

$(DISTDIR)/$(TARGET): $(BIN_TARGETS)
	$(CAT) $^ > $@

$(OBJDIR)/%.bin: $(OBJDIR)/%.out
	$(OBJCOPY) -O binary $($(notdir $@)_OPTIONS) $< $@

$(OBJDIR)/%.out: $(OBJDIR)/%.o $(SRCDIR)/%.ld
	$(LD) $(LDFLAGS) -o $@ $<

$(OBJDIR)/main.out: $(main.out_OBJS) $(SRCDIR)/main.ld
	$(LD) $(LDFLAGS) -o $@ $(main.out_OBJS)

$(OBJDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/bios.h
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -o $@ $<

$(OBJDIR)/%.o: $(SRCDIR)/%.S $(SRCDIR)/bios.h
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -Wa,-mregnames -o $@ $<

	$(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<

# Pseudo libc objects
$(OBJDIR)/%.o: $(SRCDIR)/libc/src/%.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -o $@ $<

$(OBJDIR)/mem%.o: $(SRCDIR)/libc/src/mem.c
	$(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<

$(OBJDIR)/rawmemchr.o: $(SRCDIR)/libc/src/mem.c
	$(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<

$(OBJDIR)/str%.o: $(SRCDIR)/libc/src/str.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<

$(OBJDIR)/stp%.o: $(SRCDIR)/libc/src/str.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<

$(OBJDIR)/basename.o: $(SRCDIR)/libc/src/str.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<

$(OBJDIR)/dirname.o: $(SRCDIR)/libc/src/str.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<

$(OBJDIR)/%rintf.o: $(SRCDIR)/libc/src/format.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<

# libexec objects
$(OBJDIR)/exec_%.o: $(SRCDIR)/libexec/%.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -o $@ $<

# libfs objects
$(OBJDIR)/fs_%.o: $(SRCDIR)/libfs/%.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -o $@ $<

# libpart objects
$(OBJDIR)/part_%.o: $(SRCDIR)/libpart/%.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -o $@ $<

# Devices drivers
$(OBJDIR)/dev_%.o: $(SRCDIR)/dev/%.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -o $@ $<
# Char devices drivers
$(OBJDIR)/dev_char_%.o: $(SRCDIR)/dev/char/%.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -o $@ $<
# Bloc devices drivers
$(OBJDIR)/dev_bloc_%.o: $(SRCDIR)/dev/bloc/%.c
	@$(DEBUG) "CFLAGS  = $(CFLAGS)"
	$(CC) -c $(CFLAGS) -o $@ $<

# Other targets
tarball: $(CURDIR)/Timestamp
	cd .. && $(TAR) -cjf $(CURDIR)/$(TARBALL) \
                             $(addprefix $(CURDIR)/, $(TARFILES))

svntarball: $(CURDIR)/Timestamp
	cd .. && $(TAR) -cjf $(CURDIR)/$(SVN_TARBALL) \
                             $(addprefix $(CURDIR)/, $(TARFILES) $(SVN_DIRS))

$(CURDIR)/Timestamp: force
	@cd .. && echo "$(BUILD_DATE) at $(BUILD_TIME)" > $@

clean:
	$(RM) $(OBJDIR) $(addprefix $(DISTDIR)/, $(TARGETS))
	$(RM) $(DISTFILE) $(CURDIR)/$(TARBALL)

cleansrc: clean
	$(RM) *~ src/*~ .*~ src/.*~

# Keep all intermediary files
.PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.out

.PHONY: all dist print tarball clean cleansrc

force: