-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applying 'GNU Make Manual' style to Makefile
- Loading branch information
Showing
6 changed files
with
173 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# Title : Data applications makefile | ||
# Company : SLAC National Accelerator Laboratory | ||
# ---------------------------------------------------------------------------- | ||
# File : Makefile | ||
# Author : Ryan Herbst, [email protected] | ||
# Created : 2016-08-08 | ||
# Last update: 2016-08-08 | ||
# Description : | ||
# Makefile for building application. | ||
# This Makefile demonstrates how to compile a project that consists of | ||
# a library and an application using the library. | ||
# ---------------------------------------------------------------------------- | ||
# This file is part of the aes_stream_drivers package. It is subject to | ||
# the license terms in the LICENSE.txt file found in the top-level directory | ||
|
@@ -15,43 +14,53 @@ | |
# copied, modified, propagated, or distributed except according to the terms | ||
# contained in the LICENSE.txt file. | ||
# ---------------------------------------------------------------------------- | ||
# | ||
|
||
# Variables | ||
HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
CC := $(CROSS_COMPILE)g++ | ||
DEF := | ||
BIN := $(HOME)/bin | ||
OBJ := $(HOME)/.obj | ||
CFLAGS := -O2 -Wall -I$(HOME)/../../include/ -I$(HOME)/../../common/app_lib/ | ||
CFLAGS := -O2 -Wall -I$(HOME)/../../include -I$(HOME)/../../common/app_lib | ||
LFLAGS := -lpthread | ||
|
||
# Generic Sources | ||
LIB_DIR := $(HOME)/../../common/app_lib/ | ||
LIB_SRC := $(wildcard $(LIB_DIR)/*.cpp) | ||
LIB_HDR := $(wildcard $(LIB_DIR)/*.h) | ||
LIB_OBJ := $(patsubst $(LIB_DIR)/%.cpp,$(OBJ)/%.o,$(LIB_SRC)) | ||
# Source and Object Directories | ||
LIB_DIR := $(HOME)/../../common/app_lib | ||
LIB_SRC := $(wildcard $(LIB_DIR)/*.cpp) | ||
LIB_HDR := $(wildcard $(LIB_DIR)/*.h) | ||
LIB_OBJ := $(patsubst $(LIB_DIR)/%.cpp,$(OBJ)/%.o,$(LIB_SRC)) | ||
|
||
# Application Sources | ||
APP_DIR := $(HOME)/src | ||
APP_SRC := $(wildcard $(APP_DIR)/*.cpp) | ||
APP_BIN := $(patsubst $(APP_DIR)/%.cpp,$(BIN)/%,$(APP_SRC)) | ||
APP_DIR := $(HOME)/src | ||
APP_SRC := $(wildcard $(APP_DIR)/*.cpp) | ||
APP_BIN := $(patsubst $(APP_DIR)/%.cpp,$(BIN)/%,$(APP_SRC)) | ||
|
||
# Targets | ||
# Main Targets | ||
all: $(LIB_OBJ) $(APP_BIN) | ||
@echo "Build complete." | ||
|
||
# Clean | ||
# Phony Targets | ||
.PHONY: all clean nothing_done | ||
|
||
# Clean Build Artifacts | ||
clean: | ||
@echo "Cleaning build artifacts." | ||
@rm -f $(BIN)/* | ||
@rm -f $(OBJ)/* | ||
|
||
# Compile Generic Sources | ||
# Compile Library Objects | ||
$(OBJ)/%.o: $(LIB_DIR)/%.cpp $(LIB_DIR)/%.h | ||
@test -d $(OBJ) || mkdir $(OBJ) | ||
@echo "Compiling $@ from $<"; $(CC) -c $(CFLAGS) $(DEF) -o $@ $< | ||
@test -d $(OBJ) || mkdir -p $(OBJ) | ||
@echo "Compiling library object $@" | ||
@$(CC) -c $(CFLAGS) $(DEF) -o $@ $< | ||
|
||
# Application sources | ||
# Compile Application Binaries | ||
$(BIN)/%: $(APP_DIR)/%.cpp $(LIB_OBJ) | ||
@test -d $(BIN) || mkdir $(BIN) | ||
@echo "Compiling $@ from $<"; $(CC) $(CFLAGS) $(CFLAGS32) $(DEF) $(LIB_OBJ) -o $@ $< $(LFLAGS) | ||
@test -d $(BIN) || mkdir -p $(BIN) | ||
@echo "Compiling application binary $@" | ||
@$(CC) $(CFLAGS) $(DEF) $(LIB_OBJ) -o $@ $< $(LFLAGS) | ||
|
||
# Check if anything was done, otherwise print a custom message | ||
nothing_done: | ||
@echo "Make done, but no tasks were performed." | ||
|
||
# Include this phony target as a dependency to main targets if needed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,51 @@ | ||
NAME := axi_memory_map | ||
HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
GITV := petalinux | ||
# ---------------------------------------------------------------------------- | ||
# Company : SLAC National Accelerator Laboratory | ||
# ---------------------------------------------------------------------------- | ||
# Description : | ||
# Builds the axi_memory_map kernel driver for petalinux package | ||
# ---------------------------------------------------------------------------- | ||
# This file is part of the aes_stream_drivers package. It is subject to | ||
# the license terms in the LICENSE.txt file found in the top-level directory | ||
# of this distribution and at: | ||
# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. | ||
# No part of the aes_stream_drivers package, including this file, may be | ||
# copied, modified, propagated, or distributed except according to the terms | ||
# contained in the LICENSE.txt file. | ||
# ---------------------------------------------------------------------------- | ||
|
||
SRCS := $(wildcard $HOME/*.c) | ||
# Name of the module | ||
NAME := axi_memory_map | ||
|
||
# Determine the directory of the current Makefile | ||
HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
# Versioning information from Git for embedding in the driver | ||
GITV := petalinux | ||
|
||
# Source and object files | ||
SRCS := $(wildcard $(HOME)/*.c) | ||
OBJS := $(patsubst %.c,%.o,$(SRCS)) | ||
|
||
# Compiler flags | ||
ccflags-y := -I$(HOME) | ||
ccflags-y += -DDMA_IN_KERNEL=1 -DGITV=\"$(GITV)\" | ||
ccflags-y += -Wformat=0 -Wno-int-to-pointer-cast | ||
ccflags-y += -g -DDEBUG | ||
|
||
# Object files for the module | ||
$(NAME)-objs := aximemorymap.o | ||
obj-m := $(NAME).o | ||
obj-m := $(NAME).o | ||
|
||
# Default target to compile the kernel module | ||
all: | ||
$(MAKE) -C $(KERNEL_SRC) M=$(HOME) | ||
@$(MAKE) -C $(KERNEL_SRC) M=$(HOME) | ||
|
||
# Target to install the module | ||
modules_install: | ||
$(MAKE) -C $(KERNEL_SRC) M=$(HOME) modules_install | ||
@$(MAKE) -C $(KERNEL_SRC) M=$(HOME) modules_install | ||
|
||
# Clean the build directory | ||
clean: | ||
rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c | ||
rm -f Module.markers Module.symvers modules.order | ||
rm -rf .tmp_versions Modules.symvers | ||
@rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c | ||
@rm -f Module.markers Module.symvers modules.order | ||
@rm -rf .tmp_versions Modules.symvers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,61 @@ | ||
NAME := axi_stream_dma | ||
HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
GITV := petalinux | ||
# ---------------------------------------------------------------------------- | ||
# Company : SLAC National Accelerator Laboratory | ||
# ---------------------------------------------------------------------------- | ||
# Description : | ||
# Builds the axi_stream_dma kernel driver for petalinux package | ||
# ---------------------------------------------------------------------------- | ||
# This file is part of the aes_stream_drivers package. It is subject to | ||
# the license terms in the LICENSE.txt file found in the top-level directory | ||
# of this distribution and at: | ||
# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. | ||
# No part of the aes_stream_drivers package, including this file, may be | ||
# copied, modified, propagated, or distributed except according to the terms | ||
# contained in the LICENSE.txt file. | ||
# ---------------------------------------------------------------------------- | ||
|
||
SRCS := $(wildcard $HOME/*.c) | ||
# Kernel module name | ||
NAME := axi_stream_dma | ||
|
||
# Directory containing the Makefile | ||
HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
# Version or identifier for this build | ||
GITV := petalinux | ||
|
||
# Source files discovery within the same directory as the Makefile | ||
SRCS := $(wildcard $(HOME)/*.c) | ||
|
||
# Object files corresponding to the source files | ||
OBJS := $(patsubst %.c,%.o,$(SRCS)) | ||
|
||
# Compiler flags | ||
# - Include the directory of the Makefile for header file searches | ||
# - Define macros relevant to the DMA and debug options | ||
# - Suppress specific warnings and enable debugging symbols | ||
ccflags-y := -I$(HOME) | ||
ccflags-y += -DDMA_IN_KERNEL=1 -DGITV=\"$(GITV)\" | ||
ccflags-y += -Wformat=0 -Wno-int-to-pointer-cast | ||
ccflags-y += -g -DDEBUG | ||
|
||
$(NAME)-objs := dma_buffer.o dma_common.o | ||
$(NAME)-objs += axis_gen1.o axis_gen2.o axistreamdma.o | ||
obj-m := $(NAME).o | ||
# Object files needed for the kernel module | ||
$(NAME)-objs := dma_buffer.o dma_common.o axis_gen1.o axis_gen2.o axistreamdma.o | ||
|
||
# Kernel module object | ||
obj-m := $(NAME).o | ||
|
||
# Default target: build the kernel module | ||
all: | ||
@echo "Building $(NAME) kernel module..." | ||
$(MAKE) -C $(KERNEL_SRC) M=$(HOME) | ||
|
||
# Install the built kernel module into the system | ||
modules_install: | ||
@echo "Installing $(NAME) module..." | ||
$(MAKE) -C $(KERNEL_SRC) M=$(HOME) modules_install | ||
|
||
# Clean the build directory | ||
clean: | ||
rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c | ||
rm -f Module.markers Module.symvers modules.order | ||
rm -rf .tmp_versions Modules.symvers | ||
@echo "Cleaning up build artifacts..." | ||
rm -f $(HOME)/*.o $(HOME)/*~ $(HOME)/core $(HOME)/.depend $(HOME)/.*.cmd $(HOME)/*.ko $(HOME)/*.mod.c | ||
rm -f $(HOME)/Module.markers $(HOME)/Module.symvers $(HOME)/modules.order | ||
rm -rf $(HOME)/.tmp_versions $(HOME)/Modules.symvers |