<commit_before>#
# Makefile for CuraEngine
#

BUILD_DIR = build
SRC_DIR = src
LIBS_DIR = libs

BUILD_TYPE = WEB

VERSION ?= DEV
CFLAGS += -c -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -std=c++11 -DVERSION=\"$(VERSION)\" -isystem libs

ifeq ($(BUILD_TYPE),DEBUG)
	CFLAGS+=-ggdb -Og -g
else ifeq ($(BUILD_TYPE),PROFILE)
	CFLAGS+= -pg
else ifeq ($(BUILD_TYPE),RELEASE)
	CFLAGS+= -O3 -fomit-frame-pointer
endif

SOURCES_RAW = bridge.cpp comb.cpp gcodeExport.cpp infill.cpp inset.cpp layerPart.cpp main.cpp optimizedModel.cpp pathOrderOptimizer.cpp polygonOptimizer.cpp raft.cpp settings.cpp skin.cpp skirt.cpp slicer.cpp support.cpp timeEstimate.cpp
SOURCES_RAW += modelFile/modelFile.cpp utils/gettime.cpp utils/logoutput.cpp utils/socket.cpp

ifeq ($(BUILD_TYPE), WEB)
	CXX = emcc
	SOURCES_RAW += ../$(LIBS_DIR)/clipper/clipper.cpp
	EXECUTABLE = $(BUILD_DIR)/CuraEngine.html
else
	CXX = g++
	LDFLAGS += -Lbuild/ -lclipper
	EXECUTABLE = $(BUILD_DIR)/CuraEngine
endif

SOURCES = $(addprefix $(SRC_DIR)/,$(SOURCES_RAW))

OBJECTS_RAW = $(SOURCES_RAW:.cpp=.o)
OBJECTS = $(addprefix $(BUILD_DIR)/,$(OBJECTS_RAW))

DIRS = $(sort $(dir $(OBJECTS)))

ifeq ($(OS),Windows_NT)
	#For windows make it large address aware, which allows the process to use more then 2GB of memory.
	EXECUTABLE := $(EXECUTABLE).exe
	CFLAGS += -march=pentium4 -flto
	LDFLAGS += -Wl,--large-address-aware -lm -lwsock32 -flto
	MKDIR_PREFIX = mkdir -p
else
	MKDIR_PREFIX = mkdir -p
	UNAME := $(shell uname)
	ifeq ($(UNAME), Linux)
		OPEN_HTML=firefox
		ifeq ($(BUILD_TYPE),DEBUG)
			LDFLAGS += --static
		else
			CFLAGS += -flto
			LDFLAGS += --static -flto
		endif
	endif
	ifeq ($(UNAME), Darwin)
		OPEN_HTML=open
		#For MacOS force to build
		CFLAGS += -force_cpusubtype_ALL -mmacosx-version-min=10.6 -arch x86_64 -arch i386
		LDFLAGS += -force_cpusubtype_ALL -mmacosx-version-min=10.6 -arch x86_64 -arch i386
	endif
endif

all: $(DIRS) $(SOURCES) $(EXECUTABLE)

$(BUILD_DIR)/libclipper.a: $(LIBS_DIR)/clipper/clipper.cpp
	$(CXX) $(CFLAGS) -o $(BUILD_DIR)/libclipper.a $(LIBS_DIR)/clipper/clipper.cpp

$(EXECUTABLE): $(OBJECTS) $(BUILD_DIR)/libclipper.a
	$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)

$(DIRS):
	-@$(MKDIR_PREFIX) $(DIRS)

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
	$(CXX) $(CFLAGS) $< -o $@

test: $(EXECUTABLE)
	python tests/runtest.py $(abspath $(EXECUTABLE))

## clean stuff
clean:
	rm -f $(EXECUTABLE) $(OBJECTS)

help:
	@cat Makefile |grep \#\#| grep \: |cut -d\# -f3<commit_msg>Access EMSCRIPTEN by environment variable, also assert that it exists.<commit_after>#
# Makefile for CuraEngine
#

BUILD_DIR = build
SRC_DIR = src
LIBS_DIR = libs

BUILD_TYPE = WEB

