Skip to content

Commit

Permalink
Makefile fix for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
souvikdas95 committed Aug 21, 2017
1 parent 429218a commit 821a2e7
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 169 deletions.
236 changes: 132 additions & 104 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,104 +1,132 @@
# Makefile for ECOS

# Disable implicit rules such as 'make ecos' when 'ecos.o' exists
.SUFFIXES:

# Configuration of make process in ecos.mk
include ecos.mk
CFLAGS += -Iinclude -Iexternal/ldl/include -Iexternal/amd/include -Iexternal/SuiteSparse_config
TEST_INCLUDES = -Itest -Itest/generated

# Compile all C code, including the C-callable routine
.PHONY: all
all: libecos.a libecos_bb.a runecos runecosexp

# build Tim Davis' sparse LDL package
$(LDL):
( cd external/ldl ; $(MAKE) )
$(AR) -x external/ldl/libldl.a

# build Tim Davis' AMD package
$(AMD):
( cd external/amd ; $(MAKE) )
$(AR) -x external/amd/libamd.a

# build ECOS
ECOS_OBJS = ecos.o kkt.o cone.o spla.o ctrlc.o timer.o preproc.o splamm.o equil.o expcone.o wright_omega.o
libecos.a: $(ECOS_OBJS) $(LDL) $(AMD)
$(ARCHIVE) $@ $^
- $(RANLIB) $@

# build ECOS branch-and-bound
ECOS_BB_OBJS = $(ECOS_OBJS) ecos_bb_preproc.o ecos_bb.o
libecos_bb.a: $(ECOS_BB_OBJS) $(LDL) $(AMD)
$(ARCHIVE) $@ $^
- $(RANLIB) $@

%.o : src/%.c
$(CC) $(CFLAGS) -c $< -o $@

%.o : ecos_bb/%.c
$(CC) $(CFLAGS) -c $< -o $@

ecos_bb.o : include/ecos_bb.h
ecos_bb_preproc.o : include/ecos_bb.h
ecos.o : include/ecos.h include/glblopts.h include/cone.h
kkt.o : include/kkt.h include/glblopts.h include/cone.h include/ecos.h
cone.o : include/cone.h include/glblopts.h include/ecos.h
preproc.o : include/glblopts.h include/cone.h include/ecos.h
spla.o : include/spla.h include/glblopts.h include/cone.h include/ecos.h
splamm.o : include/splamm.h include/glblopts.h include/cone.h include/ecos.h
ctrlc.o : include/ctrlc.h include/glblopts.h include/cone.h include/ecos.h
timer.o : include/timer.h include/glblopts.h include/cone.h include/ecos.h
equil.o : include/equil.h include/glblopts.h include/cone.h include/ecos.h
expcone.o : include/expcone.h
wright_omega.o : include/wright_omega.h


# ECOS demo
.PHONY: demo
demo: runecos
runecos: src/runecos.c libecos.a
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
echo ECOS successfully built. Type ./runecos to run demo problem.

runecosexp: src/runecos_exp.c libecos.a
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
echo ECOS-Exp successfully built. Type ./runecosexp to run demo problem.

# Shared library
.PHONY: shared
shared: $(SHAREDNAME)
$(SHAREDNAME): $(LDL) $(AMD) $(ECOS_OBJS)
$(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS)

# ECOS tester
TEST_OBJS = qcml_utils.o norm.o sq_norm.o sum_sq.o quad_over_lin.o inv_pos.o
.PHONY: test
test: ecostester ecos_bb_test
ecostester: test/ecostester.c $(TEST_OBJS) libecos.a
$(CC) $(CFLAGS) $(TEST_INCLUDES) -o $@ $^ $(LDFLAGS)

ecos_bb_test: test/bb_test.c libecos_bb.a
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

%.o: test/generated/%.c test/generated/%.h
$(CC) $(CFLAGS) $(TEST_INCLUDES) -c $< -o $@

%.o: test/generated/*/%.c test/generated/*/%.h
$(CC) $(CFLAGS) $(TEST_INCLUDES) -c $< -o $@


# remove object files, but keep the compiled programs and library archives
.PHONY: clean
clean:
( cd external/ldl ; $(MAKE) clean )
( cd external/amd ; $(MAKE) clean )
- $(RM) $(CLEAN)

# clean, and then remove compiled programs and library archives
.PHONY: purge
purge: clean
( cd external/ldl ; $(MAKE) purge )
( cd external/amd ; $(MAKE) purge )
- $(RM) libecos.a libecos_bb.a runecos runecosexp
# Makefile for ECOS

# Disable implicit rules such as 'make ecos' when 'ecos.o' exists
.SUFFIXES:

# Configuration of make process in ecos.mk
include ecos.mk
CFLAGS += -Iinclude -Iexternal/ldl/include -Iexternal/amd/include -Iexternal/SuiteSparse_config
TEST_INCLUDES = -Itest -Itest/generated

