Rearchitect Makefile to support dependency tracking / fast incremental builds. Lua now built and linked as static library via its own Makefile. .gitignore modified to ignore *.d Makefile fragments with dependency info.
This commit is contained in:
parent
a8d9fe55bb
commit
0213df5580
|
|
@ -2,6 +2,7 @@
|
|||
# Ignore files ending in the following #
|
||||
########################################
|
||||
*.o
|
||||
*.d
|
||||
*.swp
|
||||
*.swo
|
||||
*.bin
|
||||
|
|
@ -14,3 +15,6 @@ firmware/source/shared_*.h
|
|||
|
||||
# ignore trash/temp files stored in host/ignore
|
||||
host/ignore
|
||||
|
||||
# OS X Metadata
|
||||
.DS_Store
|
||||
|
|
@ -1,25 +1,39 @@
|
|||
#compiler flags: -Wall Warnings all, -g gdb debug markings,
|
||||
CFLAGS=-Wall -O
|
||||
LDFLAGS= -llua -lusb-1.0 -Lsource/lua
|
||||
INCLUDE= -I ./include -I ../shared
|
||||
WINLIB= -L ./winlib
|
||||
LIBUSB= -lusb-1.0
|
||||
LDFLAGS_WINDOWS= -L ./winlib $(LDFLAGS)
|
||||
LDFLAGS_UNIX= -lm $(LDFLAGS)
|
||||
CC= gcc
|
||||
|
||||
SOURCES=$(wildcard source/*.c source/lua/*.c)
|
||||
OBJECTS=$(patsubst %.c,%.o,$(SOURCES))
|
||||
SOURCES=$(wildcard source/*.c)
|
||||
OBJECTS=$(SOURCES:.c=.o)
|
||||
|
||||
LUAOBJ=$(wildcard source/lua/*.o)
|
||||
# Use GCC preprocessor to determine dependencies for all source files.
|
||||
DEPS=$(OBJECTS:.o=.d)
|
||||
%.d: %.c
|
||||
@$(CC) $(CFLAGS) $(INCLUDE) $< -MM -MT $(@:.d=.o) >$@
|
||||
# Include generated .d Makefile fragments to manage object dependencies.
|
||||
-include $(DEPS)
|
||||
|
||||
# Provide recipes for building all objects, dependencies managed via earlier inclusion.
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $<
|
||||
|
||||
# TODO: Pass through platform when building liblua.
|
||||
liblua:
|
||||
$(MAKE) -C source/lua a
|
||||
|
||||
TARGET=inlretro
|
||||
|
||||
#default to windows build
|
||||
all:
|
||||
$(CC) $(INCLUDE) $(LUAOBJ) $(SOURCES) -o $(TARGET) $(WINLIB) $(CFLAGS) $(LIBUSB)
|
||||
all: liblua $(DEPS) $(OBJECTS)
|
||||
$(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_WINDOWS)
|
||||
|
||||
#unix build doesn't need winlib directory as libusb should be installed on OS.
|
||||
#sudo apt-get install libusb-1.0-0-dev
|
||||
unix:
|
||||
$(CC) $(INCLUDE) $(LUAOBJ) $(SOURCES) -o $(TARGET) $(CFLAGS) -lm $(LIBUSB)
|
||||
unix: liblua $(DEPS) $(OBJECTS)
|
||||
$(CC) $(INCLUDE) $(OBJECTS) -o $(TARGET) $(CFLAGS) $(LDFLAGS_UNIX)
|
||||
|
||||
# "make debug" will build program with debug print messages
|
||||
# -DDEBUG show debug logs
|
||||
|
|
@ -31,7 +45,8 @@ debug: all
|
|||
unixdebug: CFLAGS += -DDEBUG -g
|
||||
unixdebug: unix
|
||||
|
||||
|
||||
#clean on unix and windows(.exe)
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(TARGET) $(TARGET).exe $(OBJECTS) $(LUAOBJ)
|
||||
$(MAKE) -C source/lua clean
|
||||
rm -f $(TARGET) $(TARGET).exe $(OBJECTS) $(DEPS) $(LUAOBJ) source/lua/liblua.a
|
||||
|
|
|
|||
Loading…
Reference in New Issue