summaryrefslogtreecommitdiff
path: root/Makefile
blob: a59853ff5c567a19d44036c7ba8edbf8e90f9b62 (plain)
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
COMMON_SOURCES = \
	allchblk.c \
	alloc.c \
	backgraph.c \
	blacklst.c \
	checksums.c \
	dbg_mlc.c \
	finalize.c \
	fnlz_mlc.c \
	gcj_mlc.c \
	headers.c \
	mach_dep.c \
	malloc.c \
	mallocx.c \
	mark.c \
	mark_rts.c \
	misc.c \
	new_hblk.c \
	obj_map.c \
	os_dep.c \
	pcr_interface.c \
	ptr_chck.c \
	real_malloc.c \
	reclaim.c \
	specific.c \
	stubborn.c \
	thread_local_alloc.c \
	typd_mlc.c

LINUX_SOURCES = \
	dyn_load.c \
	gc_dlopen.c \
	pthread_start.c \
	pthread_stop_world.c \
	pthread_support.c

OCTOPOS_SOURCES = \
	octopos_threads.c

DARWIN_SOURCES = \
	dyn_load.c \
	darwin_stop_world.c \
	gc_dlopen.c

GUESSED_TARGET := $(shell $(CC) -dumpmachine)
TARGET         ?= $(GUESSED_TARGET)
CC              = $(TARGET)-gcc

CPPFLAGS  = -Iinclude/ -DATOMIC_UNCOLLECTABLE -DNO_EXECUTE_PERMISSION -DALL_INTERIOR_POINTERS
CPPFLAGS += -DGC_ASSERTIONS
CFLAGS    = -O2 -g -Wall -W

# Architecture-specific stuff
ifeq ($(findstring sparc, $(TARGET)), sparc)
	EXTRA_OBJECTS += src/sparc_mach_dep.o
endif
ifeq ($(findstring x86_64, $(GUESSED_TARGET)), x86_64)
ifeq ($(findstring i686, $(TARGET)), i686)
	CFLAGS += -m32
endif
endif

# Operating-system-specific stuff
ifeq ($(findstring linux, $(TARGET)), linux)
	SOURCES        = $(COMMON_SOURCES) $(LINUX_SOURCES)
	CPPFLAGS      += -Ilibatomic_ops/src
	CPPFLAGS      += -DGC_LINUX_THREADS -DPARALLEL_MARK -DTHREAD_LOCAL_ALLOC
	EXTRA_OBJECTS  = libatomic_ops/libatomic_ops.a
endif
ifeq ($(findstring invasic, $(TARGET)), invasic)
	SOURCES = $(COMMON_SOURCES) $(OCTOPOS_SOURCES)
	CFLAGS += -ffreestanding
endif
ifeq ($(findstring darwin, $(TARGET)), darwin)
	SOURCES = $(COMMON_SOURCES) $(DARWIN_SOURCES)
endif

# Platform-specific stuff
OCTOPOS_RELEASE = current

ifeq ($(findstring invasic, $(TARGET)), invasic)
	CFLAGS   += -fno-stack-protector
	CPPFLAGS += -nostdinc -Ulinux -U__linux -U__linux__ -U__gnu_linux__ -Uunix -U__unix -U__unix__ -D__OCTOPOS__
endif

ifeq ($(findstring i686-invasic, $(TARGET)), i686-invasic)
	OCTOPOS_ARCH    = x86guest
	OCTOPOS_VARIANT = default
	OCTOPOS_BASE    = ../octopos-app/releases/$(OCTOPOS_RELEASE)/$(OCTOPOS_ARCH)/$(OCTOPOS_VARIANT)
	GCC_INCLUDE     = $(shell $(CC) --print-file-name=include)

	CFLAGS   += -mfpmath=sse -msse2 -m32
	CPPFLAGS += -I$(OCTOPOS_BASE)/include -isystem $(GCC_INCLUDE)
endif
ifeq ($(findstring x86_64-invasic, $(TARGET)), x86_64-invasic)
	OCTOPOS_ARCH    = x64native
	OCTOPOS_VARIANT = default
	OCTOPOS_BASE    = ../octopos-app/releases/$(OCTOPOS_RELEASE)/$(OCTOPOS_ARCH)/$(OCTOPOS_VARIANT)
	GCC_INCLUDE     = $(shell $(CC) --print-file-name=include)

	CFLAGS   += -mno-red-zone
	CPPFLAGS += -I$(OCTOPOS_BASE)/include -isystem $(GCC_INCLUDE)
endif
ifeq ($(findstring sparc-invasic, $(TARGET)), sparc-invasic)
	OCTOPOS_ARCH    = leon
	OCTOPOS_VARIANT = default
	OCTOPOS_BASE    = ../octopos-app/releases/$(OCTOPOS_RELEASE)/$(OCTOPOS_ARCH)/$(OCTOPOS_VARIANT)
	GCC_INCLUDE     = $(shell $(CC) --print-file-name=include)

	CPPFLAGS += -D__leon__ -I $(OCTOPOS_BASE)/include -isystem $(GCC_INCLUDE)
endif

BUILDDIR = build/$(TARGET)
OBJECTS  = $(SOURCES:%.c=$(BUILDDIR)/%.o)
ARCHIVE  = $(BUILDDIR)/gc.a
Q        = @

all: $(ARCHIVE)

$(ARCHIVE): $(BUILDDIR) $(OBJECTS) $(EXTRA_OBJECTS)
	$(Q)ar ru $(ARCHIVE) $(OBJECTS) $(EXTRA_OBJECTS)

$(BUILDDIR)/%.o: %.c
	@echo "CC $@"
	$(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

# Special objects
libatomic_ops/libatomic_ops.a: libatomic_ops/src/atomic_ops.o
	@echo "AR $@"
	$(Q)ar ru $@ $<

libatomic_ops/src/atomic_ops.o: libatomic_ops/src/atomic_ops.c
	@echo "CC $@"
	$(Q)$(CC) -c $< -o $@

src/sparc_mach_dep.o: src/sparc_mach_dep.S
	@echo "CC $@"
	$(Q)$(CC) -c $< -o $@

$(BUILDDIR):
	$(Q)mkdir -p $(BUILDDIR)

clean:
	$(Q)rm -f $(OBJECTS)
	$(Q)rm -f $(EXTRA_OBJECTS)
	$(Q)rm -f $(ARCHIVE)
	$(Q)rm -rf $(BUILDDIR)

.PHONY: all clean