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
|
## file melt-module.mk
## a -*- Makefile -*- for GNU make.
# Copyright (C) 2009 Free Software Foundation, Inc.
# Contributed by Basile Starynkevitch <basile@starynkevitch.net>
# This file is part of GCC.
# GCC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# GCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3. If not see
# <http://www.gnu.org/licenses/>.
### should be invoked, perhaps from melt-runtime.c, with
#### make -f melt-module.mk \
#### GCCMELT_MODULE_SOURCE=foo.c \
#### GCCMELT_MODULE_BINARY=foo.so \
#### GCCMELT_MODULE_WORKSPACE=/tmp
ifndef GCCMELT_MODULE_SOURCE
$(error GCCMELT_MODULE_SOURCE not defined)
endif
ifndef GCCMELT_MODULE_BINARY
$(error GCCMELT_MODULE_BINARY not defined)
endif
ifndef GCCMELT_MODULE_WORKSPACE
GCCMELT_MODULE_WORKSPACE=.
endif
MELTMODULE_BASENAME:=$(basename $(GCCMELT_MODULE_SOURCE))
MELTMODULE_PLAIN:=$(notdir $(MELTMODULE_BASENAME))
MELTMODULE_SRCDIR:=$(dir $(GCCMELT_MODULE_SOURCE))
## Usually, when melt_module_withoutline is the sole target, the
## GCCMELT_MODULE_BINARY already ends with .n.so, so we don"t have to
## generate it. In some rare occasions, both melt_module &
## melt_module_withoutline could be explicitly given targets, with
## GCCMELT_MODULE_BINARY=foo.so
##
## so we need to patsubst only when the original suffix is just .so,
## not when it is already .d.so or .n.so
## The .d.so & .n.so suffixes are wired in melt-runtime.c!
MELTMODULE_DYNAMIC:= \
$(patsubst %.so, %.d.so, $(filter-out %.d.so, $(GCCMELT_MODULE_BINARY))) \
$(filter %.d.so, $(GCCMELT_MODULE_BINARY))
MELTMODULE_NOLINE:= \
$(patsubst %.so, %.n.so, $(filter-out %.n.so, $(GCCMELT_MODULE_BINARY))) \
$(filter %.n.so, $(GCCMELT_MODULE_BINARY))
MELTSTAMP:=$(GCCMELT_MODULE_WORKSPACE)/$(MELTMODULE_PLAIN)-stamp.c
MELTMODULE_CFILES:=$(wildcard $(MELTMODULE_BASENAME).c $(MELTMODULE_BASENAME)+*.c)
MELTMODULE_OBJPICFILES:=$(patsubst %.c, $(GCCMELT_MODULE_WORKSPACE)/%.pic.o, $(notdir $(MELTMODULE_CFILES)))
MELTMODULE_OBJDYNPICFILES:=$(patsubst %.c, $(GCCMELT_MODULE_WORKSPACE)/%.dynpic.o, $(notdir $(MELTMODULE_CFILES)))
MELTMODULE_OBJNOLPICFILES:=$(patsubst %.c, $(GCCMELT_MODULE_WORKSPACE)/%.nolpic.o, $(notdir $(MELTMODULE_CFILES)))
ifndef GCCMELT_CC
GCCMELT_CC=gcc
endif
ifndef GCCMELT_CFLAGS
GCCMELT_CFLAGS=-O
endif
RM=rm -f
MD5SUM=md5sum
.PHONY: melt_module melt_module_dynamic melt_module_rawdynamic melt_module_withoutline melt_clean
melt_module: $(GCCMELT_MODULE_BINARY)
melt_module_dynamic: $(MELTMODULE_DYNAMIC)
melt_module_rawdynamic: $(GCCMELT_MODULE_BINARY)
# melt_module_rawdynamic: override GCCMELT_CFLAGS += -DMELTGCC_DYNAMIC_OBJSTRUCT
melt_module_withoutline: $(MELTMODULE_NOLINE)
melt_module_rawwithoutline: $(GCCMELT_MODULE_BINARY)
$(GCCMELT_MODULE_BINARY): $(MELTMODULE_OBJPICFILES) $(MELTSTAMP)
$(GCCMELT_CC) $(GCCMELT_CFLAGS) -fPIC -shared \
$(MELTMODULE_OBJPICFILES) $(MELTSTAMP) -o $@
$(RM) $(MELTSTAMP)
$(MELTMODULE_DYNAMIC): $(MELTMODULE_OBJDYNPICFILES) $(MELTSTAMP)
$(GCCMELT_CC) $(GCCMELT_CFLAGS) -DMELTGCC_DYNAMIC_OBJSTRUCT \
-fPIC -shared $(MELTMODULE_OBJDYNPICFILES) $(MELTSTAMP) -o $@
$(RM) $(MELTSTAMP)
$(MELTMODULE_NOLINE): $(MELTMODULE_OBJNOLPICFILES) $(MELTSTAMP)
$(GCCMELT_CC) $(GCCMELT_CFLAGS) -DMELTGCC_NOLINENUMBERING \
-fPIC -shared $(MELTMODULE_OBJNOLPICFILES) $(MELTSTAMP) -o $@
$(RM) $(MELTSTAMP)
$(GCCMELT_MODULE_WORKSPACE)/%.pic.o: $(MELTMODULE_SRCDIR)/%.c
$(GCCMELT_CC) $(GCCMELT_CFLAGS) -fPIC -c -o $@ $<
$(GCCMELT_MODULE_WORKSPACE)/%.dynpic.o: $(MELTMODULE_SRCDIR)/%.c
$(GCCMELT_CC) $(GCCMELT_CFLAGS) -DMELTGCC_DYNAMIC_OBJSTRUCT -fPIC -c -o $@ $<
$(GCCMELT_MODULE_WORKSPACE)/%.nolpic.o: $(MELTMODULE_SRCDIR)/%.c
$(GCCMELT_CC) $(GCCMELT_CFLAGS) -DMELTGCC_NOLINENUMBERING -fPIC -c -o $@ $<
$(MELTSTAMP): $(MELTMODULE_CFILES)
echo '/*' generated file $(MELTSTAMP) '*/' > $@-tmp
date "+const char melt_compiled_timestamp[]=\"%c $(MELTMODULE)\";" >> $@-tmp
echo "const char melt_md5[]=\"\\" >> $@-tmp
for f in $(MELTMODULE_CFILES); do \
md5line=`$(MD5SUM) $$f` ; \
printf "%s\\\n" $$md5line >> $@-tmp; \
done
echo "\";" >> $@-tmp
echo "const char melt_csource[]=\"$(MELTMODULE_CFILES)\";" >> $@-tmp
mv $@-tmp $@
melt_clean:
$(RM) $(MELTMODULE_OBJPICFILES) \
$(MELTMODULE_OBJNOLPICFILES) \
$(MELTMODULE_OBJDYNPICFILES) \
$(MELTSTAMP) \
$(GCCMELT_MODULE_BINARY) \
$(MELTMODULE_DYNAMIC) \
$(MELTMODULE_NOLINE)
## eof melt-module.mk
|