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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
|
## Copyright (C) 2010 Matthew Fluet.
# Copyright (C) 1999-2009 Henry Cejtin, Matthew Fluet, Suresh
# Jagannathan, and Stephen Weeks.
# Copyright (C) 1997-2000 NEC Research Institute.
#
# MLton is released under a BSD-style license.
# See the file MLton-LICENSE for details.
##
PATH := ../bin:$(shell echo $$PATH)
TARGET := self
ifeq ($(TARGET), self)
CC := gcc -std=gnu99
AR := ar rc
RANLIB := ranlib
else
CC := $(TARGET)-gcc -std=gnu99
AR := $(TARGET)-ar rc
RANLIB := $(TARGET)-ranlib
endif
TARGET_ARCH := $(shell ../bin/host-arch)
TARGET_OS := $(shell ../bin/host-os)
GCC_MAJOR_VERSION := \
$(shell $(CC) -v 2>&1 | grep 'gcc version' | \
sed 's/.*gcc version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1/')
GCC_MINOR_VERSION := \
$(shell $(CC) -v 2>&1 | grep 'gcc version' | \
sed 's/.*gcc version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\2/')
GCC_VERSION := $(GCC_MAJOR_VERSION).$(GCC_MINOR_VERSION)
FLAGS := -fno-common
EXE :=
OPTFLAGS := -O2 -fomit-frame-pointer
DEBUGFLAGS := -O1 -fno-inline -fkeep-inline-functions -g2
PICFLAGS := -DPIC
GCOPTFLAGS :=
GCDEBUGFLAGS :=
GCPICFLAGS :=
WARNFLAGS :=
OPTWARNFLAGS :=
DEBUGWARNFLAGS :=
PICWARNFLAGS :=
# Win32&64 don't use PIC code, all other platforms do
ifeq ($(findstring $(TARGET_OS), mingw cygwin),)
PICFLAGS += -fPIC
endif
# Make mlton library symbols private (win32&64 use another technique)
ifeq ($(findstring $(GCC_MAJOR_VERSION), 4),$(GCC_MAJOR_VERSION))
ifeq ($(findstring $(TARGET_OS), mingw cygwin),)
FLAGS += -fvisibility=hidden
endif
endif
ifeq ($(TARGET_ARCH), alpha)
FLAGS += -mieee -mbwx -mtune=ev6 -mfp-rounding-mode=d
endif
ifeq ($(TARGET_ARCH), amd64)
FLAGS += -m64
DEBUGFLAGS += -gstabs+
endif
ifeq ($(findstring $(TARGET_ARCH), hppa ia64 powerpc sparc),$(TARGET_ARCH))
ifeq (4.2, $(firstword $(sort $(GCC_VERSION) 4.2)))
# GMP headers contain C99 inline functions which generate warnings
# with a suggestion to use this flag to disable the warnings.
FLAGS += -fgnu89-inline
endif
endif
ifeq ($(TARGET_ARCH), ia64)
FLAGS += -mtune=itanium2
ifeq ($(TARGET_OS), hpux)
FLAGS += -mlp64
endif
endif
ifeq ($(TARGET_OS)-$(TARGET_ARCH), aix-powerpc64)
FLAGS += -maix64
AR := ar -X 64 rc
endif
ifeq ($(TARGET_ARCH), sparc)
FLAGS += -m32 -mcpu=v8 -Wa,-xarch=v8plusa
endif
ifeq ($(TARGET_ARCH), x86)
FLAGS += -m32
ifeq (3, $(firstword $(sort $(GCC_MAJOR_VERSION) 3)))
OPTFLAGS += -falign-loops=2 -falign-jumps=2 -falign-functions=5
else
OPTFLAGS += -malign-loops=2 -malign-jumps=2 -malign-functions=5
endif
DEBUGFLAGS += -gstabs+
endif
ifeq ($(TARGET_OS), cygwin)
EXE := .exe
endif
ifeq ($(TARGET_OS), darwin)
FLAGS += -I/usr/local/include -I/sw/include -I/opt/local/include
endif
ifeq ($(TARGET_OS), freebsd)
FLAGS += -I/usr/local/include
endif
ifeq ($(TARGET_OS), mingw)
EXE := .exe
endif
ifeq ($(TARGET_OS), netbsd)
FLAGS += -I/usr/pkg/include
endif
ifeq ($(TARGET_OS), openbsd)
FLAGS += -I/usr/local/include
endif
ifeq ($(TARGET_OS), solaris)
FLAGS += -funroll-all-loops
endif
# These flags can be overridden by the user
CPPFLAGS :=
CFLAGS :=
INCFLAGS := -I. -Iplatform
OPTCFLAGS := $(CFLAGS) $(INCFLAGS) $(CPPFLAGS) $(FLAGS) $(OPTFLAGS)
DEBUGCFLAGS := $(CFLAGS) $(INCFLAGS) $(CPPFLAGS) $(FLAGS) -DASSERT=1 $(DEBUGFLAGS)
PICCFLAGS := $(CFLAGS) $(INCFLAGS) $(CPPFLAGS) $(FLAGS) $(OPTFLAGS) $(PICFLAGS)
GCOPTCFLAGS = $(GCOPTFLAGS)
GCDEBUGCFLAGS = $(GCDEBUGFLAGS)
GCPICCFLAGS = $(GCOPTFLAGS) $(GCPICFLAGS)
WARNCFLAGS :=
WARNCFLAGS += -pedantic -Wall
ifeq ($(findstring $(GCC_MAJOR_VERSION), 3),$(GCC_MAJOR_VERSION))
WARNCFLAGS += -W
endif
ifeq ($(findstring $(GCC_MAJOR_VERSION), 4),$(GCC_MAJOR_VERSION))
WARNCFLAGS += -Wextra
endif
WARNCFLAGS += -Wformat=2
ifeq ($(findstring $(GCC_MAJOR_VERSION), 4),$(GCC_MAJOR_VERSION))
WARNCFLAGS += -Wswitch-default -Wswitch-enum
endif
WARNCFLAGS += -Wuninitialized
ifeq ($(findstring $(GCC_MAJOR_VERSION), 4),$(GCC_MAJOR_VERSION))
WARNCFLAGS += -Winit-self
endif
ifeq ($(findstring $(GCC_MAJOR_VERSION), 4),$(GCC_MAJOR_VERSION))
WARNCFLAGS += -Wstrict-aliasing=2
endif
WARNCFLAGS += -Wfloat-equal
WARNCFLAGS += -Wundef
WARNCFLAGS += -Wshadow
WARNCFLAGS += -Wpointer-arith
WARNCFLAGS += -Wbad-function-cast -Wcast-qual
WARNCFLAGS += -Wwrite-strings
# WARNCFLAGS += -Wconversion
WARNCFLAGS += -Waggregate-return
WARNCFLAGS += -Wstrict-prototypes
ifeq ($(findstring $(GCC_MAJOR_VERSION), 4),$(GCC_MAJOR_VERSION))
WARNCFLAGS += -Wold-style-definition
endif
WARNCFLAGS += -Wmissing-prototypes -Wmissing-declarations
ifeq ($(findstring $(GCC_MAJOR_VERSION), 4),$(GCC_MAJOR_VERSION))
WARNCFLAGS += -Wmissing-field-initializers
endif
WARNCFLAGS += -Wmissing-noreturn
WARNCFLAGS += -Wmissing-format-attribute
# WARNCFLAGS += -Wpacked
# WARNCFLAGS += -Wpadded
WARNCFLAGS += -Wredundant-decls
WARNCFLAGS += -Wnested-externs
# WARNCFLAGS += -Wunreachable-code
WARNCFLAGS += $(WARNFLAGS)
# GCC doesn't recognize the %I64 format specifier which means %ll on windows
ifeq ($(TARGET_OS), mingw)
WARNCFLAGS += -Wno-format -Wno-missing-format-attribute
endif
OPTWARNCFLAGS := $(WARNCFLAGS) -Wdisabled-optimization $(OPTWARNFLAGS)
DEBUGWARNCFLAGS := $(WARNCFLAGS) $(DEBUGWARNFLAGS)
PICWARNCFLAGS := $(WARNCFLAGS) -Wdisabled-optimization $(OPTWARNFLAGS)
GDTOACFILES := \
dmisc.c g__fmt.c misc.c strtoIdd.c strtopdd.c strtorf.c \
dtoa.c gmisc.c smisc.c strtoIf.c strtopf.c strtorQ.c \
g_ddfmt.c g_Qfmt.c strtod.c strtoIg.c strtopQ.c strtorx.c \
g_dfmt.c g_xfmt.c strtodg.c strtoIQ.c strtopx.c strtorxL.c \
gdtoa.c g_xLfmt.c strtodI.c strtoIx.c strtopxL.c sum.c \
gethex.c hd_init.c strtof.c strtoIxL.c strtord.c ulp.c \
g_ffmt.c hexnan.c strtoId.c strtopd.c strtordd.c
GDTOACFILES := $(patsubst %,gdtoa/%,$(GDTOACFILES))
UTILHFILES := \
util.h \
$(shell find util -type f | grep '\.h$$')
UTILCFILES := \
$(shell find util -type f | grep '\.c$$')
PLATFORMHFILES := \
platform.h \
$(shell find platform -type f | grep '\.h$$')
PLATFORMCFILES := \
$(shell find platform -type f | grep '\.c$$')
GCHFILES := \
gc.h \
$(shell find gc -type f | grep '\.h$$')
GCCFILES := \
$(shell find gc -type f | grep '\.c$$')
BYTECODEHFILES := \
$(shell find bytecode -type f | grep '\.h$$')
BASISHFILES := \
ml-types.h \
c-types.h \
basis-ffi.h \
$(shell find basis -type f | grep '\.h$$')
BASISCFILES := \
$(shell find basis -type f | grep '\.c$$')
HFILES := \
cenv.h \
$(UTILHFILES) \
$(PLATFORMHFILES) \
$(GCHFILES) \
$(BASISHFILES)
GDTOA_OBJS := $(patsubst %.c,%.o,$(GDTOACFILES))
GDTOA_DEBUG_OBJS := $(patsubst %.c,%-gdb.o,$(GDTOACFILES))
GDTOA_PIC_OBJS := $(patsubst %.c,%-pic.o,$(GDTOACFILES))
OBJS := \
util.o \
platform.o \
platform/$(TARGET_OS).o \
gc.o
OMIT_BYTECODE := no
ifeq ($(OMIT_BYTECODE), yes)
else
OBJS += bytecode/interpret.o
endif
ifeq ($(COMPILE_FAST), yes)
OBJS += basis.o
else
OBJS += \
$(foreach f, $(basename $(BASISCFILES)), $(f).o)
endif
DEBUG_OBJS := $(patsubst %.o,%-gdb.o,$(OBJS))
PIC_OBJS := $(patsubst %.o,%-pic.o,$(OBJS))
ALL := libgdtoa.a libgdtoa-gdb.a libgdtoa-pic.a \
libmlton.a libmlton-gdb.a libmlton-pic.a
ALL += gen/c-types.sml gen/basis-ffi.sml gen/sizes
ifeq ($(OMIT_BYTECODE), yes)
else
ALL += bytecode/opcodes
endif
all: $(ALL)
gdtoa/arithchk.c: gdtoa.tgz gdtoa-patch gdtoa-patch.internal gdtoa-patch.mlton
gzip -dc gdtoa.tgz | tar xf -
patch -s -p0 <gdtoa-patch
patch -s -p0 <gdtoa-patch.internal
patch -s -p0 <gdtoa-patch.mlton
$(GDTOACFILES): gdtoa/arithchk.c
@touch $@
gdtoa/arithchk.out: gdtoa/arithchk.c
cd gdtoa && $(CC) $(OPTCFLAGS) $(OPTWARNCFLAGS) -w -O1 -o arithchk.out arithchk.c
gdtoa/arith.h: gdtoa/arithchk.out
cd gdtoa && ./arithchk.out >arith.h
gdtoa/%-pic.o: gdtoa/%.c gdtoa/arith.h
$(CC) $(PICCFLAGS) $(PICWARNCFLAGS) -w -DINFNAN_CHECK -c -o $@ $<
gdtoa/%-gdb.o: gdtoa/%.c gdtoa/arith.h
$(CC) $(DEBUGCFLAGS) $(DEBUGWARNCFLAGS) -w -DINFNAN_CHECK -c -o $@ $<
gdtoa/%.o: gdtoa/%.c gdtoa/arith.h
$(CC) $(OPTCFLAGS) $(OPTWARNCFLAGS) -w -DINFNAN_CHECK -c -o $@ $<
libgdtoa.a: $(GDTOA_OBJS)
libgdtoa-gdb.a: $(GDTOA_DEBUG_OBJS)
libgdtoa-pic.a: $(GDTOA_PIC_OBJS)
util-pic.o: util.c $(UTILCFILES) cenv.h $(UTILHFILES)
$(CC) $(PICCFLAGS) $(PICWARNCFLAGS) -c -o $@ $<
util-gdb.o: util.c $(UTILCFILES) cenv.h $(UTILHFILES)
$(CC) $(DEBUGCFLAGS) $(DEBUGWARNCFLAGS) -c -o $@ $<
util.o: util.c $(UTILCFILES) cenv.h $(UTILHFILES)
$(CC) $(OPTCFLAGS) $(OPTWARNCFLAGS) -c -o $@ $<
c-types.h: gen/c-types.h
cp $< $@
ml-types.h: gen/ml-types.h
cp $< $@
gen/c-types.h gen/c-types.sml gen/ml-types.h: gen/gen-types.stamp
@touch $@
gen/gen-types.stamp: gen/gen-types.c util.h util.o
$(CC) $(OPTCFLAGS) $(WARNCFLAGS) -o gen/gen-types gen/gen-types.c util.o
rm -f gen/c-types.h gen/c-types.sml gen/ml-types.h gen/gen-types.stamp
cd gen && ./gen-types
rm -f gen/gen-types$(EXE) gen/gen-types
touch $@
basis-ffi.h: gen/basis-ffi.h
cp $< $@
gen/basis-ffi.h gen/basis-ffi.sml: gen/gen-basis-ffi.stamp
@touch $@
gen/gen-basis-ffi.stamp: gen/gen-basis-ffi.sml gen/basis-ffi.def
mlton -output gen/gen-basis-ffi gen/gen-basis-ffi.sml
rm -f gen/basis-ffi.h gen/basis-ffi.sml gen/gen-basis-ffi.stamp
cd gen && ./gen-basis-ffi
rm -f gen/gen-basis-ffi
touch $@
gen/sizes: gen/gen-sizes.stamp
@touch $@
gen/gen-sizes.stamp: gen/gen-sizes.c libmlton.a $(HFILES)
$(CC) $(OPTCFLAGS) $(WARNCFLAGS) -I. -o gen/gen-sizes gen/gen-sizes.c -L. -lmlton
rm -f gen/sizes
cd gen && ./gen-sizes
rm -f gen/gen-sizes$(EXE) gen/gen-sizes
touch $@
platform/$(TARGET_OS)-pic.o: $(PLATFORMCFILES)
platform/$(TARGET_OS)-gdb.o: $(PLATFORMCFILES)
platform/$(TARGET_OS).o: $(PLATFORMCFILES)
gc-pic.o: gc.c $(GCCFILES) $(HFILES)
$(CC) $(PICCFLAGS) $(GCPICCFLAGS) $(PICWARNCFLAGS) -c -o $@ $<
gc-gdb.o: gc.c $(GCCFILES) $(HFILES)
$(CC) $(DEBUGCFLAGS) $(GCDEBUGCFLAGS) $(DEBUGWARNCFLAGS) -c -o $@ $<
gc.o: gc.c $(GCCFILES) $(HFILES)
$(CC) $(OPTCFLAGS) $(GCOPTCFLAGS) $(OPTWARNCFLAGS) -c -o $@ $<
## Needs -Wno-float-equal for Real<N>_equal, included via "c-chunk.h".
bytecode/interpret-pic.o: bytecode/interpret.c $(HFILES) $(BYTECODEHFILES)
$(CC) -I../include $(PICCFLAGS) $(GCPICCFLAGS) $(PICWARNCFLAGS) -Wno-float-equal -c -o $@ $<
bytecode/interpret-gdb.o: bytecode/interpret.c $(HFILES) $(BYTECODEHFILES)
$(CC) -I../include $(DEBUGCFLAGS) $(GCDEBUGCFLAGS) $(DEBUGWARNCFLAGS) -Wno-float-equal -c -o $@ $<
bytecode/interpret.o: bytecode/interpret.c $(HFILES) $(BYTECODEHFILES)
$(CC) -I../include $(OPTCFLAGS) $(GCOPTCFLAGS) $(OPTWARNCFLAGS) -Wno-float-equal -c -o $@ $<
bytecode/opcodes: bytecode/print-opcodes
@touch $@
bytecode/print-opcodes: bytecode/print-opcodes.c bytecode/opcode.h $(HFILES)
$(CC) $(OPTCFLAGS) $(WARNCFLAGS) -o bytecode/print-opcodes bytecode/print-opcodes.c
rm -f bytecode/opcodes
cd bytecode && ./print-opcodes > opcodes
basis.c: $(BASISCFILES)
rm -f basis.c
cat $(BASISCFILES) >> basis.c
## Needs -Wno-float-equal for Real<N>_equal;
## needs -Wno-format-nonliteral for Date_strfTime;
## needs -Wno-redundant-decls for 'extern struct GC_state gcState'.
basis-pic.o: basis.c $(BASISCFILES) $(HFILES)
$(CC) -Ibasis -Ibasis/Word -Ibasis/Real $(PICCFLAGS) $(PICWARNCFLAGS) -Wno-float-equal -Wno-format-nonliteral -Wno-redundant-decls -c -o $@ $<
basis-gdb.o: basis.c $(BASISCFILES) $(HFILES)
$(CC) -Ibasis -Ibasis/Word -Ibasis/Real $(DEBUGCFLAGS) $(DEBUGWARNCFLAGS) -Wno-float-equal -Wno-format-nonliteral -Wno-redundant-decls -c -o $@ $<
basis.o: basis.c $(BASISCFILES) $(HFILES)
$(CC) -Ibasis -Ibasis/Word -Ibasis/Real $(OPTCFLAGS) $(OPTWARNCFLAGS) -Wno-float-equal -Wno-format-nonliteral -Wno-redundant-decls -c -o $@ $<
## Needs -Wno-float-equal for Real<N>_equal.
basis/Real/Real-pic.o: basis/Real/Real.c $(HFILES)
$(CC) $(PICCFLAGS) $(PICWARNCFLAGS) -Wno-float-equal -c -o $@ $<
basis/Real/Real-gdb.o: basis/Real/Real.c $(HFILES)
$(CC) $(DEBUGCFLAGS) $(DEBUGWARNCFLAGS) -Wno-float-equal -c -o $@ $<
basis/Real/Real.o: basis/Real/Real.c $(HFILES)
$(CC) $(OPTCFLAGS) $(OPTWARNCFLAGS) -Wno-float-equal -c -o $@ $<
## Needs -Wno-format-nonliteral for Date_strfTime.
basis/System/Date-pic.o: basis/System/Date.c $(HFILES)
$(CC) $(PICCFLAGS) $(PICWARNCFLAGS) -Wno-format-nonliteral -c -o $@ $<
basis/System/Date-gdb.o: basis/System/Date.c $(HFILES)
$(CC) $(DEBUGCFLAGS) $(DEBUGWARNCFLAGS) -Wno-format-nonliteral -c -o $@ $<
basis/System/Date.o: basis/System/Date.c $(HFILES)
$(CC) $(OPTCFLAGS) $(OPTWARNCFLAGS) -Wno-format-nonliteral -c -o $@ $<
libmlton.a: $(OBJS)
libmlton-gdb.a: $(DEBUG_OBJS)
libmlton-pic.a: $(PIC_OBJS)
%-pic.o: %.c $(HFILES)
$(CC) $(PICCFLAGS) $(PICWARNCFLAGS) -c -o $@ $<
%-gdb.o: %.c $(HFILES)
$(CC) $(DEBUGCFLAGS) $(DEBUGWARNCFLAGS) -c -o $@ $<
%.o: %.c $(HFILES)
$(CC) $(OPTCFLAGS) $(OPTWARNCFLAGS) -c -o $@ $<
%.a:
rm -f $@
$(AR) $@ $^
$(RANLIB) $@
.PHONY: flags
flags:
echo TARGET = $(TARGET)
echo TARGET_ARCH = $(TARGET_ARCH)
echo TARGET_OS = $(TARGET_OS)
echo GCC_MAJOR_VERSION = $(GCC_MAJOR_VERSION)
echo GCC_MINOR_VERSION = $(GCC_MINOR_VERSION)
echo GCC_VERSION = $(GCC_VERSION)
echo FLAGS = $(FLAGS)
echo EXE = $(EXE)
echo OPTFLAGS = $(OPTFLAGS)
echo GCOPTFLAGS = $(GCOPTFLAGS)
echo DEBUGFLAGS = $(DEBUGFLAGS)
echo WARNFLAGS = $(WARNFLAGS)
echo OPTWARNFLAGS = $(OPTWARNFLAGS)
echo DEBUGWARNFLAGS = $(DEBUGWARNFLAGS)
echo OBJS = $(OBJS)
.PHONY: clean
clean:
../bin/clean
.PHONY: rebuild-gdtoa-patch
rebuild-gdtoa-patch:
cd gdtoa && $(MAKE) clean && rm -f *~ *.orig
mv gdtoa gdtoa-new
gzip -dc gdtoa.tgz | tar xf -
diff -P -C 2 -r gdtoa gdtoa-new >gdtoa-patch || exit 0
rm -rf gdtoa
mv gdtoa-new gdtoa
|