Skip to content

Commit

Permalink
Merge pull request JuliaLang#604 from carlobaldassi/linprog_extras
Browse files Browse the repository at this point in the history
glpk wrapper and high-level functions for linear programming/mixed integer programming
  • Loading branch information
StefanKarpinski committed Mar 18, 2012
2 parents 107a5b5 + 5ed8393 commit ea7002f
Show file tree
Hide file tree
Showing 14 changed files with 2,597 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ USE_SYSTEM_FFTW=0
USE_SYSTEM_GMP=0
USE_SYSTEM_ARPACK=0
USE_SYSTEM_SUITESPARSE=0
USE_SYSTEM_GLPK=0

ifeq ($(USE_DEBIAN), 1)
USE_SYSTEM_LLVM=1
Expand All @@ -73,6 +74,7 @@ USE_SYSTEM_FFTW=1
USE_SYSTEM_GMP=1
USE_SYSTEM_ARPACK=1
USE_SYSTEM_SUITESPARSE=1
USE_SYSTEM_GLPK=1
endif

#ifeq ($(OS), Darwin)
Expand Down
2 changes: 2 additions & 0 deletions extras/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/glpk-*
/glpk_h.jl
94 changes: 94 additions & 0 deletions extras/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
JULIAHOME = $(abspath ..)
include $(JULIAHOME)/Make.inc

USE_SYSTEM_GLPK=0

OS = $(shell uname)
ARCH = $(shell uname -m)
LIBS = glpk-wrapper

ifeq ($(USE_SYSTEM_GLPK), 0)
LIBS += glpk
endif

WGET = wget
WGET_DASH_O = wget -O
ifeq ($(OS), Darwin)
WGET = curl -kLO
WGET_DASH_O = curl -kLo
endif

ifeq ($(OS), FreeBSD)
WGET = curl -LO
WGET_DASH_O = curl -Lo
endif

GLPK_VER = 4.43
GLPK_CONST = 0x[0-9a-fA-F]+|[-+]?\s*[0-9]+
GLPK_PREFIX = /usr/

default: install
compile: $(addprefix compile-, $(LIBS)) glpk_h.jl
install: $(addprefix install-, $(LIBS))
cleanall: $(addprefix clean-, $(LIBS)) clean-rest
distclean: $(addprefix distclean-, $(LIBS))

## GLPK ##

ifeq ($(USE_SYSTEM_GLPK), 1)
GLPK_INC = -I /usr/include/
GLPK_LIB =
else
GLPK_INC = -I glpk-$(GLPK_VER)/
GLPK_LIB =
endif

GLPK_OBJ_TARGET = $(EXTROOTLIB)/libglpk.$(SHLIB_EXT)

compile-glpk: install-glpk
install-glpk: $(GLPK_OBJ_TARGET) $(EXTROOTLIB)/libglpk_wrapper.$(SHLIB_EXT) glpk_h.jl

glpk-$(GLPK_VER).tar.gz:
$(WGET) ftp://ftp.gnu.org/gnu/glpk/$@

glpk-$(GLPK_VER)/configure: glpk-$(GLPK_VER).tar.gz
tar zxf $<
touch $@
glpk-$(GLPK_VER)/config.status: glpk-$(GLPK_VER)/configure
cd glpk-$(GLPK_VER) && \
./configure --prefix=$(abspath $(EXTROOT))
$(GLPK_OBJ_TARGET): glpk-$(GLPK_VER)/config.status
$(MAKE) $(jPARALLEL_BUILD_JOBS) -C glpk-$(GLPK_VER) install
touch $@

glpk_h.jl:
$(QUIET_PERL) cpp -dM $(GLPK_PREFIX)/include/glpk.h | perl -nle '/^\s*#define\s+(GLP\w*)\s*\(?($(GLPK_CONST))\)?\s*$$/ and print "const $$1 = int32($$2)"' | sort > $@

clean-glpk:
$(MAKE) $(jPARALLEL_BUILD_JOBS) -C glpk-$(GLPK_VER) uninstall || true
$(MAKE) $(jPARALLEL_BUILD_JOBS) -C glpk-$(GLPK_VER) clean
rm -f glpk_h.jl
distclean-glpk: clean-glpk
rm -rf glpk-$(GLPK_VER).tar.bz2 glpk-$(GLPK_VER)


## GLPK Wrapper

GLPKW_INC = -I glpk-$(GLPK_VER)/
GLPKW_LIB = -L$(EXTROOTLIB)/ -lglpk

$(EXTROOTLIB)/libglpk_wrapper.$(SHLIB_EXT): glpk_wrapper.c $(GLPK_OBJ_TARGET)
$(CC) -O2 -shared -fPIC $(GLPKW_INC) glpk_wrapper.c $(GLPKW_LIB) -o $(EXTROOTLIB)/libglpk_wrapper.$(SHLIB_EXT) -Wl,-rpath,$(EXTROOTLIB)
touch $@
install-glpk-wrapper: $(EXTROOTLIB)/libglpk_wrapper.$(SHLIB_EXT) glpk_wrapper.c

clean-glpk-wrapper:
rm -f $(GLPK_OBJ_TARGET) $(EXTROOTLIB)/libglpk_wrapper.$(SHLIB_EXT)
distclean-glpk-wrapper: clean-glpk-wrapper


## phony targets ##

.PHONY: \
default compile install cleanall distclean \
compile-* install-* clean-* distclean-*
Loading

0 comments on commit ea7002f

Please sign in to comment.