Thread: How to I 'make' from subfolders?

  1. #1
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

    How to I 'make' from subfolders?

    I am making an OpenGL framework on which to base my code on while learning OpenGL (and Computer Graphics in general).
    It is structured in a way that I only have to modify a few data files and shaders along with a single .cpp file to implement examples.
    I want to move that 'unit' away from the framework code, into independent subfolders, so that I can work on multiple things at the same time.
    I can't figure out how to incorporate that into 'make' .

    So far, I'm using a pretty crude chell script that copies the .cpp file into the main folder, invokes the original Makefile and moves back the executable to the subfolder so that it can reach its files.

    What is a better way to do this ?
    Any build system recommendation that supports this kind of stuff 'naturally' ?

    (Here is the code, https://bitbucket.org/manasij7479/gl/ )

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    It is structured in a way that I only have to modify a few data files and shaders along with a single .cpp file to implement examples.
    This is by definition not part of the framework.

    It is part of the examples of using the framework.

    This file, and all such files, always belong in a different directory.

    Use relative linking, in whatever fashion, to build these examples. The example files can just stay in their directories.

    You can then just call `make' against files in those directories with a file, such as a library, as a prerequisite for building the examples so that building one of those would also call the main source to build.

    Soma

  3. #3
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Thanks.
    Can't believe I didn't think of putting them on the 'same level' before.
    Would have to tinker a bit to get it working nicely.

    **Wow..a lot of typos in my original post.
    And now I'm irritated that I can't edit them .

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    This is what I finally did.
    Example Makefile:
    Code:
    TARGET:= main
    DIR:=../../framework/
    SRC:=mygl.cpp
    CXX:=g++
    CXXFLAGS :=-Wall -std=c++11 -g
    LDFLAGS := -lframework -lpthread -lGL -lGLEW -lsfml-system -lsfml-window
    default: $(TARGET)
        
    lib:
        make -j9 -C $(DIR) 
    $(TARGET): $(SRC) lib
        $(CXX) $(SRC) -I$(DIR) -L$(DIR) $(LDFLAGS) $(CXXFLAGS) -o $(TARGET)
    clean:
        rm $(TARGET)
        make clean -C $(DIR)
    Framework Makefile:
    Code:
    CXX:= g++
    CXXFLAGS :=-c -Wall -std=c++11 -g
    SRCS := $(wildcard *.cpp)
    OBJS := $(patsubst %.cpp, %.o, $(SRCS))
    TARGET := libframework.a
    default : $(TARGET)
    %.o : %.cpp %.h
        $(CXX) $(CXXFLAGS) $< -o $@
    $(TARGET) : $(OBJS)
        ar rcs $(TARGET)  $^
    clean :
        rm -f $(OBJS) $(TARGET) *~ *.a *.o

  5. #5
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by manasij7479 View Post
    For some reason I cannot access the code,...I wanted to have a glimpse of it

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    He doesn't have it set to private.

    Beyond that, he'd have little control.

    Just try again...

    Soma

  7. #7
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Yap it just worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-23-2012, 10:07 AM
  2. Creating a folder with subfolders
    By JonathanS in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2012, 05:26 PM
  3. Replies: 2
    Last Post: 04-27-2011, 04:14 PM
  4. Deleting subfolders and such...
    By HelpLol in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2008, 01:23 AM
  5. Replies: 6
    Last Post: 04-20-2002, 06:35 PM