Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7013729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:25:44+00:00 2026-05-27T22:25:44+00:00

I have a main kernel module with which other kernel modules communicate. I have

  • 0

I have a main kernel module with which other kernel modules communicate. I have structured the modules like this (conceptually):

main module/
           |
            \drivers/
                    |
                    |\driver1
                    |\driver2
                     \driver3

Since these are kernel modules, I need to compile them like this:

make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules

However, since the Makefile of drivers can be called from previous directories, I need to do the $(shell pwd) before calling the other make (linux’s make). So the Makefile now looks like this:

CURRENT_DIR := $(shell pwd)

.PHONY: all
all:
    $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURRENT_DIR) modules

So far it is fine and it works perfectly. The problem is this: I have a file that the drivers need to include, so I have to give the include path to make. I first tried

EXTRA_CFLAGS += -I../..

and immediately understood why it doesn’t work (relative path would be to /lib/module/… not to current directory). So I changed it to:

MAIN_MODULE_HOME := $(CURRENT_DIR)/../..
EXTRA_CFLAGS += -I$(MAIN_MODULE_HOME)

Oddly enough, this doesn’t work! If I write

EXTRA_CFLAGS += -Ipath/I/get/from/pwd/../..

manually, it compiles! Can someone explain what I am doing wrong? Before calling make, I echoed $(CURRENT_DIR) and $(MAIN_MODULE_HOME) and the variables are meaningful.

I know that EXTRA_CFLAGS is not immediately evaluated, but since CURRENT_DIR and MAIN_MODULE_HOME are declared with := I don’t understand how things are getting messed up.

(If anyone can phrase the question title better, please do!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:25:44+00:00Added an answer on May 27, 2026 at 10:25 pm

    You should pass EXTRA_CFLAGS to make like this:

    $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(CURRENT_DIR) \
               EXTRA_CFLAGS="$(EXTRA_CFLAGS)" modules
    

    Update:

    The content of driver1/Makefile is read twice: first – when you run make inside driver1 directory, second – by Kbuild system.

    First, CURRENT_DIR := $(shell pwd) is evaluated to something like /home/users/.../main module/drivers/driver1. Second, Kbuild evaluates CURRENT_DIR := $(shell pwd) to something like /usr/src/linux-headers-2.6.32-33-generic/

    That situation described in LDD3, ch2, p24

    The trick is to write your makefile as follows:

    # If KERNELRELEASE is defined, we've been invoked from the
    # kernel build system and can use its language.
    ifneq ($(KERNELRELEASE),)
        obj-m := hello.o
    # Otherwise we were called directly from the command
    # line; invoke the kernel build system.
    else
        KERNELDIR ?= /lib/modules/$(shell uname -r)/build
        PWD  := $(shell pwd)
    default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table called category in which i have main category ids and
I have a main asp.net app, which is written in asp.net 1.1. Runnning underneath
I have a main window (#1) on my webpage from which I open a
I have a main canvas 'blackboard' in a panel, this canvas has itself several
I have several threads which act as backup for the main one spending most
I have this code, for which I already posted something some time ago. Today
I have a WCF service to communicate with a Mathematica Kernel to evaluate arbitrary
I have main categories and sub categories. I want to be able to sort
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
I have 2 classes within same package. Both classes have main method in them.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.