# Compile all C code, including the C-callable routine
.PHONY: all
all: libecos.a libecos_bb.a runecos runecosexp

# build Tim Davis' SuiteSparse_config package
$(SuiteSparse_config):
( cd external/SuiteSparse_config ; $(MAKE) static )
$(AR) -x external/SuiteSparse_config/libsuitesparseconfig.a

# build Tim Davis' sparse LDL package
$(LDL):
( cd external/ldl ; $(MAKE) static )
$(AR) -x external/ldl/lib/libldl.a

# build Tim Davis' AMD package
$(AMD):
( cd external/amd ; $(MAKE) static )
$(AR) -x external/amd/lib/libamd.a

# build ECOS
ECOS_OBJS = ecos.o kkt.o cone.o spla.o ctrlc.o timer.o preproc.o splamm.o equil.o expcone.o wright_omega.o
libecos.a: $(ECOS_OBJS) $(SuiteSparse_config) $(LDL) $(AMD)
$(ARCHIVE) $@ $^
- $(RANLIB) $@

# build ECOS branch-and-bound
ECOS_BB_OBJS = $(ECOS_OBJS) ecos_bb_preproc.o ecos_bb.o
libecos_bb.a: $(ECOS_BB_OBJS) $(SuiteSparse_config) $(LDL) $(AMD)
$(ARCHIVE) $@ $^
- $(RANLIB) $@

%.o : src/%.c
$(CC) $(CFLAGS) -c $< -o $@

%.o : ecos_bb/%.c
$(CC) $(CFLAGS) -c $< -o $@

ecos_bb.o : include/ecos_bb.h
ecos_bb_preproc.o : include/ecos_bb.h
ecos.o : include/ecos.h include/glblopts.h include/cone.h
kkt.o : include/kkt.h include/glblopts.h include/cone.h include/ecos.h
cone.o : include/cone.h include/glblopts.h include/ecos.h
preproc.o : include/glblopts.h include/cone.h include/ecos.h
spla.o : include/spla.h include/glblopts.h include/cone.h include/ecos.h
splamm.o : include/splamm.h include/glblopts.h include/cone.h include/ecos.h
ctrlc.o : include/ctrlc.h include/glblopts.h include/cone.h include/ecos.h
timer.o : include/timer.h include/glblopts.h include/cone.h include/ecos.h
equil.o : include/equil.h include/glblopts.h include/cone.h include/ecos.h
expcone.o : include/expcone.h
wright_omega.o : include/wright_omega.h


# ECOS demo
.PHONY: demo
demo: runecos
runecos: src/runecos.c libecos.a
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
echo ECOS successfully built. Type ./runecos to run demo problem.

runecosexp: src/runecos_exp.c libecos.a
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
echo ECOS-Exp successfully built. Type ./runecosexp to run demo problem.

# Shared library
.PHONY: shared
shared: $(SHARED_ECOS) $(SHARED_ECOS_BB)
$(SHARED_ECOS): $(SuiteSparse_config) $(LDL) $(AMD) $(ECOS_OBJS)
$(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS)
$(SHARED_ECOS_BB): $(SuiteSparse_config) $(LDL) $(AMD) $(ECOS_BB_OBJS)
$(CC) $(CFLAGS) -shared -o $@ $^ $(LDFLAGS)

# ECOS tester
TEST_OBJS = qcml_utils.o norm.o sq_norm.o sum_sq.o quad_over_lin.o inv_pos.o
.PHONY: test
test: ecostester ecos_bb_test
ecostester: test/ecostester.c $(TEST_OBJS) libecos.a
$(CC) $(CFLAGS) $(TEST_INCLUDES) -o $@ $^ $(LDFLAGS)

ecos_bb_test: test/bb_test.c libecos_bb.a
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

%.o: test/generated/%.c test/generated/%.h
$(CC) $(CFLAGS) $(TEST_INCLUDES) -c $< -o $@

%.o: test/generated/*/%.c test/generated/*/%.h
$(CC) $(CFLAGS) $(TEST_INCLUDES) -c $< -o $@


# remove object files, but keep the compiled programs and library archives
.PHONY: clean
clean:
( cd external/SuiteSparse_config ; $(MAKE) clean )
( cd external/ldl ; $(MAKE) clean )
( cd external/amd ; $(MAKE) clean )
- $(RM) $(CLEAN)

# clean, and then remove compiled programs and library archives
.PHONY: purge
purge: clean
( cd external/SuiteSparse_config ; $(MAKE) purge )
( cd external/ldl ; $(MAKE) purge )
( cd external/amd ; $(MAKE) purge )
- $(RM) runecos runecosexp \
libecos*.a libecos*.so libecos*.dylib libecos*.dll \
ecos_bb_test ecos_bb_test.exe \
ecostester ecostester.exe
















