Makefile 3.72 KB
Newer Older
Lucas Russo's avatar
Lucas Russo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
# Set your cross compile prefix with CROSS_COMPILE variable
CROSS_COMPILE ?=

CMDSEP = ;

CC =		$(CROSS_COMPILE)gcc
AR =		$(CROSS_COMPILE)ar
LD =		$(CROSS_COMPILE)ld
OBJDUMP =	$(CROSS_COMPILE)objdump
OBJCOPY =	$(CROSS_COMPILE)objcopy
SIZE =		$(CROSS_COMPILE)size
MAKE =		make

INSTALL_DIR ?= /usr/lib
export INSTALL_DIR

# Kernel stuff (pcie driver and library) relative
# directory
KERNEL_DIR = kernel

# General C flags
CFLAGS = -std=gnu99 -O2

LOCAL_MSG_DBG ?= n
DBE_DBG ?= n
CFLAGS_DEBUG =

ifeq ($(LOCAL_MSG_DBG),y)
CFLAGS_DEBUG += -DLOCAL_MSG_DBG=1
endif

ifeq ($(DBE_DBG),y)
CFLAGS_DEBUG += -DDBE_DBG=1
endif

# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g

# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =

# Libraries
LIBS = -lzmq -lczmq -lmdp -lpcidriver
# General library flags -L<libdir>
LFLAGS =

# Specific platform objects
OBJS_PLATFORM =

# Include other Makefiles as needed here
#include services/services.mk
#include clients/clients.mk
include hal/hal.mk

# Include directories
INCLUDE_DIRS = $(hal_INCLUDE_DIRS) \
	       -I$(KERNEL_DIR)/include/pcie

# Merge all flags. Optimize for size (-Os)
CFLAGS += $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG)
#-Os

LDFLAGS = $(LDFLAGS_PLATFORM)
#-ffunction-sections -fdata-sections -Wl,--gc-sections

# Output modules
OUT = $(hal_OUT)

.SECONDEXPANSION:

# Save a git repository description
#REVISION = $(shell git describe --dirty --always)
#REVISION_NAME = revision
#OBJ_REVISION = $(addsuffix .o, $(REVISION_NAME))

OBJS_all =  $(hal_OBJS) $(OBJ_REVISION)

.PHONY: all kernel_check clean mrproper install uninstall tests examples

# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)

# Makefile rules
all: kernel_check $(OUT)

# Output Rule
$(OUT): $$($$@_OBJS)
	#$(REVISION_NAME).o
	$(CC) $(LFLAGS) $(CFLAGS) $(INCLUDE_DIRS) -o $@ $^ $(LDFLAGS) $(LIBS)
#$(SIZE) $@

#$(REVISION_NAME).o: $(REVISION_NAME).c
#	$(CC) $(CFLAGS) $(INCLUDE_DIRS) -DGIT_REVISION=\"$(REVISION)\" -c $<
#	$(SIZE) -t $@

# Pull in dependency info for *existing* .o files and don't complain if the
# corresponding .d file is not found
-include $(OBJS_all:.o=.d)

# Autodependencies generatation by Scott McPeak, November 2001,
# from article "Autodependencies with GNU make"
%.o: %.c
	$(CC) $(CFLAGS) $(INCLUDE_DIRS) -c $*.c -o $@

# create the dependency files "target: pre-requisites"
	${CC} -MM $(CFLAGS) $(INCLUDE_DIRS) $*.c > $*.d

# Workaround to make objects in different folders have
# the correct target path. e.g., "dir/bar.o: dir/bar.c dir/foo.h"
# instead of "bar.o: dir/bar.c dir/foo.h"
	@mv -f $*.d $*.d.tmp
	@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d

# All prereqs listed will also become command-less,
# prereq-less targets. In this way, the prereq file will be
# treated as changed and the target will be rebuilt
#   sed:    strip the target (everything before colon)
#   sed:    remove any continuation backslashes
#   fmt -1: list words one per line
#   sed:    strip leading spaces
#   sed:    add trailing colons
	@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
		sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
	@rm -f $*.d.tmp

kernel_check:
# Check for libraries and issue warning!!!
# $(MAKE) -C $(KERNEL_DIR) all

tests:
	$(MAKE) -C $@ all

examples:
	$(MAKE) -C $@ all

#install:
#	@install -m 755 $(TARGET_SHARED_VER) $(INSTALL_DIR)
#	$(foreach lib,$(TARGET_SHARED),ln -sf $(lib).$(LIB_VER) $(INSTALL_DIR)/$(lib) $(CMDSEP))
#
#uninstall:
#	$(foreach lib,$(TARGET_SHARED),rm -f $(INSTALL_DIR)/$(lib).$(LIB_VER) $(CMDSEP))
#	$(foreach lib,$(TARGET_SHARED),rm -f $(INSTALL_DIR)/$(lib) $(CMDSEP))

clean:
	rm -f $(OBJS_all) $(OBJS_all:.o=.d)
	$(MAKE) -C tests clean
	$(MAKE) -C examples clean
	$(MAKE) -C $(KERNEL_DIR) clean

mrproper: clean
	rm -f $(OUT)
	$(MAKE) -C examples mrproper