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
    Location
    Kolkata@India
    Posts
    2,498

    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/ )
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,332
    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
    Location
    Kolkata@India
    Posts
    2,498
    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 .
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    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
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    169
    Quote Originally Posted by manasij7479 View Post
    For some reason I cannot access the code,...I wanted to have a glimpse of it
    In C++14 you just write "auto auto(auto auto) { auto; }".
    The compiler infers the rest from context.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,332
    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
    169
    Yap it just worked.
    In C++14 you just write "auto auto(auto auto) { auto; }".
    The compiler infers the rest from context.

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