Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

linux makefile

  • Loading branch information...
commit fed2e0d7d3d5c7488d2f32dd0c8e47a6ce802686 1 parent 37e578d
arturo authored

Showing 2 changed files with 240 additions and 0 deletions. Show diff stats Hide diff stats

  1. +4 0 addons.make
  2. +236 0 makefile
4 addons.make
... ... @@ -0,0 +1,4 @@
  1 +ofxThread
  2 +ofxOpenCv
  3 +ofxXmlSettings
  4 +ofxVectorMath
236 makefile
... ... @@ -0,0 +1,236 @@
  1 +# openFrameworks universal makefile
  2 +#
  3 +# make help : shows this message
  4 +# make Debug: makes the application with debug symbols
  5 +# make Release: makes the app with optimizations
  6 +# make: the same as make Release
  7 +# make CleanDebug: cleans the Debug target
  8 +# make CleanRelease: cleans the Release target
  9 +# make clean: cleans everything
  10 +#
  11 +#
  12 +# this should work with any OF app, just copy any example
  13 +# change the name of the folder and it should compile
  14 +# only .cpp support, don't use .c files
  15 +# it will look for files in any folder inside the application
  16 +# folder except that in the EXCLUDE_FROM_SOURCE variable
  17 +# it doesn't autodetect include paths yet
  18 +# add the include paths in the USER_CFLAGS variable
  19 +# using the gcc syntax: -Ipath
  20 +#
  21 +# to add addons to your application, edit the addons.make file
  22 +# in this directory and add the names of the addons you want to
  23 +# include
  24 +#
  25 +# edit the following vars to customize the makefile
  26 +
  27 +
  28 +COMPILER_OPTIMIZATION = -march=native -mtune=native -O3 -finline-functions -funroll-all-loops -funroll-loops -fomit-frame-pointer -ffast-math -ftree-vectorize -fopenmp
  29 +EXCLUDE_FROM_SOURCE="bin,.xcodeproj,obj"
  30 +USER_CFLAGS = -I/usr/include/libusb-1.0 -I src/ofxKinect/src
  31 +USER_LD_FLAGS = -lusb-1.0
  32 +USER_LIBS =
  33 +OTHER_ADDONS_PATH = src/
  34 +
  35 +
  36 +
  37 +
  38 +# you shouldn't modify anything below this line
  39 +
  40 +
  41 +SHELL = /bin/sh
  42 +CXX = g++
  43 +
  44 +ARCH = $(shell uname -m)
  45 +ifeq ($(ARCH),x86_64)
  46 + LIBSPATH=linux64
  47 +else
  48 + LIBSPATH=linux
  49 +endif
  50 +
  51 +NODEPS = clean
  52 +SED_EXCLUDE_FROM_SRC = $(shell echo $(EXCLUDE_FROM_SOURCE) | sed s/\,/\\\\\|/g)
  53 +SOURCE_DIRS = $(shell find . -maxdepth 1 -mindepth 1 -type d | grep -v $(SED_EXCLUDE_FROM_SRC) | sed s/.\\///)
  54 +SOURCES = $(shell find $(SOURCE_DIRS) -name "*.cpp" -or -name "*.c")
  55 +OBJFILES = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCES)))
  56 +APPNAME = $(shell basename `pwd`)
  57 +CORE_INCLUDES = $(shell find ../../../libs/openFrameworks/ -type d)
  58 +CORE_INCLUDE_FLAGS = $(addprefix -I,$(CORE_INCLUDES))
  59 +INCLUDES = $(shell find ../../../libs/*/include -type d)
  60 +INCLUDES_FLAGS = $(addprefix -I,$(INCLUDES))
  61 +LIB_STATIC = $(shell ls ../../../libs/*/lib/$(LIBSPATH)/*.a | grep -v openFrameworksCompiled | sed "s/.*\\/lib\([^/]*\)\.a/-l\1/")
  62 +LIB_SHARED = $(shell ls ../../../libs/*/lib/$(LIBSPATH)/*.so | grep -v openFrameworksCompiled| sed "s/.*\\/lib\([^/]*\)\.so/-l\1/")
  63 +
  64 +#LIB_PATHS_FLAGS = -L../../../libs/openFrameworksCompiled/lib/$(LIBSPATH)
  65 +LIB_PATHS_FLAGS = $(shell ls -d ../../../libs/*/lib/$(LIBSPATH) | sed "s/\(\.*\)/-L\1/")
  66 +
  67 +CFLAGS = -Wall -fexceptions
  68 +CFLAGS += -I.
  69 +CFLAGS += $(INCLUDES_FLAGS)
  70 +CFLAGS += $(CORE_INCLUDE_FLAGS)
  71 +CFLAGS +=`pkg-config gstreamer-0.10 gstreamer-video-0.10 gstreamer-base-0.10 libudev --cflags`
  72 +
  73 +LDFLAGS = $(USER_LD_FLAGS) $(LIB_PATHS_FLAGS) -Wl,-rpath=./libs
  74 +
  75 +LIBS = $(LIB_SHARED)
  76 +LIBS += $(LIB_STATIC)
  77 +LIBS +=`pkg-config gstreamer-0.10 gstreamer-video-0.10 gstreamer-base-0.10 libudev --libs`
  78 +LIBS += -lglut -lGL -lGLU -lasound
  79 +
  80 +ifeq ($(findstring addons.make,$(wildcard *.make)),addons.make)
  81 + ADDONS_INCLUDES = $(shell find ../../../addons/*/src/ -type d)
  82 + ADDONS_INCLUDES += $(shell find ../../../addons/*/libs/ -type d)
  83 + ADDONS_INCLUDES += $(shell find $(OTHER_ADDONS_PATH)/*/src/ -type d)
  84 + ADDONS_INCLUDES += $(shell find $(OTHER_ADDONS_PATH)/*/libs/ -type d)
  85 + ADDONSCFLAGS = $(addprefix -I,$(ADDONS_INCLUDES))
  86 +
  87 + ADDONS_LIBS_STATICS = $(shell ls ../../../addons/*/libs/*/lib/$(LIBSPATH)/*.a)
  88 + ADDONS_LIBS_SHARED = $(shell ls ../../../addons/*/libs/*/lib/$(LIBSPATH)/*.so)
  89 + ADDONS_LIBS_STATICS += $(shell ls $(OTHER_ADDONS_PATH)/*/libs/*/lib/$(LIBSPATH)/*.a)
  90 + ADDONS_LIBS_SHARED += $(shell ls $(OTHER_ADDONS_PATH)/*/libs/*/lib/$(LIBSPATH)/*.so)
  91 +
  92 + ADDONSLIBS = $(ADDONS_LIBS_STATICS)
  93 + ADDONSLIBS += $(ADDONS_LIBS_SHARED)
  94 +
  95 + ADDONS = $(shell cat addons.make)
  96 + ADDONS_REL_DIRS = $(addsuffix /src, $(ADDONS))
  97 + ADDONS_LIBS_REL_DIRS = $(addsuffix /libs, $(ADDONS))
  98 + ADDONS_DIRS = $(addprefix ../../../addons/, $(ADDONS_REL_DIRS) )
  99 + ADDONS_LIBS_DIRS = $(addprefix ../../../addons/, $(ADDONS_LIBS_REL_DIRS) )
  100 + OTHER_ADDONS_DIRS = $(addprefix $(OTHER_ADDONS_PATH)/, $(ADDONS_REL_DIRS) )
  101 + OTHER_ADDONS_LIBS_DIRS = $(addprefix $(OTHER_ADDONS_PATH)/, $(ADDONS_LIBS_REL_DIRS) )
  102 + ADDONS_SOURCES = $(shell find $(ADDONS_DIRS) -name "*.cpp" -or -name "*.c")
  103 + ADDONS_SOURCES += $(shell find $(ADDONS_LIBS_DIRS) -name "*.cpp" -or -name "*.c" 2>/dev/null)
  104 + ADDONS_SOURCES += $(shell find $(OTHER_ADDONS_DIRS) -name "*.cpp" -or -name "*.c")
  105 + ADDONS_SOURCES += $(shell find $(OTHER_ADDONS_LIBS_DIRS) -name "*.cpp" -or -name "*.c" 2>/dev/null)
  106 + ADDONS_OBJFILES = $(subst ../../../, ,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(ADDONS_SOURCES))))
  107 +endif
  108 +
  109 +
  110 +
  111 +ifeq ($(findstring Debug,$(MAKECMDGOALS)),Debug)
  112 + TARGET_CFLAGS = -g
  113 + TARGET_LIBS = -lopenFrameworksDebug
  114 + TARGET_NAME = Debug
  115 + BIN_NAME = $(APPNAME)_debug
  116 + TARGET = bin/$(BIN_NAME)
  117 +endif
  118 +
  119 +ifeq ($(findstring Release,$(MAKECMDGOALS)),Release)
  120 + TARGET_CFLAGS = $(COMPILER_OPTIMIZATION)
  121 + TARGET_LIBS = -lopenFrameworks
  122 + TARGET_NAME = Release
  123 + BIN_NAME = $(APPNAME)
  124 + TARGET = bin/$(BIN_NAME)
  125 +endif
  126 +
  127 +ifeq ($(MAKECMDGOALS),)
  128 + TARGET_CFLAGS = $(COMPILER_OPTIMIZATION)
  129 + TARGET_LIBS = -lopenFrameworks
  130 + TARGET_NAME = Release
  131 + BIN_NAME = $(APPNAME)
  132 + TARGET = bin/$(BIN_NAME)
  133 +endif
  134 +
  135 +ifeq ($(MAKECMDGOALS),clean)
  136 + TARGET = bin/$(APPNAME)_debug bin/$(APPNAME)
  137 +endif
  138 +
  139 +OBJ_OUTPUT = obj/$(TARGET_NAME)/
  140 +CLEANTARGET = Clean$(TARGET_NAME)
  141 +OBJS = $(addprefix $(OBJ_OUTPUT), $(OBJFILES))
  142 +DEPFILES = $(patsubst %.o,%.d,$(OBJS))
  143 +ifeq ($(findstring addons.make,$(wildcard *.make)),addons.make)
  144 + ADDONS_OBJS = $(addprefix $(OBJ_OUTPUT), $(ADDONS_OBJFILES))
  145 + DEPFILES += $(patsubst %.o,%.d,$(ADDONS_OBJS))
  146 +endif
  147 +
  148 +.PHONY: Debug Release all after
  149 +
  150 +Release: $(TARGET) after
  151 +
  152 +Debug: $(TARGET) after
  153 +
  154 +all:
  155 + make Release
  156 +
  157 +
  158 +#This rule does the compilation
  159 +#$(OBJS): $(SOURCES)
  160 +$(OBJ_OUTPUT)%.o: %.cpp
  161 + @echo "compiling object for: " $<
  162 + mkdir -p $(@D)
  163 + $(CXX) -c $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o$@ -c $<
  164 +
  165 +$(OBJ_OUTPUT)%.o: %.c
  166 + @echo "compiling object for: " $<
  167 + mkdir -p $(@D)
  168 + $(CC) -c $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o$@ -c $<
  169 +
  170 +
  171 +$(OBJ_OUTPUT)%.o: ../../../%.cpp
  172 + @echo "compiling addon object for" $<
  173 + mkdir -p $(@D)
  174 + $(CXX) $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o $@ -c $<
  175 +
  176 +$(OBJ_OUTPUT)%.o: ../../../%.c
  177 + @echo "compiling addon object for" $<
  178 + mkdir -p $(@D)
  179 + $(CC) $(TARGET_CFLAGS) $(CFLAGS) $(ADDONSCFLAGS) $(USER_CFLAGS) -MMD -MP -MF$(OBJ_OUTPUT)$*.d -MT$(OBJ_OUTPUT)$*.d -o $@ -c $<
  180 +
  181 +$(TARGET): $(OBJS) $(ADDONS_OBJS)
  182 + @echo "linking" $(TARGET)
  183 + $(CXX) -o $@ $(OBJS) $(ADDONS_OBJS) $(LDFLAGS) $(USER_LDFLAGS) $(USER_LIBS) $(TARGET_LIBS) $(LIBS) $(ADDONSLIBS)
  184 +
  185 +-include $(DEPFILES)
  186 +
  187 +.PHONY: clean CleanDebug CleanRelease
  188 +clean:
  189 + rm -Rf obj
  190 + rm -f -v $(TARGET)
  191 + rm -Rf -v bin/libs
  192 +
  193 +$(CLEANTARGET):
  194 + rm -Rf -v $(OBJ_OUTPUT)
  195 + rm -f -v $(TARGET)
  196 +
  197 +
  198 +after:
  199 + cp -r ../../../export/$(LIBSPATH)/libs bin/
  200 + @echo
  201 + @echo " compiling done"
  202 + @echo " to launch the application"
  203 + @echo
  204 + @echo " cd bin"
  205 + @echo " ./$(BIN_NAME)"
  206 + @echo
  207 +
  208 +
  209 +.PHONY: help
  210 +help:
  211 + @echo
  212 + @echo openFrameworks universal makefile
  213 + @echo
  214 + @echo targets:
  215 + @echo "make Debug: builds the application with debug symbols"
  216 + @echo "make Release: builds the app with optimizations"
  217 + @echo "make: = make Release"
  218 + @echo "make all: = make Release"
  219 + @echo "make CleanDebug: cleans the Debug target"
  220 + @echo "make CleanRelease: cleans the Release target"
  221 + @echo "make clean: cleans everything"
  222 + @echo
  223 + @echo this should work with any OF app, just copy any example
  224 + @echo change the name of the folder and it should compile
  225 + @echo "only .cpp support, don't use .c files"
  226 + @echo it will look for files in any folder inside the application
  227 + @echo folder except that in the EXCLUDE_FROM_SOURCE variable.
  228 + @echo "it doesn't autodetect include paths yet"
  229 + @echo "add the include paths editing the var USER_CFLAGS"
  230 + @echo at the beginning of the makefile using the gcc syntax:
  231 + @echo -Ipath
  232 + @echo
  233 + @echo to add addons to your application, edit the addons.make file
  234 + @echo in this directory and add the names of the addons you want to
  235 + @echo include
  236 + @echo

0 comments on commit fed2e0d

Please sign in to comment.
Something went wrong with that request. Please try again.