VERSION ?= DEV
CFLAGS += -c -Wall -Wextra -Wold-style-cast -Woverloaded-virtual -std=c++11 -DVERSION=\"$(VERSION)\" -isystem libs

ifeq ($(BUILD_TYPE),DEBUG)
	CFLAGS+=-ggdb -Og -g
else ifeq ($(BUILD_TYPE),PROFILE)
	CFLAGS+= -pg
else ifeq ($(BUILD_TYPE),RELEASE)
	CFLAGS+= -O3 -fomit-frame-pointer
endif

SOURCES_RAW = bridge.cpp comb.cpp gcodeExport.cpp infill.cpp inset.cpp layerPart.cpp main.cpp optimizedModel.cpp pathOrderOptimizer.cpp polygonOptimizer.cpp raft.cpp settings.cpp skin.cpp skirt.cpp slicer.cpp support.cpp timeEstimate.cpp
SOURCES_RAW += modelFile/modelFile.cpp utils/gettime.cpp utils/logoutput.cpp utils/socket.cpp

ifeq ($(BUILD_TYPE), WEB)
	CXX = $(EMSCRIPTEN)/emcc
	SOURCES_RAW += ../$(LIBS_DIR)/clipper/clipper.cpp
	EXECUTABLE = $(BUILD_DIR)/CuraEngine.html
else
	CXX = g++
	LDFLAGS += -Lbuild/ -lclipper
	EXECUTABLE = $(BUILD_DIR)/CuraEngine
endif

SOURCES = $(addprefix $(SRC_DIR)/,$(SOURCES_RAW))

OBJECTS_RAW = $(SOURCES_RAW:.cpp=.o)
OBJECTS = $(addprefix $(BUILD_DIR)/,$(OBJECTS_RAW))

DIRS = $(sort $(dir $(OBJECTS)))

ifeq ($(OS),Windows_NT)
	#For windows make it large address aware, which allows the process to use more then 2GB of memory.
	EXECUTABLE := $(EXECUTABLE).exe
	CFLAGS += -march=pentium4 -flto
	LDFLAGS += -Wl,--large-address-aware -lm -lwsock32 -flto
	MKDIR_PREFIX = mkdir -p
else
	MKDIR_PREFIX = mkdir -p
	UNAME := $(shell uname)
	ifeq ($(UNAME), Linux)
		OPEN_HTML=firefox
		ifeq ($(BUILD_TYPE),DEBUG)
			LDFLAGS += --static
		else
			CFLAGS += -flto
			LDFLAGS += --static -flto
		endif
	endif
	ifeq ($(UNAME), Darwin)
		OPEN_HTML=open
		#For MacOS force to build
		CFLAGS += -force_cpusubtype_ALL -mmacosx-version-min=10.6 -arch x86_64 -arch i386
		LDFLAGS += -force_cpusubtype_ALL -mmacosx-version-min=10.6 -arch x86_64 -arch i386
	endif
endif

all: check-env $(DIRS) $(SOURCES) $(EXECUTABLE)

check-env:
ifndef EMSCRIPTEN
	ifeq ($(BUILD_TYPE, WEB)
		$(error EMSCRIPTEN is not set)
	endif
endif


$(BUILD_DIR)/libclipper.a: $(LIBS_DIR)/clipper/clipper.cpp
	$(CXX) $(CFLAGS) -o $(BUILD_DIR)/libclipper.a $(LIBS_DIR)/clipper/clipper.cpp

$(EXECUTABLE): $(OBJECTS) $(BUILD_DIR)/libclipper.a
	$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)

$(DIRS):
	-@$(MKDIR_PREFIX) $(DIRS)

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
	$(CXX) $(CFLAGS) $< -o $@

test: $(EXECUTABLE)
	python tests/runtest.py $(abspath $(EXECUTABLE))

## clean stuff
clean:
	rm -f $(EXECUTABLE) $(OBJECTS)

help:
	@cat Makefile |grep \#\#| grep \: |cut -d\# -f3
{'fraction_non_alphanumeric': 0.16234786022771888, 'fraction_numerical': 0.01099332548095799, 'mean_word_length': 4.420212765957447, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1382213', 'n_tokens_mistral': 2157, 'n_tokens_neox': 1988, 'n_words': 466}