# Directories OBJDIR=obj BINDIR=bin SRCDIR=src INCDIR=include LIBDIR=lib LOGDIR=logs LOCALDIR=$(HOME)/local PAPIHIGHLEVELLIBDIR=lib PAPIHIGHLEVELINCDIR=include # Compilation flags # I know -finline-functions and -finline-functions-called-once are enabled by # -O3 but I did this in case gcc behaviour change one day CFLAGS=-g -O3 -finline-functions -finline-functions-called-once -Wall -Werror LDFLAGS=-L$(LIBDIR) -L$(LOCALDIR)/$(PAPIHIGHLEVELLIBDIR) -Wl,-rpath-link,$(HOME)/local/lib -lpthread -lpapihighlevel # Executables CC=gcc # Files BINNAMES=asm_cache_comm c_cache_comm pipe_comm shared_mem_comm shared_mem_opt_comm jikes_barrier_comm fake_comm BINS=$(patsubst %, $(BINDIR)/%, $(BINNAMES)) MAIN_OBJS=main.o common.o COMMON_LIB_OBJS=common.o .PHONY: all tidy clean distclean symlink .SECONDARY: .SUFFIXES: .c .o default: $(BINS) ifneq (,$(findstring $(MAKECMDGOALS),$(BINS))) BASE_TARGET=$(patsubst $(BINDIR)/%_comm,%,$(MAKECMDGOALS)) # Compilation of binary $(BINDIR)/$(BASE_TARGET)_comm: $(patsubst %,$(OBJDIR)/$(BASE_TARGET)_%,$(MAIN_OBJS)) $(LIBDIR)/lib$(BASE_TARGET).a if [ ! -d $(BINDIR) ] ; then mkdir $(BINDIR) ; fi $(CC) -o $@ $^ $(LDFLAGS) # Compilation of library $(LIBDIR)/lib$(BASE_TARGET).a: $(OBJDIR)/$(BASE_TARGET).o $(patsubst %,$(OBJDIR)/$(BASE_TARGET)_%,$(COMMON_LIB_OBJS)) if [ ! -d $(LIBDIR) ] ; then mkdir $(LIBDIR) ; fi $(AR) -rcus $@ $^ # Compile common source files $(OBJDIR)/$(BASE_TARGET)_%.o: $(SRCDIR)/%.c symlink if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi $(CC) $(CFLAGS) -I$(INCDIR) -I$(LOCALDIR)/$(PAPIHIGHLEVELINCDIR) -c $< -o $@ endif # Compile non common source files $(OBJDIR)/%.o: $(SRCDIR)/%.c symlink if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi $(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@ symlink: ln -sfT $(BASE_TARGET)_comm.h $(INCDIR)/specific_comm.h #.%.d: %.c # gcc $(CFLAGS) -MM $^ | sed -e 's/\([^:]*\):\(.*\)/\1 $@: \2 Makefile/' > $@ tidy: rm -f $(SRCDIR)/*~ \#* clean: rm -f $(INCDIR)/specific_comm.h rm -rf $(OBJDIR) logclean: rm -rf $(LOGDIR) distclean: clean rm -rf $(BINDIR) $(LIBDIR) #ifneq ($(MAKECMDGOALS),tidy) #ifneq ($(MAKECMDGOALS),clean) #ifneq ($(MAKECMDGOALS),distclean) # If the rules called is not a phony rules, then include the %.d makefile # corresponding to all objects #include $(patsubst %.o, .%.d, $(OBJ)) #endif #endif #endif