Added support to Platform for detecting whether on a POSIX or Windows system, and...
[cslatevm.git] / common.mk
blobdce06cc83850461c7227a1e6d6dafb76f7ef84e4
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
25 ifndef QUIETNESS
26 QUIETNESS := -q
27 endif
29 ifdef QUIET
30 VERBOSE := 0
31 SILENT := @
32 SILENT_ERRORS := 2> $(DEVNULL)
33 LIBTOOL_FLAGS += --silent
34 endif
36 ifdef DEBUG
37 MODE := debug
38 COPTFLAGS += -g
39 CFLAGS += -DSLATE_BUILD_TYPE="\"Debug\""
40 else
41 ifdef PROFILE
42 MODE += profiled
43 COPTFLAGS += -pg -g -O2 -fprofile-arcs -ftest-coverage
44 CFLAGS += -DSLATE_BUILD_TYPE="\"Profile\""
45 else
46 MODE := optimized
47 CFLAGS += -DSLATE_BUILD_TYPE="\"Optimized\""
48 COPTFLAGS += -O2
49 endif
50 endif
52 ## All required executables
54 CC := gcc
55 CPP := g++
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 -D_POSIX_C_SOURCE=200112L
71 CFLAGS += $(COPTFLAGS) -Wall -Wno-unknown-pragmas -pthread $(PRINT_DEBUG) $(EXTRACFLAGS) $(INCLUDES)
72 # include -pedantic later fixme
74 ## Determine the host system's byte order.
75 ## This creates a temporary test executable in the $(slateroot) directory
76 ## since we can guarantee write permissions there on all platforms.
78 BYTE_ORDER_FN := $(slateroot)/byteorder
79 BYTE_ORDER_SRC := "int main(){union{long l;char c[sizeof(long)];}u;u.l=1;return(u.c[sizeof(long)-1]==1);}"
80 BYTE_ORDER := $(shell echo $(BYTE_ORDER_SRC) > $(BYTE_ORDER_FN).c)
81 BYTE_ORDER := $(shell $(CC) -o $(BYTE_ORDER_FN) $(BYTE_ORDER_FN).c)
82 BYTE_ORDER := $(shell $(BYTE_ORDER_FN); echo $$?)
83 BYTE_ORDER_ := $(shell $(RM) $(BYTE_ORDER_FN).* $(BYTE_ORDER_FN) 1>&2)
84 ifeq ($(BYTE_ORDER),0)
85 BYTE_ORDER := LITTLE_ENDIAN
86 BYTE_ORDER_PREFIX := little
87 LITTLE_ENDIAN_SLATE := True
88 else
89 BYTE_ORDER := BIG_ENDIAN
90 BYTE_ORDER_PREFIX := big
91 LITTLE_ENDIAN_SLATE := False
92 endif
94 ## Default variables
96 PLATFORM := unix
97 CCVERSION := $(shell $(CC) -dumpversion)
98 #WORD_SIZE := 32
99 LDFLAGS := # -avoid-version
100 LIBS := #-lm -ldl
101 #PLUGINS := platform.so posix.so pipe.so
102 #PLUGINS := x-windows.so
103 PLUGINS :=
104 HOST_SYSTEM := $(shell uname -s)
105 LIB_SO_EXT := .so
106 INSTALL_MODE := -m 644
107 CPU_TYPE := `uname -m`
108 VM_LIBRARIES = -lm -ldl -lpthread
110 VMNAME := vm
111 VMDIR := $(slateroot)/src/vm
112 VM := $(VMDIR)/$(VMNAME)
113 DEFAULT_IMAGE ?= slate.image
114 KERNEL_IMAGES := kernel.new.*.$(WORD_SIZE).*.image
115 DEFAULT_KERNEL_IMAGE ?= $(shell ls -t $(KERNEL_IMAGES) | head -1)
117 CFLAGS_x-windows.c=`pkg-config --cflags x11` `pkg-config --cflags cairo` -Werror
118 LDFLAGS_x-windows.lo=`pkg-config --libs x11` `pkg-config --libs cairo`
119 CFLAGS_cocoa-windows.c=`pkg-config --cflags cocoa` `pkg-config --cflags cairo`
120 LDFLAGS_cocoa-windows.lo=`pkg-config --libs cocoa` `pkg-config --libs cairo`
121 CFLAGS_glib-wrapper.c=`pkg-config --cflags glib-2.0`
122 LDFLAGS_glib-wrapper.lo=`pkg-config --libs glib-2.0` `pkg-config --libs gobject-2.0`
123 CFLAGS_gdk-wrapper.c=`pkg-config --cflags gdk-2.0`
124 LDFLAGS_gdk-wrapper.lo=`pkg-config --libs gdk-2.0` `pkg-config --libs gthread-2.0`
125 CFLAGS_gtk-wrapper.c=`pkg-config --cflags gtk+-2.0`
126 LDFLAGS_gtk-wrapper.lo=`pkg-config --libs gtk+-2.0`
127 CFLAGS_llvm-wrapper.c=`llvm-config --cflags`
128 LDFLAGS_llvm-wrapper.lo=
130 #CFLAGS_socket.c=
132 PRINT_DEBUG_G=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG_GC_1 -DPRINT_DEBUG_OPCODES
133 PRINT_DEBUG_Y= -DPRINT_DEBUG_STACK_POINTER -DPRINT_DEBUG_STACK_PUSH -DPRINT_DEBUG_FOUND_ROLE -DPRINT_DEBUG_FUNCALL
134 PRINT_DEBUG_X=-DPRINT_DEBUG -DPRINT_DEBUG_OPCODES -DPRINT_DEBUG_INSTRUCTION_COUNT -DPRINT_DEBUG_CODE_POINTER -DPRINT_DEBUG_DISPATCH
135 PRINT_DEBUG_1=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG_GC_1
136 PRINT_DEBUG_4=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG_GC -DPRINT_DEBUG_OPCODES -DPRINT_DEBUG_CODE_POINTER -DPRINT_DEBUG_ENSURE -DPRINT_DEBUG_STACK
137 PRINT_DEBUG_3=-DPRINT_DEBUG_DEFUN -DPRINT_DEBUG_GC -DPRINT_DEBUG_OPTIMIZER -DPRINT_DEBUG_PIC_HITS -DPRINT_DEBUG_UNOPTIMIZER
138 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
139 PRINT_DEBUG=$(PRINT_DEBUG_1)
141 ## Determine CPU type
143 ## TODO: Sparc detection for SunOS?
144 ## TODO: Base CPU type on real information, not just generic OS variant
146 ## CPU-type specific overrides. Any of the variables above may be changed here.
148 ifdef ARCH
149 CFLAGS += -m$(ARCH)
150 endif
152 ifdef VERSION
153 CFLAGS += -DVERSION="\"$(VERSION)\""
154 endif
156 CFLAGS +=-DSLATE_DEFAULT_IMAGE=$(DEFAULT_IMAGE)
158 ifdef WORD_SIZE
159 CFLAGS += -m$(WORD_SIZE)
160 endif
162 #ifeq ($(CPU_TYPE), i686)
163 # CFLAGS += -m$(WORD_SIZE)
164 #endif
166 #ifeq ($(CPU_TYPE), x86_64)
167 # CFLAGS += -m$(WORD_SIZE)
168 #endif
170 ## Platform specific overrides. Any of the variables above may be changed here.
172 ifeq ($(HOST_SYSTEM), AIX)
173 LIB_SO_EXT := .a
174 PLUGINS := platform.so posix.so pipe.so
175 endif
177 ifeq ($(HOST_SYSTEM), BeOS)
178 PLATFORM := beos
179 endif
181 ifeq ($(findstring CYGWIN,$(HOST_SYSTEM)), CYGWIN)
182 PLATFORM := windows
183 LDFLAGS += -no-undefined
184 LIBS := -lm
185 LIB_SO_EXT := .dll
186 # DEVNULL := NUL # Required if using cmd.exe and not bash.
187 endif
189 ifeq ($(HOST_SYSTEM), Darwin)
190 # LIBTOOL := MACOSX_DEPLOYMENT_TARGET=10.3 glibtool
191 LIBTOOL := glibtool
192 PLUGINS := cocoa-windows.so
193 endif
195 ifeq ($(HOST_SYSTEM), DragonFly)
196 LIBS := -lm
197 endif
199 ifeq ($(HOST_SYSTEM), FreeBSD)
200 LIBS := -lm -lc_r
201 LIBTOOL := libtool13
202 endif
204 ifeq ($(HOST_SYSTEM), HP-UX)
205 LIBS := -lm -ldld
206 LIB_SO_EXT := .sl
207 PLUGINS := platform.so posix.so pipe.so
208 endif
210 ifeq ($(HOST_SYSTEM), Linux)
211 LIBS := -lm -ldl
212 PLUGINS += gtk-wrapper.so gdk-wrapper.so glib-wrapper.so llvm-wrapper.so x-windows.so
213 endif
215 ifeq ($(findstring MINGW,$(HOST_SYSTEM)), MINGW)
216 PLATFORM := windows
217 LIBS := -lm
218 endif
220 ifeq ($(HOST_SYSTEM), NetBSD)
221 LIBS := -lm
222 endif
224 ifeq ($(HOST_SYSTEM), SunOS)
225 PLUGINS := platform.so posix.so pipe.so
226 # Work around GCC Ultra SPARC alignment bug
227 # TODO: Should be CPU specific.
228 COPTFLAGS := $(subst -O2,-O0, $(COPTFLAGS))
229 endif
231 PLUGINS := $(subst .so,$(LIB_SO_EXT), $(PLUGINS))