Skip to content

Commit

Permalink
Makefile: adds support for absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
vedaldi committed Dec 8, 2009
1 parent 08c57c5 commit 5597066
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
44 changes: 24 additions & 20 deletions Makefile
Expand Up @@ -115,6 +115,9 @@ LIBTOOL ?= libtool
# programs required to build VLFeat distribution
GIT ?= git

# VLFeat root directory. Useful to use absolute paths in Xcode.
VLDIR ?= .

.PHONY : all
all : dll all-bin

Expand Down Expand Up @@ -210,9 +213,10 @@ DEBUG := yes
endif

C_CFLAGS = $(CFLAGS)
C_CFLAGS += -I. -pedantic -std=c99 -O3
C_CFLAGS += -I$(VLDIR)
C_CFLAGS += -pedantic -std=c99 -O3
C_CFLAGS += -Wall -Wno-unused-function -Wno-long-long
C_CFLAGS += $(if $(DEBUG), -O0 -g -std=c89)
C_CFLAGS += $(if $(DEBUG), -O0 -g)

C_LDFLAGS = $(LDFLAGS)
C_LDFLAGS += -L$(BINDIR) -l$(DLL_NAME)
Expand All @@ -221,7 +225,7 @@ DLL_NAME = vl
DLL_CFLAGS = $(C_CFLAGS) -fvisibility=hidden -fPIC -DVL_BUILD_DLL

MEX_FLAGS = $(if $(DEBUG), -g)
MEX_CFLAGS = $(C_CFLAGS) -Itoolbox
MEX_CFLAGS = $(CFLAGS) -I$(VLDIR) -I$(VLDIR)/toolbox
MEX_LDFLAGS = -L$(BINDIR) -l$(DLL_NAME)

ifdef MATLABPATH
Expand All @@ -234,7 +238,7 @@ endif

# Mac OS X on PPC processor
ifeq ($(ARCH),mac)
BINDIR := bin/mac
BINDIR := $(VLDIR)/bin/mac
DLL_SUFFIX := dylib
MEX_SUFFIX := mexmac
C_CFLAGS += -D__BIG_ENDIAN__ -Wno-variadic-macros
Expand All @@ -248,7 +252,7 @@ endif

# Mac OS X on Intel processor
ifeq ($(ARCH),maci)
BINDIR := bin/maci
BINDIR := $(VLDIR)/bin/maci
DLL_SUFFIX := dylib
MEX_SUFFIX := mexmaci
C_CFLAGS += -D__LITTLE_ENDIAN__ -Wno-variadic-macros
Expand All @@ -263,7 +267,7 @@ endif

# Mac OS X on Intel 64 processor
ifeq ($(ARCH),maci64)
BINDIR := bin/maci64
BINDIR := $(VLDIR)/bin/maci64
DLL_SUFFIX := dylib
MEX_SUFFIX := mexmaci64
C_CFLAGS += -D__LITTLE_ENDIAN__ -Wno-variadic-macros
Expand All @@ -278,7 +282,7 @@ endif

# Linux-32
ifeq ($(ARCH),glx)
BINDIR := bin/glx
BINDIR := $(VLDIR)/bin/glx
MEX_SUFFIX := mexglx
DLL_SUFFIX := so
C_CFLAGS += -D__LITTLE_ENDIAN__ -std=c99
Expand All @@ -293,7 +297,7 @@ endif

# Linux-64
ifeq ($(ARCH),a64)
BINDIR := bin/a64
BINDIR := $(VLDIR)/bin/a64
MEX_SUFFIX := mexa64
DLL_SUFFIX := so
C_CFLAGS += -D__LITTLE_ENDIAN__ -std=c99
Expand All @@ -307,7 +311,7 @@ endif

DIST := $(NAME)-$(VER)
BINDIST := $(DIST)-bin
MEX_BINDIR := toolbox/$(MEX_SUFFIX)
MEX_BINDIR := $(VLDIR)/toolbox/$(MEX_SUFFIX)

# Sanity check
ifeq ($(DLL_SUFFIX),)
Expand Down Expand Up @@ -367,8 +371,8 @@ $(eval $(call gendir, noprefix, toolbox/noprefix ))

