#######################################
# hp41uc Makefile
#######################################

TARGET=hp41uc
BUILD_DIR=build

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

CC=gcc
CFLAGS= -g -O2 -Wall -fno-strict-aliasing -Wno-format-overflow


#######################################
# Generate dependency information
CFLAGS += -MD -MP -MF .dep/$(@F).d

all: $(BUILD_DIR)/$(TARGET)

#######################################
# Sources
SRCS= Source/barcode.c  Source/compile.c  Source/convert.c  Source/decomp.c  Source/hp41uc.c

#######################################
# Includes
CFLAGS += -ISource


#######################################
# Building
#######################################

OBJS = $(addprefix $(BUILD_DIR)/,$(notdir $(SRCS:.c=.o)))
vpath %.c $(sort $(dir $(SRCS)))

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
	$(CC) -c $(CFLAGS) $< -o $@

$(BUILD_DIR)/$(TARGET): $(OBJS) Makefile
	$(CC) $(OBJS) $(LDFLAGS) -o $@


$(BUILD_DIR):
	mkdir -p $@


#######################################
# clean up
#######################################
clean:
	-rm -fR .dep $(BUILD_DIR)

#######################################
# dependencies
#######################################
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

.PHONY: clean all

