How to I 'make' from subfolders?

This is a discussion on How to I 'make' from subfolders? within the Tech Board forums, part of the Community Boards category; I am making an OpenGL framework on which to base my code on while learning OpenGL (and Computer Graphics in ...

  1. #1
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Posts
    2,599

    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
    4,942
    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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Posts
    2,599
    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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Posts
    2,599
    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
    407
    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
    4,942
    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
    407
    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, 12:23 AM
  5. Replies: 6
    Last Post: 04-20-2002, 06:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21