dll_tgt := $(BINDIR)/lib$(DLL_NAME).$(DLL_SUFFIX)
dll_lnk := $(MEX_BINDIR)/lib$(DLL_NAME).$(DLL_SUFFIX)
dll_src := $(wildcard vl/*.c)
dll_hdr := $(wildcard vl/*.h) $(wildcard vl/*.tc)
dll_src := $(wildcard $(VLDIR)/vl/*.c)
dll_hdr := $(wildcard $(VLDIR)/vl/*.h) $(wildcard $(VLDIR)/vl/*.tc)
dll_obj := $(addprefix $(BINDIR)/objs/, $(notdir $(dll_src:.c=.o)))
dll_dep := $(dll_obj:.o=.d)

Expand All @@ -378,12 +382,12 @@ dll: $(dll_tgt)
.PRECIOUS: $(BINDIR)/objs/%.d

$(BINDIR)/objs/%.o : vl/%.c $(bin-dir)
$(call C,CC) $(DLL_CFLAGS) -c $< -o $@
$(call C,CC) $(DLL_CFLAGS) -c "$(<)" -o "$(@)"

$(BINDIR)/objs/%.d : vl/%.c $(bin-dir)
$(call C,CC) $(DLL_CFLAGS) \
-M -MT '$(BINDIR)/objs/$*.o $(BINDIR)/objs/$*.d' \
$< -MF $@
"$(<)" -MF "$(@)"

$(BINDIR)/lib$(DLL_NAME).dylib : $(dll_obj)
$(call C,LIBTOOL) -dynamic \
Expand All @@ -403,7 +407,7 @@ $(BINDIR)/lib$(DLL_NAME).so : $(dll_obj)
# dependency in order avoiding rebuilding all the executables if only
# a part of the library is changed.

bin_src := $(wildcard src/*.c)
bin_src := $(wildcard $(VLDIR)/src/*.c)
bin_tgt := $(notdir $(bin_src))
bin_tgt := $(addprefix $(BINDIR)/, $(bin_tgt:.c=))
bin_dep := $(addsuffix .d, $(bin_tgt))
Expand Down Expand Up @@ -432,13 +436,13 @@ $(BINDIR)/%.d : src/%.c $(bin-dir)
# MEX file. On Mac OS X this is implicitly obtained since libvl.dylib
# has install_name relative to @loader_path/.

mex_src := $(shell find toolbox -name "*.c")
mex_src := $(shell find $(VLDIR)/toolbox -name "*.c")
mex_tgt := $(addprefix $(MEX_BINDIR)/, \
$(notdir $(mex_src:.c=.$(MEX_SUFFIX)) ) )
mex_dep := $(mex_tgt:.$(MEX_SUFFIX)=.d)

vpath %.c $(shell find toolbox -type d)
vpath vl_%.m $(shell find toolbox -type d)
vpath %.c $(shell find $(VLDIR)/toolbox -type d)
vpath vl_%.m $(shell find $(VLDIR)/toolbox -type d)

.PHONY: all-mex
all-mex : $(mex_tgt) noprefix
Expand All @@ -447,7 +451,7 @@ $(MEX_BINDIR)/%.d : %.c $(mex-dir)
$(call C,CC) $(MEX_CFLAGS) \
-I"$(MATLABPATH)/extern/include" -M -MT \
'$(MEX_BINDIR)/$*.$(MEX_SUFFIX) $(MEX_BINDIR)/$*.d' \
$< -MF $@
"$(<)" -MF "$(@)"

$(MEX_BINDIR)/%.$(MEX_SUFFIX) : %.c $(mex-dir) #$(MEX_BINDIR)/lib$(DLL_NAME).$(DLL_SUFFIX)
@make -s $(dll_tgt)
Expand All @@ -456,15 +460,15 @@ $(MEX_BINDIR)/%.$(MEX_SUFFIX) : %.c $(mex-dir) #$(MEX_BINDIR)/lib$(DLL_NAME).$(D
$(call C,MEX) CFLAGS='$$CFLAGS $(MEX_CFLAGS)' \
LDFLAGS='$$LDFLAGS $(MEX_LDFLAGS)' \
$(MEX_FLAGS) \
$< -outdir $(dir $(@))
"$(<)" -outdir "$(dir $(@))"

# --------------------------------------------------------------------
# Prefix-less M and MEX files
# --------------------------------------------------------------------
# Populate the directory toolbox/noprefix with links to the MEX / M
# files without the vl_ prefix.

m_src := $(shell find toolbox -name "vl_*.m")
m_src := $(shell find $(VLDIR)/toolbox -name "vl_*.m")
m_lnk := $(addprefix toolbox/noprefix/, \
$(filter-out setup.m, \
$(filter-out help.m, \
Expand Down
4 changes: 2 additions & 2 deletions vlfeat.xcodeproj/project.pbxproj
Expand Up @@ -17,7 +17,6 @@
2D13F028100A6E8800C072E8 /* vl_alldist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vl_alldist.c; path = toolbox/misc/vl_alldist.c; sourceTree = "<group>"; };
2D13F02C100A718600C072E8 /* vl_simdctrl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = vl_simdctrl.c; path = toolbox/misc/vl_simdctrl.c; sourceTree = "<group>"; };
2D13F039100A733D00C072E8 /* vl_simdctrl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = vl_simdctrl.m; path = toolbox/misc/vl_simdctrl.m; sourceTree = "<group>"; };
2D36D6310DE337C700F6EFD5 /* mexversion.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mexversion.c; path = /Applications/MATLAB7/extern/src/mexversion.c; sourceTree = "<absolute>"; };
2D624AD20FF927E300DB3122 /* heap-t.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "heap-t.h"; sourceTree = "<group>"; };
2D624AD60FF9306700DB3122 /* test_heap-t.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "test_heap-t.c"; sourceTree = "<group>"; };
2D6DD0F4100F5E5E006AE152 /* test_mathop_abs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = test_mathop_abs.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,7 +141,6 @@
children = (
2DD66ECE0FEFB0F3005A3664 /* matrix.h */,
2DD66ECC0FEFB076005A3664 /* mex.h */,
2D36D6310DE337C700F6EFD5 /* mexversion.c */,
2D732DE30CF8C2CB0099B03C /* Makefile */,
2DE5B34E0FDC28A5008CEB1D /* Makefile.doc */,
2DC75D0B0E4B4FE7005223E7 /* Makefile.mak */,
Expand Down Expand Up @@ -392,6 +390,7 @@
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
VERB = yes;
VLDIR = "$(PROJECT_DIR)";
};
name = Debug;
};
Expand All @@ -415,6 +414,7 @@
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
VERB = yes;
VLDIR = "$(PROJECT_DIR)";
};
name = Release;
};
Expand Down

0 comments on commit 5597066

Please sign in to comment.