Thread: short makefile problem

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604

    Question short makefile problem

    Been a while since I programmed last and had to make a makefile from scratch, this is not for a game but I didn't see any other boards here that would take this question without issue.
    This is my makefile as it stands:
    Code:
    TOP?=
    SYS:=$(if ${.ProgramFiles},posix,win32)
    CWD:=$(CURRENT_DIRECTORY)
    ECHO=$1: $($1)
    
    PAW_INC_DIR:=$(TOP)/include
    PAW_SRC_DIR:=$(TOP)/src
    
    PAW_SRC:=$(SYS)/paw.c
    PAW_INC:=$(SYS)/paw.h
    PAW_MAK:=$(PAW_INC: %.h=%.h.mak) $(PAW_SRC: %.c=%.c.mak)
    
    VPATHS:=$(PAW_SRC_DIR);$(PAW_INC_DIR)
    
    include $(PAW_MAK)
    
    all: shared
        @echo $(call ECHO,CWD)
    
    shared: $(SYS)/shared.c $(SYS)/paw.c
        @echo PAW_BUILD_SHARED
    
    test: shared
        @echo PAW_BUILD_TEST
    
    %.c.mak: %.c
        @echo -D DEF_DEP $< $$
    
    %.c.o: %.c
        @echo $< $$
    #@echo gcc -std=c99 $< -o $$
    
    %.cpp.mak: %.cpp
        @echo -D DEF_DEP $< $$
    
    %.cpp.o: %.cpp
        @echo $< $$
    #@echo gcc $< -o $$
    My problem is the
    Code:
    include $(PAW_MAK)
    part is resulting in errors, my console output looks like this:
    Code:
    NPP_EXEC: "Run Make"
    NPP_SAVEALL
    make -f "X:\GitHub\paw\src\makefile.mak"
    Process started >>>
    X:\GitHub\paw\src\makefile.mak:15: win32/paw.c: No such file or directory
    make: *** No rule to make target 'win32/paw.c'.  Stop.
    <<< Process finished. (Exit code 2)
    ================ READY ================
    This is despite the file actually existing, I expected errors in finding win32/paw.c.mak & win32.h.mak since those don't exist yet but the source files being reported wrong leads me to believe I did something wrong with VPATHS, any help is appreciated here.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    630
    Doesn't this conditional function have it's then and else parts the wrong way round?
    Code:
    SYS:=$(if ${.ProgramFiles},posix,win32)
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  3. #3
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    I didn't check that, for now I'm getting win32 as the result so I'll leave it until later, for now I just want to be able to auto generate the compile paths and dependencies so I can then check my project code (wrote it from scratch without compiling so I am sure there are errors to be fixed) which means I need my includes and targets responding correctly

    Edit: In case you want to try fiddling about using actual files here's the project: GitHub - awsdert/paw: Process API Wrapper
    Last edited by awsdert; 05-28-2018 at 12:36 PM.

  4. #4
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    Resolved the problem, turned out I hadn't noticed that Notepad++ wasn't passing on the current directory properly, after that I started getting proper response from make . Made some changes to my makefile also but still not reaching the compiling object stage, if someone could help me identify the issue I'd be most grateful, in meantime I will check the $(if ...) spec along with environment variable spec.

    Code:
    NPP_EXEC: "Run Make"
    NPP_SAVEALL
    CD: X:\GitHub\paw\src
    Current directory: X:\GitHub\paw\src
    make -f "X:\GitHub\paw\src\makefile.mak" -D CURRENT_DIRECTORY="X:\GitHub\paw\src"
    Process started >>>
    make: Nothing to be done for 'paw.h'.
    make (pid = 3700)
    make is suspending for 30 seconds...done sleep(30). Continuing.
    <<< Process finished. (Exit code 0)
    ================ READY ================
    Code:
    TOP?=../
    SYS:=$(if ${.ProgramFiles},posix,win32)
    SYS32?=$(if ${.ProgramFiles},,$(if {.ProgramFiles_x86},64,32))
    LIB_PFX:=$(if ${.ProgramFiles},lib,)
    LIB_SFX:=$(SYS32)$(if ${.ProgramFiles},.so,.dll)
    EXE_SFX:=$(SYS32)$(if ${.ProgramFiles},,.exe)
    APP_SFX:=$(SYS32)$(EXE_SFX)
    
    PAW_INC_DIR:=$(TOP)include
    PAW_SRC_DIR:=$(TOP)src
    
    PAW_SRC:=$(SYS)/paw.c
    PAW_CPP:=
    PAW_INC:=$(SYS)/paw.h
    PAW_OBJ:=$(PAW_SRC:%.c=%.c.o) $(PAW_CPP:%.cpp=%.cpp.o)
    PAW_MAK:=$(PAW_INC:%.h=%.h.mak) $(PAW_SRC:%.c=%.c.mak)
    
    VPATHS:="$(PAW_SRC_DIR)";"$(PAW_INC_DIR)"
    
    CC:=gcc
    IFLAGS:=-I"$(PAW_INC_DIR)" -I"$(PAW_SRC_DIR)"
    CFLAGS:=$(IFLAGS)
    MFLAGS:=$(IFLAGS) -E -DDEF_DEP
    
    include $(PAW_MAK)
    
    # Compile everything
    
    all: test
    	@echo all
    
    # Compile paw into a library file
    
    shared: $(PAW_SRC) $(PAW_OBJ)
    	@echo shared
    	$(CC) $(IFLAGS) -shared $(PAW_OBJ) -o $(LIB_PFX)paw$(LIB_SFX)
    
    # Compile a test app
    
    test: shared $(SYS)/test.c
    	@echo test
    	$(CC) $(IFLAGS) -text$(APP_SFX)
    
    # Compile *.mak options
    
    %.mak:
    	@echo %%.mak
    	$(CC) "$(patsubst %.mak,%,$@)" -o "$@" $(MFLAGS)
    
    # Compile *.o options
    
    %.c.o: %.c
    	@echo %%.c
    	$(CC) -c "$^" -o "$@" $(CFLAGS)
    
    %.cpp.o: %.cpp
    	@echo %%.cpp
    	$(CC) -c "$^" -o "$@" $(CFLAGS)

  5. #5
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    Quote Originally Posted by john.c View Post
    Doesn't this conditional function have it's then and else parts the wrong way round?
    Code:
    SYS:=$(if ${.ProgramFiles},posix,win32)
    Well you were right I was using it incorrectly and have now rectified that, still doesn't resolve my problem of no objects being compiled though

  6. #6
    Registered User
    Join Date
    Dec 2017
    Posts
    630
    Firstly, I'm not that great at make. But I interpret the conditional as saying "if ProgramFiles exists and is not blank, then assign win32, else assign posix.
    Code:
    SYS:=$(if ${.ProgramFiles},win32,posix)
    But I was wondering about that conditional function:
    1. Where does ProgramFiles get set? (And what is it's value.)
    2. Why does it have a period in front of it? (Or is that just part of its name?)

    And if the first conditional is backwards then they all are, so I assume you've switched them all around.
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  7. #7
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    Yep, the changes have been uploaded to the github project I mentioned earlier. ProgramFiles is an environment variable, just using it for the case that no target system is defined when make is executed, gonna use a separate variable for target system later but for now the host system is sufficient since I'm still deciding the API I'm gonna use as a wrapper.

  8. #8
    Registered User
    Join Date
    Dec 2017
    Posts
    630
    Are you certain that the environment variables are set up properly? And exported? And it is apparently .ProgramFiles, not ProgramFiles. (And .ProgramFiles_x86) Do the environment variables really have a period in front of the names?
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

  9. #9
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    Just realised I wasn't compiling the paw.h.mak because I didn't add it to PAW_INC, rectified that but now need a way to stop make from being suspended for 30s, dunno if it is from Notepad++ end or from make itself, anyone familiar with that sort of problem?

  10. #10
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    Quote Originally Posted by john.c View Post
    Are you certain that the environment variables are set up properly? And exported? And it is apparently .ProgramFiles, not ProgramFiles. (And .ProgramFiles_x86) Do the environment variables really have a period in front of the names?
    The period was a mistake, as I said before it had been a while since I last programmed and had written the makefile from scratch and since I don't usually touch the makefile after I got it doing what I want it to do I forgot whether it was needed for environment variables

  11. #11
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    Now I'm just stuck at compiling the dll, I doubt you need the full makefile now so I'll just provide the line executed when attempting the dll:
    Code:
    $(CC) $(LFLAGS) $(patsubst %,"%",$(PAW_OBJ)) -o $(LIB_PFX)paw$(LIB_SFX)
    And the console log:
    Code:
    NPP_EXEC: "Run Make"
    NPP_SAVEALL
    CD: X:\GitHub\paw\src
    Current directory: X:\GitHub\paw\src
    make -D CURRENT_DIRECTORY="X:\GitHub\paw\src" -D MINGW="X:\GitHub\paw\src/../mingw"
    Process started >>>
    make (pid = 2928)
    make is suspending for 30 seconds...done sleep(30). Continuing.
    shared
    gcc -shared -L"../include" -L"../src" -l "../src/win32/paw.c.o" "../src/win32/shared.c.o" -o paw64.dll
    x:/portableapps/pocketcpp_x64/mingw/bin/../lib/gcc/x86_64-w64-mingw32/6.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -l../src/win32/paw.c.o
    collect2.exe: error: ld returned 1 exit status
    make: *** [makefile:41: shared] Error 1
    <<< Process finished. (Exit code 2)
    ================ READY ================
    If you really need more of the makefile details the current state has already been uploaded to: GitHub - awsdert/paw: Process API Wrapper

  12. #12
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    Okay managed to fix that with an additional -L and tacking on -mwindows, now I need to figure out how to get my test executable compiled (cannot find an object that I can see in explorer just fine). At this point I'd say it's safe to close this thread now so I will attempt to close it myself but admin are free to do it if I can't (I'll try straight after posting this post)

  13. #13
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    604
    Nope I can find no such option, I'll leave it to the admin

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Playing a Short Music File Problem
    By aileentas in forum C++ Programming
    Replies: 6
    Last Post: 12-14-2012, 10:15 AM
  2. Short Sorting Problem
    By workisnotfun in forum C Programming
    Replies: 6
    Last Post: 11-19-2012, 12:11 AM
  3. short matrix problem
    By kiwi101 in forum C Programming
    Replies: 76
    Last Post: 10-04-2012, 01:31 PM
  4. Replies: 5
    Last Post: 10-01-2012, 10:57 PM
  5. Please help! short while loop tracking problem.
    By matthayzon89 in forum C Programming
    Replies: 7
    Last Post: 04-22-2010, 12:29 PM

Tags for this Thread