First Commit of my working state
[simh.git] / Makefile.posted
CommitLineData
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
11BUILD=linux
12
13ifneq ($(WIN32),)
14 BUILD=win32
15endif
16
17ifneq (,$(findstring solaris,$(OSTYPE)))
18 BUILD=solaris
19endif
20
21ifneq (,$(findstring darwin,$(OSTYPE)))
22 BUILD=darwin
23endif
24
25
26################################################################################
27
28# Set build options according to what we found out.
29
30ifeq ($(BUILD),win32)
31 CC = gcc
32 LDFLAGS = -lm -lwsock32 -lwinmm
33 CFLAGS=-std=c99 -U__STRICT_ANSI__ -O2 -I. -Wall
34 EXEC_SUFFIX = .exe
35endif
36
37ifeq ($(BUILD),solaris)
38 CC=gcc
39 CFLAGS=-D_GNU_SOURCE
40 LDFLAGS=-lm -lsocket -lnsl -lrt -lpthread
41endif
42
43ifeq ($(BUILD),darwin)
44 CC=gcc
45 CFLAGS = -D_GNU_SOURCE
46 LDFLAGS=
47endif
48
49ifeq ($(BUILD),linux)
50 CC=gcc
51 CFLAGS = -D_GNU_SOURCE -std=c99 -U__STRICT_ANSI__ -g
52 LDFLAGS= -lrt -lm
53endif
54
55
56################################################################################
57
58# Add network definitions if desired
59
60ifneq ($(USE_NETWORK),)
61 CFLAGS+=-DUSE_NETWORK
62 LDFLAGS+=-lwpcap -lpacket
63endif
64
65
66################################################################################
67
68# Other stuff to add to CFLAGS and LDFLAGS
69
70CFLAGS+=-I common
71LDFLAGS+=
72
73
74################################################################################
75
76# Target directory where the executables go to.
77# The directory is automatically created if it doesn't exist.
78TARGET_DIR=bin
79
80# This makes the target directory go away with "make clean":
81CLEANSTUFF+=$(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
96SIM_NAMES=COMMON H316 NOVA ECLIPSE
97
98#
99# Global stuff. The special executable "nothing" will not be built.
100#
101COMMON_DIR=common
102COMMON_MODULES=scp sim_console sim_fio sim_timer sim_sock sim_tmxr sim_ether sim_tape
103COMMON_CFLAGS=
104COMMON_EXEC=nothing
105
106
107################################################################################
108#
109# Data General Nova
110#
111NOVA_DIR=nova
112NOVA_EXEC=nova
113NOVA_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
129ECLIPSE_SRC_DIR=nova
130ECLIPSE_OBJ_DIR=eclipse
131CLEANSTUFF+=$(ECLIPSE_OBJ_DIR)
132
133ECLIPSE_EXEC=eclipse
134ECLIPSE_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
136ECLIPSE_CFLAGS=-DECLIPSE -DUSE_INT64
137
138
139################################################################################
140
141#
142# Honeywell DDP-516/H316
143#
144H316_DIR=h316
145H316_EXEC=h316
146H316_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
155default: all
156
157
158#################################
159#
160# The object file build rule template
161#
162
163define OBJECT_TEMPLATE
164
165# If no ..._OBJ_DIR is specified, use ..._DIR
166
167ifeq (,$$($(1)_OBJ_DIR))
168$(1)_OBJ_DIR=$$($(1)_DIR)
169endif
170
171# If no ..._SRC_DIR is specified, use ..._DIR
172
173ifeq (,$$($(1)_SRC_DIR))
174 $(1)_SRC_DIR=$$($(1)_DIR)
175endif
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
183CLEANSTUFF+=$$($(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
196ifneq (,$$(VERBOSE))
197 @echo $$(CC) -c -o $$@ -I $$($(1)_DIR) $$(CFLAGS) $$($(1)_CFLAGS) $$<
198endif
199
200 @$$(CC) -c -o $$@ -I $$($(1)_DIR) $$(CFLAGS) $$($(1)_CFLAGS) $$<
201
202endef
203
204
205#################################
206#
207# The executable file build rule template
208#
209
210define PROGRAM_TEMPLATE
211
212# Add the executable to the CLEANSTUFF list
213
214CLEANSTUFF+=$$(TARGET_DIR)/$$($(1)_EXEC)$$(EXEC_SUFFIX)
215
216# We won't build or mention the executable named "noting"!
217ifneq (nothing,$$($(1)_EXEC))
218EXEC_TARGETS+=$$($(1)_EXEC)
219endif
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 $$@
232ifneq (,$$(VERBOSE))
233 @echo $$(CC) -o$$@ $$(LDFLAGS) $$($(1)_LDFLAGS) $$^
234endif
235 @$$(CC) -o$$@ $$(LDFLAGS) $$($(1)_LDFLAGS) $$^
236endef
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
253all: $(EXEC_TARGETS)
254
255
256#################################
257#
258# Output a little help
259#
260
261help:
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
282clean:
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