Ported gettimeofday to WIN32 for prim_timeSinceEpoch. Still need to fix this for...
[cslatevm.git] / common.mk
blob55c6a00ba399256249e5f6ef6c6797d61280bde4
1 ##
2 # Variables included by all Makefiles.
3 ##
5 ## Directory definitions
7 libdir = $(slateroot)/lib
8 mobiusdir = $(slateroot)/src/mobius
9 pluginsdir = $(slateroot)/src/plugins
10 testdir = $(slateroot)/tests
12 prefix = /usr/local
13 datadir = $(prefix)/share/slate
14 exec_prefix = $(prefix)/bin
15 execname = slate
16 includedir = $(prefix)/include
17 mandir = $(prefix)/share/man
18 man1dir = $(mandir)/man1
19 infodir = $(prefix)/info
20 lispdir = $(prefix)/share/emacs/site-lisp
21 DEVNULL := /dev/null
23 ## Build modes. Set on command line using QUIET=1, DEBUG=1 or PROFILE=1
26 ifdef QUIET
27 VERBOSE := 0
28 SILENT := @
29 SILENT_ERRORS := 2> $(DEVNULL)
30 LIBTOOL_FLAGS += --silent
31 endif
33 ifdef DEBUG
34 MODE := debug
35 COPTFLAGS += -g
36 CFLAGS += -DSLATE_BUILD_TYPE="\"Debug\""
37 else
38 MODE := optimized
39 CFLAGS += -DSLATE_BUILD_TYPE="\"Optimized\""
40 COPTFLAGS += -O2
41 endif
43 ifdef PROFILE
44 MODE += profiled
45 COPTFLAGS += -pg -g
46 CFLAGS += -DSLATE_BUILD_TYPE="\"Profile\""
47 else
48 # COPTFLAGS += -fomit-frame-pointer
49 endif
53 ## All required executables
55 #CC := gcc
56 CP := cp -f
57 LIBTOOL ?= libtool
58 ECHO := echo
59 WGET := wget -q --cache=off
60 SECHO := @$(ECHO)
61 INSTALL := install
62 TAR := tar
63 GZIP := gzip
64 ETAGS := etags
65 EMACS := emacs
67 ## Platform independent definitions
69 INCLUDES +=
70 CFLAGS += -DSLATE_DATADIR=$(datadir) -D_POSIX_SOURCE=200112L
71 CFLAGS += $(COPTFLAGS) -std=c99 -Wall -pedantic -pthread $(PRINT_DEBUG) $(INCLUDES)
73 ## Determine the host system's byte order.
74 ## This creates a temporary test executable in the $(slateroot) directory
75 ## since we can guarantee write permissions there on all platforms.
77 BYTE_ORDER := "int main(){union{long l;char c[sizeof(long)];}u;u.l=1;return(u.c[sizeof(long)-1]==1);}"
78 BYTE_ORDER := $(shell echo $(BYTE_ORDER) > $(slateroot)/byteorder.c)
79 BYTE_ORDER := $(shell $(CC) -o $(slateroot)/byteorder $(slateroot)/byteorder.c)
80 BYTE_ORDER := $(shell $(slateroot)/byteorder; echo $$?)
81 BYTE_ORDER_ := $(shell $(RM) $(slateroot)/byteorder.* $(slateroot)/byteorder 1>&2)
82 ifeq ($(BYTE_ORDER),0)
83 BYTE_ORDER := LITTLE_ENDIAN
84 BYTE_ORDER_PREFIX := little
85 else
86 BYTE_ORDER := BIG_ENDIAN
87 BYTE_ORDER_PREFIX := big
88 endif
90 ## Default variables
92 PLATFORM := unix
93 CCVERSION := $(shell $(CC) -dumpversion)
94 WORD_SIZE := 32
95 LDFLAGS := # -avoid-version
96 LIBS := #-lm -ldl
97 #PLUGINS := platform.so posix.so pipe.so
98 #PLUGINS := x-windows.so
99 PLUGINS :=
100 HOST_SYSTEM := $(shell uname -s)
101 LIB_SO_EXT := .so
102 INSTALL_MODE := -m 644
103 CPU_TYPE := `uname -m`
104 VM_LIBRARIES = -lm -ldl -lpthread
107 VMDIR := $(slateroot)/src/vm
108 VM := $(VMDIR)/vm
109 DEFAULT_IMAGE ?= slate.image
110 KERNEL_IMAGES := kernel.new.*.$(WORD_SIZE).*.image
111 DEFAULT_KERNEL_IMAGE ?= $(shell ls -t $(KERNEL_IMAGES) | head -1)
113 CFLAGS_x-windows.c=`pkg-config --cflags x11` `pkg-config --cflags cairo` -Werror
114 LDFLAGS_x-windows.lo=`pkg-config --libs x11` `pkg-config --libs cairo`
115 CFLAGS_cocoa-windows.c=`pkg-config --cflags cocoa` `pkg-config --cflags cairo`
116 LDFLAGS_cocoa-windows.lo=`pkg-config --libs cocoa` `pkg-config --libs cairo`
117 CFLAGS_glib-wrapper.c=`pkg-config --cflags glib-2.0`
118 LDFLAGS_glib-wrapper.lo=`pkg-config --libs glib-2.0` `pkg-config --libs gobject-2.0`
119 CFLAGS_gdk-wrapper.c=`pkg-config --cflags gdk-2.0`
120 LDFLAGS_gdk-wrapper.lo=`pkg-config --libs gdk-2.0` `pkg-config --libs gthread-2.0`
121 CFLAGS_gtk-wrapper.c=`pkg-config --cflags gtk+-2.0`
122 LDFLAGS_gtk-wrapper.lo=`pkg-config --libs gtk+-2.0`
123 CFLAGS_llvm-wrapper.c=`llvm-config --cflags`
124 LDFLAGS_llvm-wrapper.lo=
126 #CFLAGS_socket.c=
128 PRINT_DEBUG_G=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG_GC_1 -DPRINT_DEBUG_OPCODES
129 PRINT_DEBUG_Y= -DPRINT_DEBUG_STACK_POINTER -DPRINT_DEBUG_STACK_PUSH -DPRINT_DEBUG_FOUND_ROLE -DPRINT_DEBUG_FUNCALL
130 PRINT_DEBUG_X=-DPRINT_DEBUG -DPRINT_DEBUG_OPCODES -DPRINT_DEBUG_INSTRUCTION_COUNT -DPRINT_DEBUG_CODE_POINTER -DPRINT_DEBUG_DISPATCH
131 PRINT_DEBUG_1=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG_GC_1
132 PRINT_DEBUG_4=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG_GC -DPRINT_DEBUG_OPCODES -DPRINT_DEBUG_CODE_POINTER -DPRINT_DEBUG_ENSURE -DPRINT_DEBUG_STACK
133 PRINT_DEBUG_3=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG_GC -DPRINT_DEBUG_OPTIMIZER -DPRINT_DEBUG_PIC_HITS -DPRINT_DEBUG_UNOPTIMIZER
134 PRINT_DEBUG_2=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG -DPRINT_DEBUG_OPCODES -DPRINT_DEBUG_INSTRUCTION_COUNT -DPRINT_DEBUG_CODE_POINTER -DPRINT_DEBUG_DISPATCH -DPRINT_DEBUG_GC_MARKINGS
135 PRINT_DEBUG=$(PRINT_DEBUG_1)
138 ## Determine CPU type
140 #ifeq ($(HOST_SYSTEM), Darwin)
141 # CPU_TYPE := powerpc
142 #endif
144 ## TODO: Sparc detection for SunOS?
145 ## TODO: Base CPU type on real information, not just generic OS variant
147 ## CPU-type specific overrides. Any of the variables above may be changed here.
149 ifdef ARCH
150 CFLAGS += -m$(ARCH)
151 endif
153 ifdef VERSION
154 CFLAGS += -DVERSION="\"$(VERSION)\""
155 endif
157 CFLAGS +=-DSLATE_DEFAULT_IMAGE=$(DEFAULT_IMAGE)
159 #ifeq ($(CPU_TYPE), i686)
160 # CFLAGS += -m$(WORD_SIZE)
161 #endif
163 #ifeq ($(CPU_TYPE), x86_64)
164 # CFLAGS += -m$(WORD_SIZE)
165 #endif
167 ## Platform specific overrides. Any of the variables above may be changed here.
169 ifeq ($(HOST_SYSTEM), AIX)
170 LIB_SO_EXT := .a
171 PLUGINS := platform.so posix.so pipe.so
172 endif
174 ifeq ($(HOST_SYSTEM), BeOS)
175 PLATFORM := beos
176 endif
178 ifeq ($(findstring CYGWIN,$(HOST_SYSTEM)), CYGWIN)
179 PLATFORM := windows
180 LDFLAGS += -no-undefined
181 LIBS := -lm
182 LIB_SO_EXT := .dll
183 # DEVNULL := NUL # Required if using cmd.exe and not bash.
184 endif
186 ifeq ($(HOST_SYSTEM), Darwin)
187 # LIBTOOL := MACOSX_DEPLOYMENT_TARGET=10.3 glibtool
188 LIBTOOL := glibtool
189 PLUGINS := cocoa-windows.so
190 endif
192 ifeq ($(HOST_SYSTEM), DragonFly)
193 LIBS := -lm
194 endif
196 ifeq ($(HOST_SYSTEM), FreeBSD)
197 LIBS := -lm -lc_r
198 LIBTOOL := libtool13
199 endif
201 ifeq ($(HOST_SYSTEM), HP-UX)
202 LIBS := -lm -ldld
203 LIB_SO_EXT := .sl
204 PLUGINS := platform.so posix.so pipe.so
205 endif
207 ifeq ($(HOST_SYSTEM), Linux)
208 LIBS := -lm -ldl
209 PLUGINS += gtk-wrapper.so gdk-wrapper.so glib-wrapper.so llvm-wrapper.so
210 endif
212 ifeq ($(findstring MINGW,$(HOST_SYSTEM)), MINGW)
213 PLATFORM := windows
214 LIBS := -lm
215 endif
217 ifeq ($(HOST_SYSTEM), NetBSD)
218 LIBS := -lm
219 endif
221 ifeq ($(HOST_SYSTEM), SunOS)
222 PLUGINS := platform.so posix.so pipe.so
223 # Work around GCC Ultra SPARC alignment bug
224 # TODO: Should be CPU specific.
225 COPTFLAGS := $(subst -O2,-O0, $(COPTFLAGS))
226 endif
228 PLUGINS := $(subst .so,$(LIB_SO_EXT), $(PLUGINS))