Skip to content

Commit

Permalink
make: refactor archive generation (#3200)
Browse files Browse the repository at this point in the history
* Add archive_{cpp,dotnet,java,python,data} targets
* Create a Makefile for each archive to ease build
* Add test_archive_* targets
* Rework tools/README.md
  • Loading branch information
Mizux committed Apr 5, 2022
1 parent 839f4f6 commit 8b9c055
Show file tree
Hide file tree
Showing 16 changed files with 1,102 additions and 562 deletions.
24 changes: 16 additions & 8 deletions Makefile
Expand Up @@ -79,9 +79,9 @@ BUILT_LANGUAGES +=, .Net (6.0)
endif

include $(OR_ROOT)makefiles/Makefile.cpp.mk
include $(OR_ROOT)makefiles/Makefile.python.mk
include $(OR_ROOT)makefiles/Makefile.java.mk
include $(OR_ROOT)makefiles/Makefile.dotnet.mk
include $(OR_ROOT)makefiles/Makefile.java.mk
include $(OR_ROOT)makefiles/Makefile.python.mk
include $(OR_ROOT)makefiles/Makefile.archive.mk
ifneq ($(PLATFORM),WIN64)
include $(OR_ROOT)makefiles/Makefile.doc.mk
Expand All @@ -107,7 +107,7 @@ else
endif

.PHONY: help_all
help_all: help_usage help_cc help_python help_java help_dotnet help_archive help_doc
help_all: help_usage help_cc help_dotnet help_java help_python help_archive help_doc

# Commands to build/clean all languages.
.PHONY: compile
Expand All @@ -116,24 +116,32 @@ compile:

.PHONY: build_all
build_all:
$(MAKE) third_party BUILD_PYTHON=ON BUILD_JAVA=ON BUILD_DOTNET=ON
$(MAKE) third_party BUILD_DOTNET=ON BUILD_JAVA=ON BUILD_PYTHON=ON
cmake --build $(BUILD_DIR) --target install --config $(BUILD_TYPE) -j $(JOBS) -v
@echo Or-tools has been built for "$(BUILT_LANGUAGES)"

.PHONY: check_all
check_all: check_cpp check_python check_java check_dotnet
check_all: check_cpp check_dotnet check_java check_python
@echo Or-tools has been built and checked for "$(BUILT_LANGUAGES)"

.PHONY: test_all
test_all: test_cpp test_python test_java test_dotnet
test_all: test_cpp test_dotnet test_java test_python
@echo Or-tools have been built and tested for "$(BUILT_LANGUAGES)"

.PHONY: archive_all
archive_all: archive_cpp archive_dotnet archive_java archive_python archive_data
@echo Or-tools has been built and archived for "$(BUILT_LANGUAGES)"

.PHONY: test_archive_all
test_archive_all: test_archive_cpp test_archive_dotnet test_archive_java test_archive_python
@echo Or-tools has been built and archived for "$(BUILT_LANGUAGES)"

.PHONY: clean_all
clean_all: clean_cpp clean_python clean_java clean_dotnet clean_archive
clean_all: clean_cpp clean_dotnet clean_java clean_python clean_archive
@echo Or-Tools has been cleaned for "$(BUILT_LANGUAGES)"

.PHONY: detect_all
detect_all: detect_port detect_cpp detect_python detect_java detect_dotnet detect_archive
detect_all: detect_port detect_cpp detect_dotnet detect_java detect_python detect_archive
@echo SOURCE = $(SOURCE)
@echo SOURCE_PATH = $(SOURCE_PATH)
@echo SOURCE_NAME = $(SOURCE_NAME)
Expand Down
319 changes: 37 additions & 282 deletions makefiles/Makefile.archive.mk

Large diffs are not rendered by default.

179 changes: 40 additions & 139 deletions makefiles/Makefile.cpp.mk
Expand Up @@ -51,7 +51,7 @@ third_party:

JOBS ?= 4

TEMP_CPP_DIR=temp_cpp
TEMP_CPP_DIR := temp_cpp

# Main target
.PHONY: cpp # Build C++ OR-Tools library.
Expand Down Expand Up @@ -199,7 +199,7 @@ rcpp_%: \
cd $(TEMP_CPP_DIR)$S$1$S$$* &&\
cmake -S. -Bbuild \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_PREFIX_PATH=$(INSTALL_DIR) \
-DCMAKE_PREFIX_PATH=$(OR_ROOT_FULL)/$(INSTALL_DIR) \
-DCMAKE_INSTALL_PREFIX=install \
$(CMAKE_ARGS) \
-G $(GENERATOR)
Expand All @@ -212,7 +212,7 @@ else
endif
endef

CPP_SAMPLES := algorithms graph glop constraint_solver linear_solver model_builder routing sat
CPP_SAMPLES := algorithms graph glop constraint_solver linear_solver math_opt model_builder routing sat
$(foreach sample,$(CPP_SAMPLES),$(eval $(call cpp-sample-target,$(sample))))

# Examples
Expand Down Expand Up @@ -247,7 +247,7 @@ rcpp_%: \
cd $(TEMP_CPP_DIR)$S$1$S$$* &&\
cmake -S. -Bbuild \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_PREFIX_PATH=$(INSTALL_DIR) \
-DCMAKE_PREFIX_PATH=$(OR_ROOT_FULL)/$(INSTALL_DIR) \
-DCMAKE_INSTALL_PREFIX=install \
$(CMAKE_ARGS) \
-G $(GENERATOR)
Expand Down Expand Up @@ -298,7 +298,7 @@ rcpp_%: \
cd $(TEMP_CPP_DIR)$Stests$S$* && \
cmake -S. -Bbuild \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_PREFIX_PATH=$(INSTALL_DIR) \
-DCMAKE_PREFIX_PATH=$(OR_ROOT_FULL)/$(INSTALL_DIR) \
-DCMAKE_INSTALL_PREFIX=install \
$(CMAKE_ARGS) \
-G $(GENERATOR)
Expand Down Expand Up @@ -344,18 +344,18 @@ endif
## Test targets ##
####################

.PHONY: test_cc_algorithms_samples # Build and Run all C++ Algorithms Samples (located in ortools/algorithms/samples)
test_cc_algorithms_samples: \
.PHONY: test_cpp_algorithms_samples # Build and Run all C++ Algorithms Samples (located in ortools/algorithms/samples)
test_cpp_algorithms_samples: \
rcpp_knapsack \
rcpp_simple_knapsack_program

.PHONY: test_cc_graph_samples # Build and Run all C++ Graph Samples (located in ortools/graph/samples)
test_cc_graph_samples: \
.PHONY: test_cpp_graph_samples # Build and Run all C++ Graph Samples (located in ortools/graph/samples)
test_cpp_graph_samples: \
rcpp_simple_max_flow_program \
rcpp_simple_min_cost_flow_program

.PHONY: test_cc_constraint_solver_samples # Build and Run all C++ CP Samples (located in ortools/constraint_solver/samples)
test_cc_constraint_solver_samples: \
.PHONY: test_cpp_constraint_solver_samples # Build and Run all C++ CP Samples (located in ortools/constraint_solver/samples)
test_cpp_constraint_solver_samples: \
rcpp_minimal_jobshop_cp \
rcpp_nurses_cp \
rcpp_rabbits_and_pheasants_cp \
Expand All @@ -380,8 +380,8 @@ test_cc_constraint_solver_samples: \
rcpp_vrp_time_windows \
rcpp_vrp_with_time_limit

.PHONY: test_cc_linear_solver_samples # Build and Run all C++ LP Samples (located in ortools/linear_solver/samples)
test_cc_linear_solver_samples: \
.PHONY: test_cpp_linear_solver_samples # Build and Run all C++ LP Samples (located in ortools/linear_solver/samples)
test_cpp_linear_solver_samples: \
rcpp_assignment_mip \
rcpp_basic_example \
rcpp_bin_packing_mip \
Expand All @@ -397,8 +397,8 @@ test_cc_linear_solver_samples: \
test_cc_model_builder_samples: \


.PHONY: test_cc_sat_samples # Build and Run all C++ Sat Samples (located in ortools/sat/samples)
test_cc_sat_samples: \
.PHONY: test_cpp_sat_samples # Build and Run all C++ Sat Samples (located in ortools/sat/samples)
test_cpp_sat_samples: \
rcpp_assignment_sat \
rcpp_assumptions_sample_sat \
rcpp_binpacking_problem_sat \
Expand All @@ -423,12 +423,12 @@ test_cc_sat_samples: \

.PHONY: check_cpp_pimpl
check_cpp_pimpl: \
test_cc_algorithms_samples \
test_cc_constraint_solver_samples \
test_cc_graph_samples \
test_cc_linear_solver_samples \
test_cc_model_builder_samples \
test_cc_sat_samples \
test_cpp_algorithms_samples \
test_cpp_constraint_solver_samples \
test_cpp_graph_samples \
test_cpp_linear_solver_samples \
test_cpp_model_builder_samples \
test_cpp_sat_samples \
\
rcpp_linear_programming \
rcpp_constraint_programming_cp \
Expand Down Expand Up @@ -530,8 +530,8 @@ endef
$(foreach sample,$(CPP_SAMPLES),$(eval $(call cpp-sample-archive,$(sample))))

define cpp-example-archive =
$(TEMP_ARCHIVE_DIR)/$(INSTALL_DIR)/examples/%/CMakeLists.txt: \
$(TEMP_CPP_DIR)/$1/%/CMakeLists.xml \
$(INSTALL_CPP_NAME)/examples/%/CMakeLists.txt: \
$(TEMP_CPP_DIR)/$1/%/CMakeLists.txt \
$(SRC_DIR)/examples/$1/%.cc \
| $(INSTALL_CPP_NAME)/examples
-$(MKDIR_P) $(INSTALL_CPP_NAME)$Sexamples$S$$*
Expand All @@ -553,131 +553,29 @@ $(INSTALL_CPP_NAME)$(ARCHIVE_EXT): \
$(EXAMPLE_CPP_FILES)
$(MAKE) third_party BUILD_PYTHON=OFF BUILD_JAVA=OFF BUILD_DOTNET=OFF INSTALL_DIR=$(OR_ROOT)$(INSTALL_CPP_NAME)
cmake --build $(BUILD_DIR) --target install --config $(BUILD_TYPE) -j $(JOBS) -v
$(COPY) tools$SREADME.cpp.md $(INSTALL_CPP_NAME)$SREADME.md
$(COPY) tools$SMakefile.cpp $(INSTALL_CPP_NAME)$SMakefile
$(SED) -i -e 's/@PROJECT_VERSION@/$(OR_TOOLS_VERSION)/' $(INSTALL_CPP_NAME)$SMakefile
ifeq ($(PLATFORM),WIN64)
$(ZIP) -r $(INSTALL_CPP_NAME)$(ARCHIVE_EXT) $(INSTALL_CPP_NAME)
else
$(TAR) --no-same-owner -czvf $(INSTALL_CPP_NAME)$(ARCHIVE_EXT) $(INSTALL_CPP_NAME)
endif






#################
## Packaging ##
#################
TEMP_PACKAGE_CC_DIR = temp_package_cc

$(TEMP_PACKAGE_CC_DIR):
-$(MKDIR_P) $(TEMP_PACKAGE_CC_DIR)

$(TEMP_PACKAGE_CC_DIR)/$(INSTALL_DIR): | $(TEMP_PACKAGE_CC_DIR)
$(MKDIR) $(TEMP_PACKAGE_CC_DIR)$S$(INSTALL_DIR)

package_cc: cpp | $(TEMP_PACKAGE_CC_DIR)/$(INSTALL_DIR)
ifeq ($(PLATFORM),WIN64)
cd $(TEMP_PACKAGE_CC_DIR)\$(INSTALL_DIR) && \
..\..\$(TAR) -C ..\.. -c -v include | ..\..\$(TAR) xvm
cd $(TEMP_PACKAGE_CC_DIR)\$(INSTALL_DIR) && \
..\..\$(TAR) -C ..\.. -c -v lib | ..\..\$(TAR) xvm
cd $(TEMP_PACKAGE_CC_DIR)\$(INSTALL_DIR) && \
..\..\$(TAR) -C ..\.. -c -v share | ..\..\$(TAR) xvm
else
cd $(TEMP_PACKAGE_CC_DIR)/$(INSTALL_DIR) && \
tar -C ../.. -c -v include | tar xvm
cd $(TEMP_PACKAGE_CC_DIR)/$(INSTALL_DIR) && \
tar -C ../.. -c -v lib | tar xvm
cd $(TEMP_PACKAGE_CC_DIR)/$(INSTALL_DIR) && \
tar -C ../.. -c -v share | tar xvm
endif
ifeq ($(PLATFORM),WIN64)
cd $(TEMP_PACKAGE_CC_DIR) && ..$S$(ZIP) -r ..$S$(INSTALL_DIR)$(ARCHIVE_EXT) $(INSTALL_DIR)
else
$(TAR) -C $(TEMP_PACKAGE_CC_DIR) --no-same-owner -czvf $(INSTALL_DIR)$(ARCHIVE_EXT) $(INSTALL_DIR)
endif

###############
## INSTALL ##
###############
# ref: https://www.gnu.org/prep/standards/html_node/Directory-Variables.html#index-prefix
# ref: https://www.gnu.org/prep/standards/html_node/DESTDIR.html
.PHONY: install_dirs
install_dirs:
-$(MKDIR_P) "$(DESTDIR)$(prefix)"
-$(MKDIR) "$(DESTDIR)$(prefix)$Sinclude"
-$(MKDIR) "$(DESTDIR)$(prefix)$Slib"
-$(MKDIR) "$(DESTDIR)$(prefix)$Sbin"
-$(MKDIR) "$(DESTDIR)$(prefix)$Sshare"
-$(MKDIR_P) "$(DESTDIR)$(prefix)$Sshare$Sdocs$Sortools$Ssat"

# Install C++ OR-Tools to $(DESTDIR)$(prefix)
.PHONY: install_cc
install_cc: | install_dirs
$(COPY) LICENSE "$(DESTDIR)$(prefix)"
ifeq ($(PLATFORM),WIN64)
$(COPYREC) /E /Y include "$(DESTDIR)$(prefix)"
$(COPY) "$(INSTALL_DIR)$Slib$S$(LIB_PREFIX)ortools_full.$L" "$(DESTDIR)$(prefix)$Slib$S$(LIB_PREFIX)ortools.$L"
$(COPYREC) /E /Y share "$(DESTDIR)$(prefix)"
else
$(COPYREC) include "$(DESTDIR)$(prefix)$S"
$(COPY) $(INSTALL_DIR)$Slib*$S$(LIB_PREFIX)ortools*.$L* "$(DESTDIR)$(prefix)$Slib$S"
$(COPYREC) share "$(DESTDIR)$(prefix)$S"
endif
$(COPY) bin$Sprotoc* "$(DESTDIR)$(prefix)$Sbin"
$(COPY) ortools$Ssat$Sdocs$S*.md "$(DESTDIR)$(prefix)$Sshare$Sdocs$Sortools$Ssat"

#######################
## EXAMPLE ARCHIVE ##
#######################
TEMP_CC_DIR=temp_cpp

$(TEMP_CC_DIR)/ortools_examples: | $(TEMP_CC_DIR)
$(MKDIR) $(TEMP_CC_DIR)$Sortools_examples

$(TEMP_CC_DIR)/ortools_examples/examples: | $(TEMP_CC_DIR)/ortools_examples
$(MKDIR) $(TEMP_CC_DIR)$Sortools_examples$Sexamples

$(TEMP_CC_DIR)/ortools_examples/examples/cpp: | $(TEMP_CC_DIR)/ortools_examples/examples
$(MKDIR) $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp

$(TEMP_CC_DIR)/ortools_examples/examples/data: | $(TEMP_CC_DIR)/ortools_examples/examples
$(MKDIR) $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Sdata

.PHONY: cc_examples_archive # Build stand-alone C++ examples archive file for redistribution.
cc_examples_archive: | \
$(TEMP_CC_DIR)/ortools_examples/examples/cpp \
$(TEMP_CC_DIR)/ortools_examples/examples/data
$(COPY) $(CC_EX_PATH)$S*.h $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp
$(COPY) $(CC_EX_PATH)$S*.cc $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp
# $(COPY) $(CONTRIB_EX_PATH)$S*.cc $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp
$(COPY) ortools$Salgorithms$Ssamples$S*.cc $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp
$(COPY) ortools$Sgraph$Ssamples$S*.cc $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp
$(COPY) ortools$Slinear_solver$Ssamples$S*.cc $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp
$(COPY) ortools$Sconstraint_solver$Ssamples$S*.cc $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp
$(COPY) ortools$Ssat$Ssamples$S*.cc $(TEMP_CC_DIR)$Sortools_examples$Sexamples$Scpp
$(COPY) tools$SREADME.cpp.md $(TEMP_CC_DIR)$Sortools_examples$SREADME.md
$(COPY) LICENSE $(TEMP_CC_DIR)$Sortools_examples
# Test archive
TEMP_CPP_TEST_DIR := temp_cpp_test
.PHONY: test_archive_cpp # Test C++ OR-Tools archive is OK.
test_archive_cpp: $(INSTALL_CPP_NAME)$(ARCHIVE_EXT)
-$(DELREC) $(TEMP_CPP_TEST_DIR)
-$(MKDIR) $(TEMP_CPP_TEST_DIR)
ifeq ($(PLATFORM),WIN64)
cd $(TEMP_CC_DIR)\ortools_examples \
&& ..\..\$(TAR) -C ..\.. -c -v \
--exclude *svn* --exclude *roadef* --exclude *vector_packing* \
examples\data | ..\..\$(TAR) xvm
cd $(TEMP_CC_DIR) \
&& ..\$(ZIP) \
-r ..\or-tools_cpp_examples_v$(OR_TOOLS_VERSION).zip \
ortools_examples
$(UNZIP) $< -d $(TEMP_CPP_TEST_DIR)
else
cd $(TEMP_CC_DIR)/ortools_examples \
&& tar -C ../.. -c -v \
--exclude *svn* --exclude *roadef* --exclude *vector_packing* \
examples/data | tar xvm
cd $(TEMP_CC_DIR) \
&& tar -c -v -z --no-same-owner \
-f ../or-tools_cpp_examples$(PYPI_OS)_v$(OR_TOOLS_VERSION).tar.gz \
ortools_examples
$(TAR) -xvf $< -C $(TEMP_CPP_TEST_DIR)
endif
-$(DELREC) $(TEMP_CC_DIR)$Sortools_examples
cd $(TEMP_CPP_TEST_DIR)$S$(INSTALL_CPP_NAME) \
&& $(MAKE) MAKEFLAGS= \
&& $(MAKE) MAKEFLAGS= test

################
## Cleaning ##
Expand All @@ -688,6 +586,9 @@ clean_cpp:
-$(DELREC) $(INSTALL_DIR)
-$(DELREC) $(TEMP_CPP_DIR)
-$(DELREC) $(INSTALL_CPP_NAME)
-$(DELREC) or-tools_cpp_*
-$(DELREC) $(TEMP_CPP_TEST_DIR)
-$(DEL) *.deb

#############
## DEBUG ##
Expand Down

0 comments on commit 8b9c055

Please sign in to comment.