133 changes: 68 additions & 65 deletions ecos.mk
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,65 +1,68 @@
# Makefile configuration for ECOS

# Whether to use Long or Int for index type
# comment it out to use ints
USE_LONG = 1

## Intel C Compiler
#CC = icc
#CFLAGS = -O3 -m64 -Wall -strict-ansi -DLDL_LONG -DDLONG
#LIBS = -lm

## GNU C Compiler
#CC = gcc

CFLAGS += -O2 -Wall -DCTRLC=1 -Wextra -fPIC #-ansi -Werror #-ipo
ifdef USE_LONG
CFLAGS += -DLDL_LONG -DDLONG
SuiteSparse_config = SuiteSparse_config.o
LDL = ldll.o
AMD = amd_l*.o amd_global.o
else
CFLAGS +=
SuiteSparse_config = SuiteSparse_config.o
LDL = ldl.o
AMD = amd_i*.o amd_global.o
endif

UNAME := $(shell uname)

ifeq (CYGWIN, $(findstring CYGWIN, $(UNAME)))
ISWINDOWS := 1
else ifeq (MINGW, $(findstring MINGW, $(UNAME)))
ISWINDOWS := 1
else ifeq (MSYS, $(findstring MSYS, $(UNAME)))
ISWINDOWS := 1
else
ISWINDOWS := 0
endif

ifeq ($(UNAME), Darwin)
# we're on apple, no need to link rt library
LDFLAGS = -lm
# shared library has extension .dylib
SHAREDNAME = libecos.dylib
else ifeq ($(ISWINDOWS), 1)
# we're on windows (cygwin or msys)
LDFLAGS = -lm
# shared library has extension .dll
SHAREDNAME = libecos.dll
else
# we're on a linux system, use accurate timer provided by clock_gettime()
LDFLAGS = -lm -lrt
# shared library has extension .so
SHAREDNAME = libecos.so
endif


## AR and RANLIB FOR GENERATING LIBRARIES
AR = ar
ARFLAGS = rcs
ARCHIVE = $(AR) $(ARFLAGS)
RANLIB = ranlib

## WHICH FILES TO CLEAN UP
CLEAN = *.o *.obj *.ln *.bb *.bbg *.da *.tcov *.gcov gmon.out *.bak *.d *.gcda *.gcno libecos*.a libecos*.so libecos*.dylib libecos*.dll ecos_bb_test ecostester ecostester.exe runecosexp
# Makefile configuration for ECOS

# Whether to use Long or Int for index type
# comment it out to use ints
USE_LONG = 1

## Intel C Compiler
#CC = icc
#CFLAGS = -O3 -m64 -Wall -strict-ansi -DLDL_LONG -DDLONG
#LIBS = -lm

## GNU C Compiler
#CC = gcc

CFLAGS += -O2 -Wall -DCTRLC=1 -Wextra -fPIC #-ansi -Werror #-ipo
ifdef USE_LONG
CFLAGS += -DLDL_LONG -DDLONG
SuiteSparse_config = SuiteSparse_config.o
LDL = ldll.o
AMD = amd_l*.o amd_global.o
else
CFLAGS +=
SuiteSparse_config = SuiteSparse_config.o
LDL = ldl.o
AMD = amd_i*.o amd_global.o
endif

UNAME := $(shell uname)

ifeq (CYGWIN, $(findstring CYGWIN, $(UNAME)))
ISWINDOWS := 1
else ifeq (MINGW, $(findstring MINGW, $(UNAME)))
ISWINDOWS := 1
else ifeq (MSYS, $(findstring MSYS, $(UNAME)))
ISWINDOWS := 1
else
ISWINDOWS := 0
endif

ifeq ($(UNAME), Darwin)
# we're on apple, no need to link rt library
LDFLAGS = -lm
# shared library has extension .dylib
SHARED_ECOS = libecos.dylib
SHARED_ECOS_BB = libecos_bb.dylib
else ifeq ($(ISWINDOWS), 1)
# we're on windows (cygwin or msys)
LDFLAGS = -lm
# shared library has extension .dll
SHARED_ECOS = libecos.dll
SHARED_ECOS_BB = libecos_bb.dll
else
# we're on a linux system, use accurate timer provided by clock_gettime()
LDFLAGS = -lm -lrt
# shared library has extension .so
SHARED_ECOS = libecos.so
SHARED_ECOS_BB = libecos_bb.so
endif


## AR and RANLIB FOR GENERATING LIBRARIES
AR = ar
ARFLAGS = rcs
ARCHIVE = $(AR) $(ARFLAGS)
RANLIB = ranlib

## WHICH FILES TO CLEAN UP
CLEAN = *.o *.obj *.ln *.bb *.bbg *.da *.tcov *.gcov gmon.out *.bak *.d *.gcda *.gcno

0 comments on commit 821a2e7

Please sign in to comment.