Skip to content

Instantly share code, notes, and snippets.

@rafacouto
Created September 30, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafacouto/73762854e3b7ee063ba330b5c0dedd9d to your computer and use it in GitHub Desktop.
Save rafacouto/73762854e3b7ee063ba330b5c0dedd9d to your computer and use it in GitHub Desktop.
TARGET_EXEC ?= simul
TARGET_PLATFORM ?= linux
SRC_DIRS ?= . ../src
SRCS := $(shell find $(SRC_DIRS) -name '*.s')
SRCS += $(shell find $(SRC_DIRS) -name '*.c')
SRCS += $(shell find $(SRC_DIRS) -name '*.cpp')
OBJS := $(SRCS:%=%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
CPPFLAGS ?= $(addprefix -I,$(INC_DIRS)) -MMD -MP -Wall
CPPFLAGS += -DPLATFORM=$(TARGET_PLATFORM)
$(TARGET_EXEC): $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
# assembly
%.s.o: %.s
$(AS) $(ASFLAGS) -o $@ -c $<
# c source
%.c.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
# c++ source
%.cpp.o: %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
.PHONY: clean
clean:
$(RM) $(TARGET_EXEC) $(OBJS) $(DEPS)
-include $(DEPS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment