Let the right reset entry point jump to the currently wrong entry point
[openhackware.git] / Makefile
blob68ed7d2cf8f4a23f236345ba261fe4a86423f592
2 # <Makefile>
3 #
4 # Makefile for Open Hack'Ware.
5 #
6 # Copyright (C) 2004-2005 Jocelyn Mayer (l_indien@magic.fr)
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License V2
10 # as published by the Free Software Foundation
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #DEBUG=1
24 CROSS_COMPILE?=powerpc-linux-
25 CC:= $(CROSS_COMPILE)gcc -m32
26 LD:= $(CROSS_COMPILE)ld -m elf32ppc
27 OBJCOPY:= $(CROSS_COMPILE)objcopy
28 MKDIR:= mkdir
29 CAT:= cat
30 TAR:= tar
31 RM:= rm -rf --
32 ECHO:= echo
33 ifeq ("$(DEBUG)", "1")
34 DEBUG:= $(ECHO)
35 else
36 DEBUG:= \#
37 endif
39 BUILD_DATE:= $(shell date -u +%F)
40 BUILD_TIME:= $(shell date -u +%T)
42 OBJDIR:= .objs
43 DISTDIR:= .
44 SRCDIR:= src
46 CC_BASE:= $(shell $(CC) -print-search-dirs | grep install | sed -e 's/.*\ //')
47 CFLAGS= -Wall -W -Werror -O2 -g -fno-builtin -fno-common -nostdinc -mregnames
48 # Disable a few warnings that would just create needless code churn
49 CFLAGS+= -Wno-pointer-sign -Wno-unused-but-set-variable
50 CFLAGS+= -DBUILD_DATE=$(BUILD_DATE) -DBUILD_TIME=$(BUILD_TIME)
51 CFLAGS+= -I$(SRCDIR)/ -I$(SRCDIR)/libc/include -I$(CC_BASE)/include
52 CFLAGS+= -I$(SRCDIR)/dev -I$(SRCDIR)/dev/block -I$(SRCDIR)/dev/char
53 CFLAGS+= -I$(SRCDIR)/dev/bus
54 LDFLAGS= -O2 -g -nostdlib
56 BIOS_IMAGE_BITS:= 20
57 BIOS_IMAGE_SIZE:= $(shell echo $$(( 1 << $(BIOS_IMAGE_BITS) )) )
59 BOOT_SIZE := 0x00000200
60 VECTORS_BASE := 0x00000000
61 VECTORS_SIZE := $(shell echo $$(( 0x00004000 - $(BOOT_SIZE) )) )
62 VECTORS_END := $(shell echo $$(( $(VECTORS_BASE) + $(VECTORS_SIZE) )) )
63 BIOS_BASE := 0x05800000
64 BIOS_SIZE := $(shell echo $$(( $(BIOS_IMAGE_SIZE) - $(BOOT_SIZE) - $(VECTORS_SIZE) )) )
65 BIOS_END := $(shell echo $$(( $(BIOS_BASE) + $(BIOS_SIZE) )) )
67 LOAD_IMAGE_BASE:= 0x04000000
69 # boot.bin build options
70 boot.o_CFLAGS:= -DBOOT_SIZE=$(BOOT_SIZE)
71 boot.o_CFLAGS+= -DVECTORS_BASE=$(VECTORS_BASE) -DVECTORS_SIZE=$(VECTORS_SIZE)
72 boot.o_CFLAGS+= -DBIOS_IMAGE_BITS=$(BIOS_IMAGE_BITS)
73 boot.out_LDFLAGS+= -T $(SRCDIR)/boot.ld
74 # vectors.bin build options
75 vectors.o_CFLAGS:= -DBIOS_BASE=$(BIOS_BASE) -DBIOS_SIZE=$(BIOS_SIZE)
76 vectors.out_LDFLAGS+= -T $(SRCDIR)/vectors.ld
77 vectors.bin_OPTIONS:= --pad-to $(VECTORS_END)
78 # main.bin build options
79 main.o_CFLAGS:= -DLOAD_IMAGE_BASE=$(LOAD_IMAGE_BASE)
80 main.out_LDFLAGS:= -T $(SRCDIR)/main.ld
81 main.out_OBJS:= main.o bootinfos.o bloc.o pci.o of.o start.o nvram.o vga.o mm.o char.o
82 main.out_OBJS:= $(addprefix $(OBJDIR)/, $(main.out_OBJS))
83 # Pseudo-libc objects
84 FORMAT_FUNCS:= _vprintf printf sprintf snprintf vprintf vsprintf vsnprintf
85 FORMAT_FUNCS+= dprintf vdprintf
86 MEM_FUNCS:= memcpy memccpy mempcpy memmove memcmove mempmove
87 MEM_FUNCS+= memset memcmp memchr rawmemchr memrchr memmem
88 STR_FUNCS:= strcpy strdup strndup stpcpy stpncpy strcat strncat
89 STR_FUNCS+= strcmp strcasecmp strncmp strncasecmp strchr strchrnul strrchr
90 STR_FUNCS+= basename dirname
91 STR_FUNCS+= strlen strnlen
92 MODULES:= format mem str
93 format_OBJS:=$(addsuffix .o, $(FORMAT_FUNCS))
94 mem_OBJS:=$(addsuffix .o, $(MEM_FUNCS))
95 str_OBJS:=$(addsuffix .o, $(STR_FUNCS))
96 pseudo_libc_OBJS:= malloc.o errno.o $(format_OBJS) $(mem_OBJS) $(str_OBJS)
97 #pseudo_libc_OBJS:= errno.o $(format_OBJS) $(mem_OBJS) $(str_OBJS)
98 main.out_OBJS+= $(addprefix $(OBJDIR)/, $(pseudo_libc_OBJS))
99 # libexec objects
100 libexec_OBJS:= core.o elf.o xcoff.o macho.o chrp.o prep.o pef.o
101 main.out_OBJS+= $(addprefix $(OBJDIR)/exec_, $(libexec_OBJS))
102 # libfs objects
103 libfs_OBJS:= core.o raw.o ext2.o isofs.o hfs.o
104 main.out_OBJS+= $(addprefix $(OBJDIR)/fs_, $(libfs_OBJS))
105 # libpart objects
106 libpart_OBJS:= core.o apple.o isofs.o prep.o
107 main.out_OBJS+= $(addprefix $(OBJDIR)/part_, $(libpart_OBJS))
108 # char devices drivers
109 chardev_OBJS:= pckbd.o kbdadb.o kbd.o
110 # bloc devices drivers
111 blocdev_OBJS:=
112 # devices drivers
113 dev_OBJS:= $(addprefix bloc_, $(blocdev_OBJS))
114 dev_OBJS+= $(addprefix char_, $(chardev_OBJS))
115 main.out_OBJS+= $(addprefix $(OBJDIR)/dev_, $(dev_OBJS))
117 CUR= $(notdir $@)
118 CFLAGS+= $($(CUR)_CFLAGS)
119 LDFLAGS+= $($(CUR)_LDFLAGS)
121 BIN_TARGETS:= $(OBJDIR)/vectors.bin $(OBJDIR)/main.bin $(OBJDIR)/boot.bin
122 TARGET:= ppc_rom.bin
123 main.bin_OPTIONS:= --gap-fill 0xFF --pad-to $(BIOS_END)
125 CURDIR:= $(shell basename `pwd`)
126 SOURCES:= boot.S vectors.S start.S main.c of.c
127 SOURCES+= vga.c vgafont.h bootinfos.c nvram.c file.c fs.c part.c bloc.c pci.c bios.h
128 LD_SCRIPTS:= boot.ld vectors.ld main.ld
129 MISC_FILES:= Makefile COPYING README Changelog Timestamp
130 SVN_DIRS:= $(shell find . -type d -name .svn)
131 TARBALL:= OpenHackWare.tar.bz2
132 TARFILES:= $(addprefix $(SRCDIR)/, $(SOURCES) $(LD_SCRIPTS)) $(MISC_FILES)
133 SVN_TARBALL:= OpenHackWare_svn.tar.bz2
134 DISTFILE:= OpenHackWare_bin.tar.bz2
136 #all: print
137 all: $(OBJDIR) $(DISTDIR) $(addprefix $(DISTDIR)/, $(TARGET))
139 dist: all $(CURDIR)/Timestamp
140 cd $(DISTDIR) && $(TAR) -cjf $(DISTFILE) $(DISTDIR)/$(TARGET) Timestamp
142 print:
143 @$(DEBUG) "BOOT_SIZE = $(BOOT_SIZE)"
144 @$(DEBUG) "VECTORS_BASE = $(VECTORS_BASE)"
145 @$(DEBUG) "VECTORS_SIZE = $(VECTORS_SIZE)"
146 @$(DEBUG) "VECTORS_END = $(VECTORS_END)"
147 @$(DEBUG) "BIOS_BASE = $(BIOS_BASE)"
148 @$(DEBUG) "BIOS_SIZE = $(BIOS_SIZE)"
149 @$(DEBUG) "BIOS_END = $(BIOS_END)"
151 $(OBJDIR) $(DISTDIR):
152 @$(MKDIR) $@
154 $(DISTDIR)/$(TARGET): $(BIN_TARGETS)
155 $(CAT) $^ > $@
157 $(OBJDIR)/%.bin: $(OBJDIR)/%.out
158 $(OBJCOPY) -O binary $($(notdir $@)_OPTIONS) $< $@
160 $(OBJDIR)/%.out: $(OBJDIR)/%.o $(SRCDIR)/%.ld
161 $(LD) $(LDFLAGS) -o $@ $<
163 $(OBJDIR)/main.out: $(main.out_OBJS) $(SRCDIR)/main.ld
164 $(LD) $(LDFLAGS) -o $@ $(main.out_OBJS)
166 $(OBJDIR)/%.o: $(SRCDIR)/%.c $(SRCDIR)/bios.h
167 @$(DEBUG) "CFLAGS = $(CFLAGS)"
168 $(CC) -c $(CFLAGS) -o $@ $<
170 $(OBJDIR)/%.o: $(SRCDIR)/%.S $(SRCDIR)/bios.h
171 @$(DEBUG) "CFLAGS = $(CFLAGS)"
172 $(CC) -c $(CFLAGS) -Wa,-mregnames -o $@ $<
174 $(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<
176 # Pseudo libc objects
177 $(OBJDIR)/%.o: $(SRCDIR)/libc/src/%.c
178 @$(DEBUG) "CFLAGS = $(CFLAGS)"
179 $(CC) -c $(CFLAGS) -o $@ $<
181 $(OBJDIR)/mem%.o: $(SRCDIR)/libc/src/mem.c
182 $(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<
184 $(OBJDIR)/rawmemchr.o: $(SRCDIR)/libc/src/mem.c
185 $(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<
187 $(OBJDIR)/str%.o: $(SRCDIR)/libc/src/str.c
188 @$(DEBUG) "CFLAGS = $(CFLAGS)"
189 $(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<
191 $(OBJDIR)/stp%.o: $(SRCDIR)/libc/src/str.c
192 @$(DEBUG) "CFLAGS = $(CFLAGS)"
193 $(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<
195 $(OBJDIR)/basename.o: $(SRCDIR)/libc/src/str.c
196 @$(DEBUG) "CFLAGS = $(CFLAGS)"
197 $(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<
199 $(OBJDIR)/dirname.o: $(SRCDIR)/libc/src/str.c
200 @$(DEBUG) "CFLAGS = $(CFLAGS)"
201 $(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<
203 $(OBJDIR)/%rintf.o: $(SRCDIR)/libc/src/format.c
204 @$(DEBUG) "CFLAGS = $(CFLAGS)"
205 $(CC) $(CFLAGS) -D__USE_$(subst .o,,$(@F))__ -c -o $@ $<
207 # libexec objects
208 $(OBJDIR)/exec_%.o: $(SRCDIR)/libexec/%.c
209 @$(DEBUG) "CFLAGS = $(CFLAGS)"
210 $(CC) -c $(CFLAGS) -o $@ $<
212 # libfs objects
213 $(OBJDIR)/fs_%.o: $(SRCDIR)/libfs/%.c
214 @$(DEBUG) "CFLAGS = $(CFLAGS)"
215 $(CC) -c $(CFLAGS) -o $@ $<
217 # libpart objects
218 $(OBJDIR)/part_%.o: $(SRCDIR)/libpart/%.c
219 @$(DEBUG) "CFLAGS = $(CFLAGS)"
220 $(CC) -c $(CFLAGS) -o $@ $<
222 # Devices drivers
223 $(OBJDIR)/dev_%.o: $(SRCDIR)/dev/%.c
224 @$(DEBUG) "CFLAGS = $(CFLAGS)"
225 $(CC) -c $(CFLAGS) -o $@ $<
226 # Char devices drivers
227 $(OBJDIR)/dev_char_%.o: $(SRCDIR)/dev/char/%.c
228 @$(DEBUG) "CFLAGS = $(CFLAGS)"
229 $(CC) -c $(CFLAGS) -o $@ $<
230 # Bloc devices drivers
231 $(OBJDIR)/dev_bloc_%.o: $(SRCDIR)/dev/bloc/%.c
232 @$(DEBUG) "CFLAGS = $(CFLAGS)"
233 $(CC) -c $(CFLAGS) -o $@ $<
235 # Other targets
236 tarball: $(CURDIR)/Timestamp
237 cd .. && $(TAR) -cjf $(CURDIR)/$(TARBALL) \
238 $(addprefix $(CURDIR)/, $(TARFILES))
240 svntarball: $(CURDIR)/Timestamp
241 cd .. && $(TAR) -cjf $(CURDIR)/$(SVN_TARBALL) \
242 $(addprefix $(CURDIR)/, $(TARFILES) $(SVN_DIRS))
244 $(CURDIR)/Timestamp: force
245 @cd .. && echo "$(BUILD_DATE) at $(BUILD_TIME)" > $@
247 clean:
248 $(RM) $(OBJDIR) $(addprefix $(DISTDIR)/, $(TARGETS))
249 $(RM) $(DISTFILE) $(CURDIR)/$(TARBALL)
251 cleansrc: clean
252 $(RM) *~ src/*~ .*~ src/.*~
254 # Keep all intermediary files
255 .PRECIOUS: $(OBJDIR)/%.o $(OBJDIR)/%.out
257 .PHONY: all dist print tarball clean cleansrc
259 force: