Skip to content

Instantly share code, notes, and snippets.

@hmyit
Forked from kanedo/Makefile
Created May 7, 2020 00:55
Show Gist options
  • Select an option

  • Save hmyit/c1e2f0413cfd67d217b12cfd89e5efc1 to your computer and use it in GitHub Desktop.

Select an option

Save hmyit/c1e2f0413cfd67d217b12cfd89e5efc1 to your computer and use it in GitHub Desktop.

Revisions

  1. @kanedo kanedo revised this gist Apr 18, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,10 @@ CFLAGS=-g -c
    # Linker Flags
    #-lz use with zlib for gzstream.o
    LDFLAGS=-g -lz

    # define an asset dir (optional)
    ASSETSDIR=assets
    # set to 1 if ASSETSDIR should be copied to BUILDIR
    # set to 0 if not
    WITH_COPY_ASSETS=1

    # CONFIGURATION_BUILD_DIR is usually defined by Xcode
    @@ -31,9 +34,6 @@ else
    BUILDIR=build
    endif

    # define an asset dir (optional)
    ASSETSDIR=assets

    # list dependencies
    # DEPS=gzstream.c
    DEPS=
  2. @kanedo kanedo revised this gist Apr 18, 2014. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,8 @@ CFLAGS=-g -c
    #-lz use with zlib for gzstream.o
    LDFLAGS=-g -lz

    WITH_COPY_ASSETS=1

    # CONFIGURATION_BUILD_DIR is usually defined by Xcode
    # use it.
    # otherwise (e.g. invoked from commandline) use build/ as buildir
    @@ -33,7 +35,8 @@ endif
    ASSETSDIR=assets

    # list dependencies
    DEPS=gzstream.c
    # DEPS=gzstream.c
    DEPS=
    # replace .c file ending and replace it with .o. change dir to $(BUILDIR)
    DEPS_OBJECTS=$(patsubst %.c,$(BUILDIR)/%.o,$(DEPS))

    @@ -57,8 +60,10 @@ all: $(BUILDIR)/$(EXECUTABLE)
    # PRODUCT_NAME is usually defined by xcode in which case only make all is invoked
    # to run the project. we need to copy some asset-files in the build folder in order to run the executable properly
    ifdef PRODUCT_NAME
    ifeq ($(WITH_COPY_ASSETS),1)
    $(MAKE) COPY_ASSETS
    endif
    endif

    # build executable
    $(BUILDIR)/$(EXECUTABLE): $(BUILDIR) $(DEPS_OBJECTS) $(OBJECTS)
    @@ -85,9 +90,11 @@ COPY_ASSETS:
    # copies optional asset files and
    # invokes the exec with arguments
    run: all
    ifeq ($(WITH_COPY_ASSETS),1)
    $(MAKE) COPY_ASSETS
    endif
    ./$(BUILDIR)/$(EXECUTABLE) -e $(BUILDIR)/$(ASSETSDIR)/e.train.gz -f $(BUILDIR)/$(ASSETSDIR)/f.train.gz -a $(BUILDIR)/$(ASSETSDIR)/Alignment.gz

    # remove generated files
    clean:
    rm -rf $(BUILDIR) $(DEPS_OBJECTS) $(OBJECTS) $(EXECUTABLE)
    rm -rf $(BUILDIR) $(DEPS_OBJECTS) $(OBJECTS) $(EXECUTABLE)
  3. @kanedo kanedo revised this gist Apr 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ else
    EXECUTABLE=singleWordExtract
    endif

    .PHONY all run clean COPY_ASSETS
    .PHONY: all run clean COPY_ASSETS

    all: $(BUILDIR)/$(EXECUTABLE)
    # PRODUCT_NAME is usually defined by xcode in which case only make all is invoked
  4. @kanedo kanedo created this gist Apr 18, 2014.
    93 changes: 93 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,93 @@
    #############################################################
    # #
    # Generic Makefile for C++ projects #
    # Author: Gabriel <[email protected]> #
    # Date: 2014-04-18 #
    # Version: 1.0 #
    # #
    #############################################################


    # the C++ Compiler
    CPP=g++
    # the C Compiler
    CC=gcc
    # Compiler flags for C++
    CPPFLAGS=-g -c
    # Compiler flags for C
    CFLAGS=-g -c
    # Linker Flags
    #-lz use with zlib for gzstream.o
    LDFLAGS=-g -lz

    # CONFIGURATION_BUILD_DIR is usually defined by Xcode
    # use it.
    # otherwise (e.g. invoked from commandline) use build/ as buildir
    ifdef CONFIGURATION_BUILD_DIR
    BUILDIR=$(CONFIGURATION_BUILD_DIR)
    else
    BUILDIR=build
    endif

    # define an asset dir (optional)
    ASSETSDIR=assets

    # list dependencies
    DEPS=gzstream.c
    # replace .c file ending and replace it with .o. change dir to $(BUILDIR)
    DEPS_OBJECTS=$(patsubst %.c,$(BUILDIR)/%.o,$(DEPS))

    # list sources
    SOURCES=$(wildcard *.cpp)
    # replace .cpp file ending and replace it with .o. change dir to $(BUILDIR)
    OBJECTS=$(patsubst %.cpp,$(BUILDIR)/%.o,$(SOURCES))

    # PRODUCT_NAME is usually defined by Xcode.
    # use it as executable name
    # otherwise define your own
    ifdef PRODUCT_NAME
    EXECUTABLE=$(PRODUCT_NAME)
    else
    EXECUTABLE=singleWordExtract
    endif

    .PHONY all run clean COPY_ASSETS

    all: $(BUILDIR)/$(EXECUTABLE)
    # PRODUCT_NAME is usually defined by xcode in which case only make all is invoked
    # to run the project. we need to copy some asset-files in the build folder in order to run the executable properly
    ifdef PRODUCT_NAME
    $(MAKE) COPY_ASSETS
    endif

    # build executable
    $(BUILDIR)/$(EXECUTABLE): $(BUILDIR) $(DEPS_OBJECTS) $(OBJECTS)
    $(CPP) $(LDFLAGS) $(DEPS_OBJECTS) $(OBJECTS) -o $@

    # compile dependencies
    $(DEPS_OBJECTS): $(DEPS)
    ${CPP} -I. -O -c $< -o $@

    # compile cpp files
    $(BUILDIR)/%.o: %.cpp
    $(CPP) $(CPPFLAGS) $< -o $@

    # target to create the builddir
    $(BUILDIR):
    mkdir -p $@

    # phony target to copy asset files into the builddir
    COPY_ASSETS:
    mkdir -p $(BUILDIR)/$(ASSETSDIR)
    cp -rf $(ASSETSDIR)/ $(BUILDIR)/$(ASSETSDIR)

    # phony target which calls the executable
    # copies optional asset files and
    # invokes the exec with arguments
    run: all
    $(MAKE) COPY_ASSETS
    ./$(BUILDIR)/$(EXECUTABLE) -e $(BUILDIR)/$(ASSETSDIR)/e.train.gz -f $(BUILDIR)/$(ASSETSDIR)/f.train.gz -a $(BUILDIR)/$(ASSETSDIR)/Alignment.gz

    # remove generated files
    clean:
    rm -rf $(BUILDIR) $(DEPS_OBJECTS) $(OBJECTS) $(EXECUTABLE)