Skip to content

Commit f477cd6

Browse files
glebmxzyfer
authored andcommitted
Makefile cleanup
1. Flattens nested if-else chains. 2. Replaces undefined-or-empty variable checks (`ifeq (,$(SOMEVAR))`) with `ifdef SOMEVAR`. 3. Merges two mostly duplicate sections of Windows-specific overrides. 4. Removes is-empty checks before `+= $(VAR)` (no-op if `VAR` is empty).
1 parent 392ffe1 commit f477cd6

File tree

1 file changed

+28
-68
lines changed

1 file changed

+28
-68
lines changed

Makefile

+28-68
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ INSTALL ?= install
1515
CFLAGS ?= -Wall
1616
CXXFLAGS ?= -Wall
1717
LDFLAGS ?= -Wall
18-
ifeq "x$(COVERAGE)" "x"
18+
ifndef COVERAGE
1919
CFLAGS += -O2
2020
CXXFLAGS += -O2
2121
LDFLAGS += -O2
@@ -28,39 +28,25 @@ CAT ?= $(if $(filter $(OS),Windows_NT),type,cat)
2828

2929
ifneq (,$(findstring /cygdrive/,$(PATH)))
3030
UNAME := Cygwin
31+
else ifneq (,$(findstring Windows_NT,$(OS)))
32+
UNAME := Windows
33+
else ifneq (,$(findstring mingw32,$(MAKE)))
34+
UNAME := Windows
35+
else ifneq (,$(findstring MINGW32,$(shell uname -s)))
36+
UNAME := Windows
3137
else
32-
ifneq (,$(findstring Windows_NT,$(OS)))
33-
UNAME := Windows
34-
else
35-
ifneq (,$(findstring mingw32,$(MAKE)))
36-
UNAME := Windows
37-
else
38-
ifneq (,$(findstring MINGW32,$(shell uname -s)))
39-
UNAME = Windows
40-
else
41-
UNAME := $(shell uname -s)
42-
endif
43-
endif
44-
endif
45-
endif
46-
47-
ifeq ($(SASS_LIBSASS_PATH),)
48-
SASS_LIBSASS_PATH = $(abspath $(CURDIR))
38+
UNAME := $(shell uname -s)
4939
endif
5040

51-
ifeq ($(LIBSASS_VERSION),)
41+
ifndef LIBSASS_VERSION
5242
ifneq ($(wildcard ./.git/ ),)
5343
LIBSASS_VERSION ?= $(shell git describe --abbrev=4 --dirty --always --tags)
5444
endif
55-
endif
56-
57-
ifeq ($(LIBSASS_VERSION),)
5845
ifneq ($(wildcard VERSION),)
5946
LIBSASS_VERSION ?= $(shell $(CAT) VERSION)
6047
endif
6148
endif
62-
63-
ifneq ($(LIBSASS_VERSION),)
49+
ifdef LIBSASS_VERSION
6450
CFLAGS += -DLIBSASS_VERSION="\"$(LIBSASS_VERSION)\""
6551
CXXFLAGS += -DLIBSASS_VERSION="\"$(LIBSASS_VERSION)\""
6652
endif
@@ -82,7 +68,10 @@ else
8268
LDFLAGS += -std=c++0x
8369
endif
8470

85-
ifneq ($(SASS_LIBSASS_PATH),)
71+
ifndef SASS_LIBSASS_PATH
72+
SASS_LIBSASS_PATH = $(abspath $(CURDIR))
73+
endif
74+
ifdef SASS_LIBSASS_PATH
8675
CFLAGS += -I $(SASS_LIBSASS_PATH)/include
8776
CXXFLAGS += -I $(SASS_LIBSASS_PATH)/include
8877
else
@@ -91,18 +80,11 @@ else
9180
CXXFLAGS += -I include
9281
endif
9382

94-
ifneq ($(EXTRA_CFLAGS),)
95-
CFLAGS += $(EXTRA_CFLAGS)
96-
endif
97-
ifneq ($(EXTRA_CXXFLAGS),)
98-
CXXFLAGS += $(EXTRA_CXXFLAGS)
99-
endif
100-
ifneq ($(EXTRA_LDFLAGS),)
101-
LDFLAGS += $(EXTRA_LDFLAGS)
102-
endif
83+
CFLAGS += $(EXTRA_CFLAGS)
84+
CXXFLAGS += $(EXTRA_CXXFLAGS)
85+
LDFLAGS += $(EXTRA_LDFLAGS)
10386

