summaryrefslogtreecommitdiffstats
path: root/src/Makefile
blob: 691f2c488cc5d8c3efed068922ea6d6342159b22 (plain) (blame)
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
# Initialise variables that get added to throughout the various Makefiles
#
MAKEDEPS	:= Makefile .toolcheck
SRCDIRS		:=
SRCS		:=
NON_AUTO_SRCS	:=
DRIVERS		:=
ROMS		:=
MEDIA		:=
NON_AUTO_MEDIA	:=

# Grab the central Config file.
#
MAKEDEPS	+= Config
include Config

# If no architecture is specified in Config or on the command-line,
# use that of the build machine.
#
ifndef ARCH
ARCH		:= $(shell uname -m | sed -e s,i[3456789]86,i386,)
endif

# Drag in architecture-specific Config
#
MAKEDEPS	+= arch/$(ARCH)/Config
include arch/$(ARCH)/Config

# If invoked with no build target, print out a helpfully suggestive
# message.
#
noargs : blib
	@echo '===================================================='
	@echo 'No target specified. To specify a target, do: '
	@echo
	@echo '    $(MAKE) bin/<rom-name>.<output-format> '
	@echo
	@echo 'where <output-format> is one of [z]{$(MEDIA) }'
	@echo
	@echo 'or: '
	@echo
	@echo '    $(MAKE) all<output-format>s'
	@echo
	@echo 'to generate all possible images of format <output-format>'
	@echo
	@echo 'For example, '
	@echo
	@echo '    make allzroms '
	@echo
	@echo 'will generate all possible .zrom (rom burnable) images, and'
	@echo
	@echo '    make allzdsks'
	@echo
	@echo 'will generate all possible .zdsk (bootable floppy) images, or'
	@echo
	@echo '===================================================='
	@exit 1

# Locations of utilities
#
HOST_CC		?= gcc
CPP		?= gcc -E -Wp,-Wall
RM		?= rm -f
TOUCH		?= touch
MKDIR		?= mkdir
PERL		?= /usr/bin/perl
CC		?= $(CROSS_COMPILE)gcc
AS		?= $(CROSS_COMPILE)as
LD		?= $(CROSS_COMPILE)ld
SIZE		?= $(CROSS_COMPILE)size
AR		?= $(CROSS_COMPILE)ar
RANLIB		?= $(CROSS_COMPILE)ranlib
OBJCOPY		?= $(CROSS_COMPILE)objcopy
PARSEROM	?= $(PERL) ./util/parserom.pl
MAKEROM		?= $(PERL) ./util/makerom.pl
NRV2B		?= ./util/nrv2b

# Location to place generated files
#
BIN		?= bin

# Library containing all compiled objects
BLIB	= $(BIN)/blib.a

# Common flags
#
CFLAGS		+= -I include -I arch/$(ARCH)/include -DARCH=$(ARCH)
CFLAGS		+= -Os -ffreestanding
CFLAGS		+= -Wall -W -Wno-format
CFLAGS		+= $(EXTRA_CFLAGS)
ASFLAGS		+= $(EXTRA_ASFLAGS)
LDFLAGS		+= $(EXTRA_LDFLAGS)

# CFLAGS for specific object types
#
CFLAGS_c	+= 
CFLAGS_S 	+= -DASSEMBLY

# Base object name of the current target
#
OBJECT		= $(firstword $(subst ., ,$(@F)))

# CFLAGS for specific object files.  You can define
# e.g. CFLAGS_rtl8139, and have those flags automatically used when
# compiling bin/rtl8139.o.
#
OBJ_CFLAGS	= $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
$(BIN)/%.flags :
	@echo $(OBJ_CFLAGS)

# Rules for specific object types.
#
COMPILE_c	= $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
RULE_c		= $(COMPILE_c) -c $< -o $@
RULE_c_to_dbg.o	= $(COMPILE_c) -DDEBUG_$(OBJECT) -c $< -o $@
RULE_c_to_c	= $(COMPILE_c) -E -c $< > $@
RULE_c_to_s	= $(COMPILE_c) -S -c $< -o $@ 

PREPROCESS_S	= $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
ASSEMBLE_S	= $(AS) $(ASFLAGS)
RULE_S		= $(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
RULE_S_to_s	= $(PREPROCESS_S) $< > $@

DEBUG_TARGETS	+= dbg.o c s

# SRCDIRS lists all directories containing source files.
#
SRCDIRS		+= core drivers/bus drivers/net
# drivers/disk

# NON_AUTO_SRCS lists files that are excluded from the normal
# automatic build system.
#
NON_AUTO_SRCS	+= core/elf_loader.c
NON_AUTO_SRCS	+= drivers/net/prism2.c

# Rules for finalising files.  TGT_MAKEROM_FLAGS is defined as part of
# the automatic build system and varies by target; it includes the
# "-p 0x1234,0x5678" string to set the PCI IDs.
#
FINALISE_rom = $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
	       -i$(IDENT) $@

# Drag in architecture-specific Makefile
#
MAKEDEPS	+= arch/$(ARCH)/Makefile
include arch/$(ARCH)/Makefile

# Drag in the automatic build system and other housekeeping functions
MAKEDEPS	+= Makefile.housekeeping
include Makefile.housekeeping