Skip to content

Commit

Permalink
Applying 'GNU Make Manual' style to Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
ruck314 committed Feb 24, 2024
1 parent 6a98f6f commit 8919ad0
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 66 deletions.
28 changes: 22 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Company : SLAC National Accelerator Laboratory
# ----------------------------------------------------------------------------
# Description:
# Example driver makefile
# Makefile for building drivers, applications, and RCE modules.
# This Makefile provides targets for compiling applications (app),
# drivers, and RCE modules for specific architectures and kernel versions.
# ----------------------------------------------------------------------------
# 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
Expand All @@ -13,35 +15,49 @@
# contained in the LICENSE.txt file.
# ----------------------------------------------------------------------------

# Set the path to the Makefile's directory
MAKE_HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

# Default architecture
ARCH ?= arm

# Discover the local kernel versions
LOC_VERS := $(wildcard /lib/modules/*/build)
LOC_VERS := $(patsubst %/,%,$(dir $(LOC_VERS)))
LOC_VERS := $(notdir $(LOC_VERS))

# Define RCE module directories
RCE_DIRS := /afs/slac.stanford.edu/g/cci/volumes/vol1/xilinx/linux-xlnx-v2016.4
RCE_DIRS += /afs/slac.stanford.edu/g/cci/volumes/vol1/xilinx/backup/linux-xlnx-v2016.1.01

# Default target: Display the available build options
all:
@echo "Options: app driver rce"
@echo "Available targets: app driver rce"

# Build applications
app:
@echo "Building applications..."
@make -C $(MAKE_HOME)/rce_stream/app clean
@make -C $(MAKE_HOME)/rce_stream/app
@make -C $(MAKE_HOME)/data_dev/app clean
@make -C $(MAKE_HOME)/data_dev/app

# Build drivers for each discovered kernel version
driver:
@mkdir -p $(MAKE_HOME)/install;
@ $(foreach ver,$(LOC_VERS), \
@echo "Building drivers for all kernel versions..."
@mkdir -p $(MAKE_HOME)/install
@$(foreach ver,$(LOC_VERS), \
mkdir -p $(MAKE_HOME)/install/$(ver); \
make -C $(MAKE_HOME)/data_dev/driver KVER=$(ver) clean; \
make -C $(MAKE_HOME)/data_dev/driver KVER=$(ver); \
scp $(MAKE_HOME)/data_dev/driver/*.ko $(MAKE_HOME)/install/$(ver); \
)

# Build RCE modules for specified directories
rce:
@mkdir -p $(MAKE_HOME)/install;
@ $(foreach d,$(RCE_DIRS), \
@echo "Building RCE modules..."
@mkdir -p $(MAKE_HOME)/install
@$(foreach d,$(RCE_DIRS), \
mkdir -p $(MAKE_HOME)/install/$(shell make -C $(d) -s kernelversion).$(ARCH); \
make -C $(MAKE_HOME)/rce_stream/driver KDIR=$(d) clean; \
make -C $(MAKE_HOME)/rce_stream/driver KDIR=$(d); \
Expand Down
59 changes: 34 additions & 25 deletions data_dev/app/Makefile
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
Expand All @@ -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
43 changes: 29 additions & 14 deletions data_dev/driver/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# ----------------------------------------------------------------------------
# Title : Data development driver makefile
# Company : SLAC National Accelerator Laboratory
# ----------------------------------------------------------------------------
# File : Makefile
# Created : 2017-03-17
# ----------------------------------------------------------------------------
# Description:
# PGP card driver makefile
# Description :
# Builds the data_dev kernel driver for aes_stream_drivers 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
Expand All @@ -16,32 +13,50 @@
# contained in the LICENSE.txt file.
# ----------------------------------------------------------------------------

# Name of the module to be built
NAME := datadev

# Determine the current directory of the Makefile
HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

# Kernel version and architecture for the build
KVER := $(shell uname -r)
ARCH := $(shell uname -m)

# Cross-compile prefix, if any
CROSS_COMPILE :=

# Directory containing the kernel build system
KERNELDIR := /lib/modules/$(KVER)/build

# Source and object files
SRCS := $(wildcard src/*.c)
OBJS := $(patsubst %.c,%.o,$(SRCS))

# Automatically determine the git version
ifndef GITV
GITT := $(shell cd $(HOME); git describe --tags)
GITD := $(shell cd $(HOME); git status --short -uno | wc -l)
GITV := $(if $(filter $(GITD),0),$(GITT),$(GITT)-dirty)
GITT := $(shell cd $(HOME); git describe --tags)
GITD := $(shell cd $(HOME); git status --short -uno | wc -l)
GITV := $(if $(filter $(GITD),0),$(GITT),$(GITT)-dirty)
endif

# Compiler flags, including path to headers and version definitions
ccflags-y += -I$(HOME)/src
ccflags-y += -DDMA_IN_KERNEL=1 -DGITV=\"$(GITV)\"

# Object files that make up the module
$(NAME)-objs := src/dma_buffer.o src/dma_common.o
$(NAME)-objs += src/axi_version.o src/axis_gen2.o src/data_dev_top.o
obj-m := $(NAME).o

# Target module to be built
obj-m := $(NAME).o

# Default target: build the kernel module
all:
@echo $(GITV)
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) modules
@echo "Building with version: $(GITV)"
@make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) modules

# Clean target: remove built module and object files
clean:
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) clean
rm -f $(OBJS)
@make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) clean
@rm -f $(OBJS)
8 changes: 7 additions & 1 deletion data_gpu/driver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
# contained in the LICENSE.txt file.
# ----------------------------------------------------------------------------

NVIDIA_DRIVERS ?= ""

NAME := datagpu
HOME := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
KVER := $(shell uname -r)
ARCH := $(shell uname -m)
CROSS_COMPILE :=
KBUILD_MODPOST_WARN := 1
KERNELDIR := /lib/modules/$(KVER)/build
SRCS := $(wildcard src/*.c)
OBJS := $(patsubst %.c,%.o,$(SRCS))

KBUILD_EXTRA_SYMBOLS := $(NVIDIA_DRIVERS)/Module.symvers

ifndef GITV
GITT := $(shell cd $(HOME); git describe --tags)
GITD := $(shell cd $(HOME); git status --short -uno | wc -l)
Expand All @@ -30,7 +35,7 @@ endif

ccflags-y += -I$(HOME)/src
ccflags-y += -DDMA_IN_KERNEL=1 -DGITV=\"$(GITV)\"
ccflags-y += -I/usr/src/nvidia-418.56/nvidia/
ccflags-y += -I$(NVIDIA_DRIVERS)/nvidia

$(NAME)-objs := src/dma_buffer.o src/dma_common.o
$(NAME)-objs += src/axi_version.o src/axis_gen2.o src/gpu_async.o src/data_gpu_top.o
Expand All @@ -43,3 +48,4 @@ all:
clean:
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(HOME) clean
rm -f $(OBJS)

46 changes: 36 additions & 10 deletions petalinux/aximemorymap/files/Makefile
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
55 changes: 45 additions & 10 deletions petalinux/axistreamdma/files/Makefile
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

0 comments on commit 8919ad0

Please sign in to comment.