Commit | Line | Data |
---|---|---|
196ba1fc PH |
1 | # New Makefile for SIMH 3.8 |
2 | # Philipp Hachtmann | |
3 | # | |
4 | ||
5 | ||
6 | ################################################################################ | |
7 | ||
8 | # Find out something about the system we build for. | |
9 | # This process is ugly and should be revisited! | |
10 | ||
11 | BUILD=linux | |
12 | ||
13 | ifneq ($(WIN32),) | |
14 | BUILD=win32 | |
15 | endif | |
16 | ||
17 | ifneq (,$(findstring solaris,$(OSTYPE))) | |
18 | BUILD=solaris | |
19 | endif | |
20 | ||
21 | ifneq (,$(findstring darwin,$(OSTYPE))) | |
22 | BUILD=darwin | |
23 | endif | |
24 | ||
25 | ||
26 | ################################################################################ | |
27 | ||
28 | # Set build options according to what we found out. | |
29 | ||
30 | ifeq ($(BUILD),win32) | |
31 | CC = gcc | |
32 | LDFLAGS = -lm -lwsock32 -lwinmm | |
33 | CFLAGS=-std=c99 -U__STRICT_ANSI__ -O2 -I. -Wall | |
34 | EXEC_SUFFIX = .exe | |
35 | endif | |
36 | ||
37 | ifeq ($(BUILD),solaris) | |
38 | CC=gcc | |
39 | CFLAGS=-D_GNU_SOURCE | |
40 | LDFLAGS=-lm -lsocket -lnsl -lrt -lpthread | |
41 | endif | |
42 | ||
43 | ifeq ($(BUILD),darwin) | |
44 | CC=gcc | |
45 | CFLAGS = -D_GNU_SOURCE | |
46 | LDFLAGS= | |
47 | endif | |
48 | ||
49 | ifeq ($(BUILD),linux) | |
50 | CC=gcc | |
51 | CFLAGS = -D_GNU_SOURCE -std=c99 -U__STRICT_ANSI__ -g | |
52 | LDFLAGS= -lrt -lm | |
53 | endif | |
54 | ||
55 | ||
56 | ################################################################################ | |
57 | ||
58 | # Add network definitions if desired | |
59 | ||
60 | ifneq ($(USE_NETWORK),) | |
61 | CFLAGS+=-DUSE_NETWORK | |
62 | LDFLAGS+=-lwpcap -lpacket | |
63 | endif | |
64 | ||
65 | ||
66 | ################################################################################ | |
67 | ||
68 | # Other stuff to add to CFLAGS and LDFLAGS | |
69 | ||
70 | CFLAGS+=-I common | |
71 | LDFLAGS+= | |
72 | ||
73 | ||
74 | ################################################################################ | |
75 | ||
76 | # Target directory where the executables go to. | |
77 | # The directory is automatically created if it doesn't exist. | |
78 | TARGET_DIR=bin | |
79 | ||
80 | # This makes the target directory go away with "make clean": | |
81 | CLEANSTUFF+=$(TARGET_DIR) | |
82 | ||
83 | ||
84 | ################################################################################ | |
85 | ################################################################################ | |
86 | ||
87 | # This is the main section containing all the simulator dependent information. | |
88 | ||
89 | ||
90 | # Names used by the template mechanism. | |
91 | # They are used as part of the corresponding variable names | |
92 | # like "NOVA" in "NOVA_CFLAGS". | |
93 | # You will have to add a name for every new simulator or build | |
94 | # configuration. | |
95 | ||
96 | SIM_NAMES=COMMON H316 NOVA ECLIPSE | |
97 | ||
98 | # | |
99 | # Global stuff. The special executable "nothing" will not be built. | |
100 | # | |
101 | COMMON_DIR=common | |
102 | COMMON_MODULES=scp sim_console sim_fio sim_timer sim_sock sim_tmxr sim_ether sim_tape | |
103 | COMMON_CFLAGS= | |
104 | COMMON_EXEC=nothing | |
105 | ||
106 | ||
107 | ################################################################################ | |
108 | # | |
109 | # Data General Nova | |
110 | # | |
111 | NOVA_DIR=nova | |
112 | NOVA_EXEC=nova | |
113 | NOVA_MODULES= nova_sys nova_cpu nova_dkp nova_dsk nova_lp nova_mta \ | |
114 | nova_plt nova_pt nova_clk nova_tt nova_tt1 nova_qty | |
115 | ||
116 | ||
117 | ################################################################################ | |
118 | # | |
119 | # Data General Eclipse | |
120 | # | |
121 | ||
122 | # Note: Here you see we define a ..._SRC_DIR and ..._OBJ_DIR. This is | |
123 | # done because Nova and Eclipse have the same modules compiled | |
124 | # with different CFLAGS. | |
125 | # This is handled automatically by the generic rule template for | |
126 | # object files. But if the OBJ_DIR should be deleted | |
127 | # by "make clean", it must be added manually to the CLEANSTUFF list. | |
128 | ||
129 | ECLIPSE_SRC_DIR=nova | |
130 | ECLIPSE_OBJ_DIR=eclipse | |
131 | CLEANSTUFF+=$(ECLIPSE_OBJ_DIR) | |
132 | ||
133 | ECLIPSE_EXEC=eclipse | |
134 | ECLIPSE_MODULES=eclipse_cpu eclipse_tt nova_sys nova_dkp nova_dsk nova_lp \ | |
135 | nova_mta nova_plt nova_pt nova_clk nova_tt1 nova_qty | |
136 | ECLIPSE_CFLAGS=-DECLIPSE -DUSE_INT64 | |
137 | ||
138 | ||
139 | ################################################################################ | |
140 | ||
141 | # | |
142 | # Honeywell DDP-516/H316 | |
143 | # | |
144 | H316_DIR=h316 | |
145 | H316_EXEC=h316 | |
146 | H316_MODULES = h316_stddev h316_lp h316_cpu h316_sys h316_mt h316_fhd h316_dp | |
147 | ||
148 | ||
149 | ################################################################################ | |
150 | ################################################################################ | |
151 | ||
152 | # Here comes the weird generic stuff. Should be altered VERY carefully only. | |
153 | ||
154 | # Default target | |
155 | default: all | |
156 | ||
157 | ||
158 | ################################# | |
159 | # | |
160 | # The object file build rule template | |
161 | # | |
162 | ||
163 | define OBJECT_TEMPLATE | |
164 | ||
165 | # If no ..._OBJ_DIR is specified, use ..._DIR | |
166 | ||
167 | ifeq (,$$($(1)_OBJ_DIR)) | |
168 | $(1)_OBJ_DIR=$$($(1)_DIR) | |
169 | endif | |
170 | ||
171 | # If no ..._SRC_DIR is specified, use ..._DIR | |
172 | ||
173 | ifeq (,$$($(1)_SRC_DIR)) | |
174 | $(1)_SRC_DIR=$$($(1)_DIR) | |
175 | endif | |
176 | ||
177 | # Generate object file names with path (for example h316/h316_cpu.o) | |
178 | ||
179 | $(1)_OBJS=$$(foreach obj, $$($(1)_MODULES), $$($(1)_OBJ_DIR)/$$(obj).o) | |
180 | ||
181 | # Add the object files to the CLEANSTUFF list | |
182 | ||
183 | CLEANSTUFF+=$$($(1)_OBJS) | |
184 | ||
185 | # The build rule. | |
186 | # At the moment, header file changes might cause too many files to be rebuilt. But | |
187 | # that seems to be acceptable for the moment. | |
188 | ||
189 | $$($(1)_OBJS) : $$($(1)_OBJ_DIR)/%.o : $$($(1)_SRC_DIR)/%.c $$($(1)_SRC_DIR)/*.h $$(COMMON_DIR)/*.h | |
190 | @echo CC $$@ | |
191 | ||
192 | # Create output directory if it doesn't exist yet. | |
193 | ||
194 | @if [ ! -d $$($(1)_OBJ_DIR) ]; then echo "MKDIR $$($(1)_OBJ_DIR)"; mkdir $$($(1)_OBJ_DIR); fi | |
195 | ||
196 | ifneq (,$$(VERBOSE)) | |
197 | @echo $$(CC) -c -o $$@ -I $$($(1)_DIR) $$(CFLAGS) $$($(1)_CFLAGS) $$< | |
198 | endif | |
199 | ||
200 | @$$(CC) -c -o $$@ -I $$($(1)_DIR) $$(CFLAGS) $$($(1)_CFLAGS) $$< | |
201 | ||
202 | endef | |
203 | ||
204 | ||
205 | ################################# | |
206 | # | |
207 | # The executable file build rule template | |
208 | # | |
209 | ||
210 | define PROGRAM_TEMPLATE | |
211 | ||
212 | # Add the executable to the CLEANSTUFF list | |
213 | ||
214 | CLEANSTUFF+=$$(TARGET_DIR)/$$($(1)_EXEC)$$(EXEC_SUFFIX) | |
215 | ||
216 | # We won't build or mention the executable named "noting"! | |
217 | ifneq (nothing,$$($(1)_EXEC)) | |
218 | EXEC_TARGETS+=$$($(1)_EXEC) | |
219 | endif | |
220 | ||
221 | # Generate a phony target with the simulator's name. | |
222 | # Enables things like "make h316". | |
223 | # On Windows this WILL NOT be "make h316.exe". | |
224 | ||
225 | $$($(1)_EXEC): $$(TARGET_DIR)/$$($(1)_EXEC)$$(EXEC_SUFFIX) | |
226 | ||
227 | .PHONY: $$($(1)_EXEC) | |
228 | ||
229 | $$(TARGET_DIR)/$$($(1)_EXEC)$$(EXEC_SUFFIX): $$($(1)_OBJS) $$(COMMON_OBJS) | |
230 | @if [ ! -d $$(TARGET_DIR) ]; then echo "MKDIR $$(TARGET_DIR)";mkdir $$(TARGET_DIR);fi | |
231 | @echo LD $$@ | |
232 | ifneq (,$$(VERBOSE)) | |
233 | @echo $$(CC) -o$$@ $$(LDFLAGS) $$($(1)_LDFLAGS) $$^ | |
234 | endif | |
235 | @$$(CC) -o$$@ $$(LDFLAGS) $$($(1)_LDFLAGS) $$^ | |
236 | endef | |
237 | ||
238 | ||
239 | ################################# | |
240 | # | |
241 | # Use the template with SIM_NAMES | |
242 | # | |
243 | ||
244 | $(foreach sn, $(SIM_NAMES),$(eval $(call OBJECT_TEMPLATE,$(sn)))) | |
245 | $(foreach sn, $(SIM_NAMES),$(eval $(call PROGRAM_TEMPLATE,$(sn)))) | |
246 | ||
247 | ||
248 | ################################# | |
249 | # | |
250 | # The all target | |
251 | # | |
252 | ||
253 | all: $(EXEC_TARGETS) | |
254 | ||
255 | ||
256 | ################################# | |
257 | # | |
258 | # Output a little help | |
259 | # | |
260 | ||
261 | help: | |
262 | @echo Available targets: | |
263 | @echo | |
264 | @echo "all - Build all simulators" | |
265 | @echo "clean - Delete all generated files and directories" | |
266 | @echo | |
267 | @echo Simulators can explicitely built by the following targets: | |
268 | @echo | |
269 | @echo $(EXEC_TARGETS) | |
270 | @echo | |
271 | @echo $(CLEANSTUFF) | |
272 | @echo | |
273 | @echo The actual CC calls can be made visible with specifying VERBOSE=something. | |
274 | @echo | |
275 | ||
276 | ||
277 | ################################# | |
278 | # | |
279 | # The clean rule. | |
280 | # | |
281 | ||
282 | clean: | |
283 | @echo CLEAN | |
284 | @rm -rf $(CLEANSTUFF) | |
285 | ||
286 | ||
287 | ################################# | |
288 | # | |
289 | # Specify phony targets | |
290 | # | |
291 | ||
292 | .PHONY: clean help all default | |
293 | ||
294 | ||
295 | ################################################################################ | |
296 | # | |
297 | # This is the end of the game :-) | |
298 | # | |
299 | ################################################################################ | |
300 | ||
301 | ||
302 |