# Using Makefile to generate ToLua bindings - problems

This topic is 4346 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I need to update a Makefile in my little project that uses Lua and ToLua. I want to change the Makefile to automatically invoke ToLua on package files I create (.pkg), which contain C++ classes that will be exported to Lua. I thought I could do something like this: OBJS=file1.o file2.o Then define actions for the stages: 1) Run ToLua on .pkg file for each object file 2) Compile each .cpp that is generated (file1.cpp) by the ToLua tool into an object 3) Link each object file into a shared library The problem is that I can almost do this, except for two things: 1) It runs ToLua twice for the file1.o but it doesn't run for file2.o. 2) It always makes things, even if the .pkg file hasn't changed. Assuming I have something rough like the following, what am I doing wrong? Thanks
 ##############################################################
# Makefile for building the Habitat audio packages on Linux.
##############################################################

# Include the default configuration for the Linux build.
include ../../HabitatConfig.mk

# Include the external configuration for the Linux build.
include ../../HabitatExternalConfig.mk

# Override the suffix for C++ files.
.cpp.o:
$(G++)$(INCLUDES) $(EXTERNAL_INCS)$(WARN) -c $< #$(G++) -MMD $(INCLUDES)$(EXTERNAL_INCS) $(WARN) -c$< >> depend.txt

##############################################################
# Define the source and object files for the audio engine.
##############################################################

SRCS=hbAudioManager_lua.cpp

OBJS=hbAudioManager_lua.o

PKGS=hbAudioManager.pkg

##############################################################

T=$(AUDIO_PACKAGE_LIB)$(T): $(OBJS) @echo Building the Habitat audio packages.$(AR) $(INSTALL_LIB)/$@ $(OBJS)$(RANLIB) $(INSTALL_LIB)/$@

$(OBJS):$(SRCS)
$(G++)$(INCLUDES) $(EXTERNAL_INCS)$(WARN) -c $<$(SRCS):$(PKGS)$(TOLUA) -n $(basename$<) -H $(basename$<)_lua.h -o $(basename$<)_lua.cpp $(basename$<).pkg

clean:
@echo Cleaning the Habitat audio packages.

##### Share on other sites
Thanks John, the file1 was just for an example. I was going to write a simple example but I thought it would be easier to just post the makefile.

I understand what you're saying, and I've been racking my brains trying to understand how to do that. Maybe with your post I'll be able to solve it.

Thanks!

##### Share on other sites
I quickly tried that - it seems to work ok except for one thing; it always makes the files, even if nothing has changed. Any suggestions on how to only regenerate/build the files when one or more have changed?

Thanks again, much appreciated.

##### Share on other sites
Ok I got it working using:

T=$(AUDIO_PACKAGE_LIB)$(T): $(OBJS) @echo Building the Habitat audio packages.$(AR) $(INSTALL_LIB)/$@ $(OBJS)$(RANLIB) $(INSTALL_LIB)/$@%_lua.o: %_lua.cpp	@echo Compiling $<$(G++) $(INCLUDES)$(EXTERNAL_INCS) $(WARN) -c$<%_lua.cpp: %.pkg	@echo Creating packages $<$(TOLUA) -n $(basename$<) -H $(basename$<)_lua.h -o $(basename$<)_lua.cpp $< Except it deletes the CPP files before Make exits? Odd... Thanks #### Share this post ##### Link to post ##### Share on other sites Quote:  Original post by stodgeExcept it deletes the CPP files before Make exits? Odd... Intermediate files (such as files produced by implicit rules) are deleted when they are no longer needed. You can use the special target .SECONDARY to prevent this. Something like this I think:  .SECONDARY: %_lua.o %_lua.cpp  #### Share this post ##### Link to post ##### Share on other sites Ah makes some sense. I'll dig through the Make manual and read about that. Thanks, appreciate it! #### Share this post ##### Link to post ##### Share on other sites target `.SECONDARY' doesn't match the target pattern at this line: .SECONDARY: %_lua.cpp: %.pkg @echo Creating packages$<
$(TOLUA) -n$(basename $<) -H$(basename $<)_lua.h -o$(basename $<)_lua.cpp$<

• 23
• 10
• 19
• 15
• 14
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!