10487
LDLIBS = -lm
105-
10688
ifneq ($(BUILD),shared)
10789
LDLIBS += -lstdc++
10890
endif
@@ -142,7 +124,7 @@ ifeq ($(DEBUG),1)
142124
BUILD := debug-$(BUILD)
143125
endif
144126

145-
ifeq (,$(TRAVIS_BUILD_DIR))
127+
ifndef TRAVIS_BUILD_DIR
146128
ifeq ($(OS),SunOS)
147129
PREFIX ?= /opt/local
148130
else
@@ -152,54 +134,34 @@ else
152134
PREFIX ?= $(TRAVIS_BUILD_DIR)
153135
endif
154136

155-
156137
SASS_SASSC_PATH ?= sassc
157138
SASS_SPEC_PATH ?= sass-spec
158139
SASS_SPEC_SPEC_DIR ?= spec
159140
SASSC_BIN = $(SASS_SASSC_PATH)/bin/sassc
160141
RUBY_BIN = ruby
161142

143+
RESOURCES =
144+
STATICLIB = lib/libsass.a
145+
SHAREDLIB = lib/libsass.so
162146
LIB_STATIC = $(SASS_LIBSASS_PATH)/lib/libsass.a
163147
LIB_SHARED = $(SASS_LIBSASS_PATH)/lib/libsass.so
164148

165-
ifeq (Windows,$(UNAME))
166-
ifeq (shared,$(BUILD))
167-
CFLAGS += -D ADD_EXPORTS
168-
CXXFLAGS += -D ADD_EXPORTS
169-
LIB_SHARED = $(SASS_LIBSASS_PATH)/lib/libsass.dll
170-
endif
171-
else
172-
ifneq (Cygwin,$(UNAME))
173-
CFLAGS += -fPIC
174-
CXXFLAGS += -fPIC
175-
LDFLAGS += -fPIC
176-
endif
177-
endif
178-
179149
ifeq (Windows,$(UNAME))
180150
SASSC_BIN = $(SASS_SASSC_PATH)/bin/sassc.exe
181-
endif
182-
183-
include Makefile.conf
184-
185-
RESOURCES =
186-
STATICLIB = lib/libsass.a
187-
SHAREDLIB = lib/libsass.so
188-
ifeq (Windows,$(UNAME))
189151
RESOURCES += res/resource.rc
190152
SHAREDLIB = lib/libsass.dll
191153
ifeq (shared,$(BUILD))
192154
CFLAGS += -D ADD_EXPORTS
193155
CXXFLAGS += -D ADD_EXPORTS
156+
LIB_SHARED = $(SASS_LIBSASS_PATH)/lib/libsass.dll
194157
endif
195-
else
196-
ifneq (Cygwin,$(UNAME))
197-
CFLAGS += -fPIC
198-
CXXFLAGS += -fPIC
199-
LDFLAGS += -fPIC
200-
endif
158+
else ifneq (Cygwin,$(UNAME))
159+
CFLAGS += -fPIC
160+
CXXFLAGS += -fPIC
161+
LDFLAGS += -fPIC
201162
endif
202163

164+
include Makefile.conf
203165
OBJECTS = $(addprefix src/,$(SOURCES:.cpp=.o))
204166
COBJECTS = $(addprefix src/,$(CSOURCES:.c=.o))
205167
RCOBJECTS = $(RESOURCES:.rc=.o)
@@ -303,11 +265,9 @@ sassc: $(SASSC_BIN)
303265
$(SASSC_BIN) -v
304266

305267
version: $(SASSC_BIN)
306-
$(SASSC_BIN) -h
307268
$(SASSC_BIN) -v
308269

309-
test: $(SASSC_BIN)
310-
$(RUBY_BIN) $(SASS_SPEC_PATH)/sass-spec.rb -V 3.5 -c $(SASSC_BIN) --impl libsass $(LOG_FLAGS) $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)
270+
test: test_build
311271

312272
test_build: $(SASSC_BIN)
313273
$(RUBY_BIN) $(SASS_SPEC_PATH)/sass-spec.rb -V 3.5 -c $(SASSC_BIN) --impl libsass $(LOG_FLAGS) $(SASS_SPEC_PATH)/$(SASS_SPEC_SPEC_DIR)

0 commit comments

Comments
 (0)