[英]editing Makefile for static build
我正在玩這個項目: https://github.com/chfritz/step2stl
我可以構建它並且運行良好。 但是,我正在查看 Makefile,我想知道如何更改它以創建一個靜態構建的二進制文件,該二進制文件將在沒有安裝依賴項的 linux 機器上運行。
我已經讀過將 -static 添加到 clang 命令的末尾會起作用,但是我迷失了 makefile 並試圖弄清楚要更改的內容...
這是代碼:
UNAME := $(shell uname -a)
OCEINCLUDE := $(shell if test -d /usr/local/include/oce; then echo "/usr/local/include/oce"; else echo ""; fi)
OPENCASCADEINC?=/usr/include/opencascade
OPENCASCADELIB?=/usr/lib/opencas
$(info Using OPENCASCADEINC as "${OPENCASCADEINC}")
$(info Using OPENCASCADELIB as "${OPENCASCADELIB}")
OCCLIBS=-lTKBRep -lTKG2d -lTKG3d -lTKGeomBase \
-lTKMath -lTKMesh -lTKSTEP -lTKSTEP209 \
-lTKSTEPAttr -lTKSTEPBase -lTKSTL -lTKXSBase -lTKernel \
ifeq "$(OCEINCLUDE)" ""
#CXX=gcc-4.4
CXXFLAGS += -I$(OPENCASCADEINC)
LDFLAGS += -L$(OPENCASCADELIB) -L/usr/lib ${OCCLIBS}
else
CXXFLAGS += -I/usr/local/include/oce -I/usr/include
LDFLAGS += -L/usr/local/lib -L/usr/lib ${OCCLIBS}
endif
# Required to compile on gentoo systems.
ifeq (gentoo,$(findstring gentoo,$(UNAME)))
CXXFLAGS = -I/usr/lib64/opencascade-6.5/ros/lin/inc
LDFLAGS = -L/usr/lib64/opencascade-6.5/ros/lin/lib64 ${OCCLIBS} -lGL
endif
# note that in ubuntu oneiric you will want to use gcc-4.4, since the
# opencascade libraries don't seem wotk work with 4.6 (because they
# were probably compiled with 4.4). on ifab.parc.com i just made 4.4
# the default.
#ifeq (Ubuntu,$(findstring Ubuntu,$(UNAME)))
#UBUNTUDISTRO := $(shell lsb_release -c)
#ifeq (oneiric,$(findstring oneiric,$(UBUNTUDISTRO)))
#CXX=g++-4.9
CXX=clang++ -std=c++11 -stdlib=libc++
#endif
#endif
#---------------------------------------------------------------------
#targets
#---------------------------------------------------------------------
ifeq "$(MAKECMDGOALS)" ""
CXXFLAGS += -ggdb3
endif
ifeq "$(MAKECMDGOALS)" "profile"
CXXFLAGS += -pg -ggdb3
LDFLAGS += -pg
endif
# Determine where we should output the object files.
OUTDIR = debug
ifeq "$(MAKECMDGOALS)" "debug"
OUTDIR = debug
CXXFLAGS += -ggdb3
endif
ifeq "$(MAKECMDGOALS)" "release"
OUTDIR = release
CXXFLAGS += -O3
endif
ifeq "$(MAKECMDGOALS)" "profile"
OUTDIR = profile
endif
# Add .d to Make's recognized suffixes.
SUFFIXES += .d
# We don't need to clean up when we're making these targets
NODEPS:=clean
#Find all the C++ files in the src/ directory
#SOURCES:=$(shell find * -name '*.cpp' | sort)
SOURCES:=$(shell ls *.cpp | sort)
OBJS:=$(patsubst %.cpp,%.o,$(SOURCES))
#These are the dependency files, which make will clean up after it creates them
DEPFILES:=$(patsubst %.cpp,%.d,$(SOURCES))
#Don't create dependencies when we're cleaning, for instance
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
-include $(DEPFILES)
endif
EXE = step2stl
ifeq (Darwin,$(findstring Darwin,$(UNAME)))
SHARED=-dynamiclib -flat_namespace
SHAREDLIB=step2stl.so.dylib
else
SHARED=-fPIC -shared
SHAREDLIB=step2stl.so
endif
all: $(EXE)
lib:
g++ -I/usr/local/include/oce -O3 -L/usr/local/lib $(OCCLIBS) -o $(SHAREDLIB) $(SHARED) lib.cpp
ffi-generate -f lib.hpp -l $(SHAREDLIB) -m step3stl -L /Library/Developer/CommandLineTools/usr/lib > node-ffi.js
debug: $(EXE)
release:$(EXE)
profile:$(EXE)
$(EXE): $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
#This is the rule for creating the dependency files
deps/%.d: %.cpp
$(CXX) $(CXXFLAGS) -MM -MT '$(patsubst src/%,obj/%,$(patsubst %.cpp,%.o,$<))' $< > $@
#This rule does the compilation
obj/%.o: %.cpp %.d %.h
@$(MKDIR) $(dir $@)
$(CXX) $(CXXFLAGS) -o $@ -c $<
# make clean && svn update
clean:
bash -c 'rm -f *.o $(OBJS) $(EXE)'
install:
cp $(SHAREDLIB) /usr/local/lib
ldconfig
安裝GNU remake並運行remake -X
。
它將帶您進入調試器,然后您可以運行step
查看 makefile 正在做什么。 這是適用於您的 Makefile 的:
$ remake -X -f /tmp/Makefile
Reading makefiles...
Using OPENCASCADEINC as "/usr/include/opencascade"
Using OPENCASCADELIB as "/usr/lib/opencas"
ls: cannot access '*.cpp': No such file or directory
Updating makefiles...
Updating goal targets...
File 'all' does not exist.
-> (/tmp/Makefile:117)
step2stl:
remake<0> where
=>#0 step2stl at /tmp/Makefile:117
#1 all at /tmp/Makefile:105
remake<1> step
File 'step2stl' does not exist.
Must remake target 'step2stl'.
/tmp/Makefile:118: target 'step2stl' does not exist
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
clang++ -std=c++11 -stdlib=libc++ -L/usr/lib/opencas -L/usr/lib -lTKBRep -lTKG2d -lTKG3d -lTKGeomBase -lTKMath -lTKMesh -lTKSTEP -lTKSTEP209 -lTKSTEPAttr -lTKSTEPBase -lTKSTL -lTKXSBase -lTKernel -o step2stl
##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
++ (/tmp/Makefile:117)
step2stl
remake<2> help
remake: That's all, folks...
請參閱視頻鏈接。 或https://github.com/rocky/remake獲取一些屏幕截圖
它將帶您進入調試器,然后您可以運行step
查看 makefile 正在做什么。 請參閱視頻鏈接。 或https://github.com/rocky/remake獲取一些屏幕截圖
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.