forked from sass/sassc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
248 lines (210 loc) · 5.03 KB
/
Makefile
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
CC ?= gcc
CXX ?= g++
RM ?= rm -f
CP ?= cp -a
CHDIR ?= chdir
MKDIR ?= mkdir
WINDRES ?= windres
INSTALL ?= install
CFLAGS ?= -Wall
CXXFLAGS ?= -Wall
LDFLAGS ?= -Wall
ifneq "$(COVERAGE)" "yes"
CFLAGS += -O2
CXXFLAGS += -O2
LDFLAGS += -O2
endif
LDFLAGS += -Wl,-undefined,error
CAT ?= $(if $(filter $(OS),Windows_NT),type,cat)
# If you run this under windows cmd.com interpreter:
# You must provide UnxUtils rm.exe and cp.exe in path
# Otherwise certain targets may not work as intended!
# Note: It seems impossible to replace `mkdir` command
ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
TARGET := Windows
else
ifneq (,$(findstring Windows,$(PATH)))
UNAME := Windows
TARGET := Windows
else
ifneq (,$(findstring mingw32,$(MAKE)))
UNAME := MinGW
TARGET := Windows
else
ifneq (,$(findstring MINGW32,$(shell uname -s)))
UNAME = MinGW
TARGET := Windows
else
UNAME := $(shell uname -s)
TARGET := $(shell uname -s)
endif
endif
endif
endif
ifeq ($(SASS_SASSC_PATH),)
SASS_SASSC_PATH = $(abspath $(CURDIR))
endif
ifeq ($(SASS_LIBSASS_PATH),)
SASS_LIBSASS_PATH = $(abspath $(CURDIR)/..)
endif
ifeq ($(SASSC_VERSION),)
ifneq ($(wildcard ./.git/ ),)
SASSC_VERSION ?= $(shell git describe --abbrev=4 --dirty --always --tags)
endif
endif
ifeq ($(SASSC_VERSION),)
ifneq ($(wildcard VERSION),)
SASSC_VERSION ?= $(shell $(CAT) VERSION)
endif
endif
ifneq ($(SASSC_VERSION),)
CFLAGS += -DSASSC_VERSION="\"$(SASSC_VERSION)\""
CXXFLAGS += -DSASSC_VERSION="\"$(SASSC_VERSION)\""
endif
# enable mandatory flag
ifeq (Windows,$(TARGET))
ifneq ($(BUILD),shared)
STATIC_ALL ?= 1
endif
STATIC_LIBGCC ?= 1
STATIC_LIBSTDCPP ?= 1
CXXFLAGS += -std=gnu++0x
LDFLAGS += -std=gnu++0x
else
STATIC_ALL ?= 0
STATIC_LIBGCC ?= 0
STATIC_LIBSTDCPP ?= 0
CXXFLAGS += -std=c++0x
LDFLAGS += -std=c++0x
endif
ifneq ($(SASS_LIBSASS_PATH),)
CFLAGS += -I $(SASS_LIBSASS_PATH)/include
CXXFLAGS += -I $(SASS_LIBSASS_PATH)/include
# only needed to support old source tree
# we have moved the files to src folder
CFLAGS += -I $(SASS_LIBSASS_PATH)
CXXFLAGS += -I $(SASS_LIBSASS_PATH)
else
# this is needed for mingw
CFLAGS += -I include
CXXFLAGS += -I include
endif
ifneq ($(EXTRA_CFLAGS),)
CFLAGS += $(EXTRA_CFLAGS)
endif
ifneq ($(EXTRA_CXXFLAGS),)
CXXFLAGS += $(EXTRA_CXXFLAGS)
endif
ifneq ($(EXTRA_LDFLAGS),)
LDFLAGS += $(EXTRA_LDFLAGS)
endif
LDLIBS = -lm
ifneq ($(BUILD),shared)
LDLIBS += -lstdc++
endif
# link statically into lib
# makes it a lot more portable
# increases size by about 50KB
ifeq ($(STATIC_ALL),1)
LDFLAGS += -static
endif
ifeq ($(STATIC_LIBGCC),1)
LDFLAGS += -static-libgcc
endif
ifeq ($(STATIC_LIBSTDCPP),1)
LDFLAGS += -static-libstdc++
endif
ifeq ($(UNAME),Darwin)
CFLAGS += -stdlib=libc++
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
endif
ifneq (Windows,$(TARGET))
ifneq (FreeBSD,$(UNAME))
LDFLAGS += -ldl
LDLIBS += -ldl
endif
endif
ifneq ($(BUILD),shared)
BUILD = static
endif
ifeq (,$(PREFIX))
ifeq (,$(TRAVIS_BUILD_DIR))
PREFIX = /usr/local
else
PREFIX = $(TRAVIS_BUILD_DIR)
endif
endif
SOURCES = sassc.c
LIB_STATIC = $(SASS_LIBSASS_PATH)/lib/libsass.a
LIB_SHARED = $(SASS_LIBSASS_PATH)/lib/libsass.so
RESOURCES =
SASSC_EXE = bin/sassc
ifeq (Windows,$(TARGET))
RESOURCES = libsass.res
SASSC_EXE = bin/sassc.exe
ifeq (shared,$(BUILD))
CFLAGS += -D ADD_EXPORTS
CXXFLAGS += -D ADD_EXPORTS
LIB_SHARED = $(SASS_LIBSASS_PATH)/lib/libsass.dll
endif
else
CFLAGS += -fPIC
CXXFLAGS += -fPIC
LDFLAGS += -fPIC
endif
OBJECTS = $(SOURCES:.c=.o)
SPEC_PATH = $(SASS_SPEC_PATH)
all: sassc
sassc: $(SASSC_EXE)
$(SASSC_EXE): libsass build-$(BUILD)
$(DESTDIR)$(PREFIX)/:
$(MKDIR) $(DESTDIR)$(PREFIX)
$(DESTDIR)$(PREFIX)/bin/:
$(MKDIR) $(DESTDIR)$(PREFIX)/bin
$(DESTDIR)$(PREFIX)/bin/%: bin/%
$(INSTALL) -D -v -m0755 "$<" "$@"
install: $(DESTDIR)$(PREFIX)/$(SASSC_EXE)
build-static: $(RESOURCES) $(OBJECTS) $(LIB_STATIC)
$(CC) $(LDFLAGS) -o $(SASSC_EXE) $^ $(LDLIBS)
build-shared: $(RESOURCES) $(OBJECTS) $(LIB_SHARED)
$(CC) $(LDFLAGS) -o $(SASSC_EXE) $^ $(LDLIBS)
$(CP) $(LIB_SHARED) bin/.
$(LIB_STATIC): libsass-static
$(LIB_SHARED): libsass-shared
libsass: libsass-$(BUILD)
libsass-static:
ifdef SASS_LIBSASS_PATH
$(MAKE) BUILD="static" -C $(SASS_LIBSASS_PATH)
else
$(error SASS_LIBSASS_PATH must be defined)
endif
libsass-shared:
ifdef SASS_LIBSASS_PATH
$(MAKE) BUILD="shared" -C $(SASS_LIBSASS_PATH)
else
$(error SASS_LIBSASS_PATH must be defined)
endif
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
test: all
$(MAKE) -C $(SASS_LIBSASS_PATH) version
libsass.res:
$(WINDRES) res/libsass.rc -O coff libsass.res
specs: all
ifdef SASS_LIBSASS_PATH
$(MAKE) -C $(SASS_LIBSASS_PATH) test_build
else
$(error SASS_LIBSASS_PATH must be defined)
endif
clean:
rm -f $(OBJECTS) $(SASSC_EXE) \
bin/*.so bin/*.dll libsass.res
ifdef SASS_LIBSASS_PATH
$(MAKE) -C $(SASS_LIBSASS_PATH) clean
endif
.PHONY: test specs clean sassc \
all build-static build-shared \
libsass libsass-static libsass-shared
.DELETE_ON_ERROR: