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

  • Home
  • SEARCH
  • 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 8294331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:10:22+00:00 2026-06-08T14:10:22+00:00

I’ve got two makefiles, which are included in one main makefile. In the second

  • 0

I’ve got two makefiles, which are included in one main makefile.
In the second makefile there’s the following rule:

$(MAKEFILE2_OBJS): CFLAGS += -fPIC

As I’ve understood, when I write a rule like this one -fPIC will be added to CFLAGS only
for MAKEFILE2_OBJS.
But when I compile MAKEFILE1_OBJS with implicit rule, CFLAGS has the -fPIC flag from the second makefile.

Why is it happening?

Main Makefile:

CC := gcc
LD := gcc
AS := nasm
DEPEND := ./depend.sh

CFLAGS += -Wall -Werror -I. -g -DNDEBUG -masm=intel
ASFLAGS += -f elf64
LDFLAGS +=

TARGET := arora
MODULES := utils stage1 stage2

all: $(TARGET)

$(TARGET): stage1/arora-stage1 stage2/arora-stage2

SRCS :=
ERROR_FILES :=
OBJS :=
DEPS :=
OUTPUTS :=

include $(wildcard $(patsubst %,%/*.mk,$(MODULES)))

OBJS += $(SRCS:.c=.o)
DEPS += $(SRCS:.c=.d)
OUTPUTS += $(OBJS) $(DEPS) $(TARGET)

include $(DEPS)

%.d: %.c
    $(DEPEND) `dirname $*` $(CFLAGS) $*.c > $@

.PHONY: clean
clean:
    rm -f $(OUTPUTS)

Makefile1:

STAGE1_ASM_SRCS := $(wildcard $(DIR)/*/*.s)
STAGE1_ASM_OBJS := $(STAGE1_ASM_SRCS:.s=.o)

STAGE1_C_SRCS := $(wildcard $(DIR)/*/*.c)
STAGE1_C_OBJS := $(STAGE1_C_SRCS:.c=.o)
STAGE1_C_DEPS := $(STAGE1_C_OBJS:.o=.d)
STAGE1_SRCS := $(STAGE1_ASM_SRCS) $(STAGE1_C_SRCS)
STAGE1_OBJS := $(STAGE1_ASM_OBJS) $(STAGE1_C_OBJS)

SRCS += $(STAGE1_C_SRCS)
ERROR_FILES += $(wildcard $(DIR)/*/*_errors.hx)
OUTPUTS += $(patsubst %,$(DIR)/%, linker_script.lds stage1.elf stage1_exec.bin stage1_data.bin stage1_main.bin arora-main-overwritten arora-exec-free-space-overwritten arora-stage1 original-definitions original-definitions.h) $(STAGE1_ASM_OBJS)

STAGE1_INCLUDE_PATH := $(DIR)

$(STAGE1_C_OBJS) $(STAGE1_C_DEPS): CFLAGS += -fno-stack-protector -nostdlib -I$(STAGE1_INCLUDE_PATH)

# hack
include $(DIR)/original-definitions

.PHONY: $(DIR)/stage1
$(DIR)/stage1: $(DIR)/arora-stage1 $(DIR)/arora-main-overwritten $(DIR)/arora-exec-free-space-overwritten $(DIR)/original-definitions $(DIR)/original-definitions.h

$(DIR)/original-definitions.h: $(DIR)/original-definitions $(DIR)/create_original_definitions_header.sh
    $(lastword $^) $< > $@

$(DIR)/original-definitions: $(DIR)/arora-original $(DIR)/extract-definitions.sh
    $(lastword $^) $< > $@

$(DIR)/arora-stage1: $(DIR)/stage1_main.bin $(DIR)/stage1_exec.bin $(DIR)/stage1_data.bin $(DIR)/arora-original
    cat $(lastword $^) > $@ && dd if=$< of=$@ bs=c seek=$(ARORA_MAIN_FILE_OFFSET) conv=notrunc && dd if=$(word 2, $^) of=$@ bs=c seek=$(ARORA_EXEC_FREE_SPACE_FILE_OFFSET) conv=notrunc && dd if=$(word 3, $^) of=$@ bs=c seek=$$(($(ARORA_EXEC_FREE_SPACE_FILE_OFFSET) + $$(wc -c $(word 2, $^) | awk '{print $$1}'))) conv=notrunc && chmod +x $@

$(DIR)/arora-main-overwritten: $(DIR)/arora-original $(DIR)/stage1_main.bin
    dd if=$< of=$@ bs=c skip=$(ARORA_MAIN_FILE_OFFSET) count=$$(wc -c $(lastword $^) | awk '{print $$1}')

$(DIR)/arora-exec-free-space-overwritten: $(DIR)/arora-original $(DIR)/stage1_exec.bin
    dd if=$< of=$@ bs=c skip=$(ARORA_EXEC_FREE_SPACE_FILE_OFFSET) count=$$(wc -c $(lastword $^) | awk '{print $$1}')

$(DIR)/arora-data-free-space-overwritten: $(DIR)/arora-original $(DIR)/stage1_exec.bin $(DIR)/stage1_data.bin
    dd if=$< of=$@ bs=c skip=$$(($(ARORA_EXEC_FREE_SPACE_FILE_OFFSET) + $$(wc -c $(word 2, $^) | awk '{print $$1}'))) count=$$(wc -c $(lastword $^) | awk '{print $$1}')

$(DIR)/stage1_main.bin: $(DIR)/stage1.elf
    objcopy -j .arora_main -O binary $^ $@

$(DIR)/stage1_exec.bin: $(DIR)/stage1.elf
    objcopy -j .arora_exec_free_space -O binary $^ $@ 

$(DIR)/stage1_data.bin: $(DIR)/stage1.elf
    objcopy -j .arora_data_free_space -O binary $^ $@

$(DIR)/stage1.elf: $(STAGE1_OBJS) utils/libpluginutils.a $(DIR)/linker_script.lds
    $(LD) $(STAGE1_OBJS) utils/libpluginutils.a -o $@ $(LDFLAGS) -ldl -nostdlib -T $(lastword $^)

$(DIR)/linker_script.lds: $(DIR)/linker_script.lds.template
    echo stage1_main will be at $(ARORA_MAIN_ADDRESS), the exec will be at $(ARORA_EXEC_FREE_SPACE_ADDRESS), the data will be after the exec. && sed s/ARORA_MAIN_ADDRESS/$(ARORA_MAIN_ADDRESS)/ $^ | sed s/ARORA_EXEC_FREE_SPACE_ADDRESS/$(ARORA_EXEC_FREE_SPACE_ADDRESS)/ | sed s/ARORA_DATA_LOADING_FREE_SPACE_ADDRESS/$(ARORA_DATA_LOADING_FREE_SPACE_ADDRESS)/  > $@

Makefile2:

DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))

STAGE2_SRCS := $(wildcard $(DIR)/*/*.c)
STAGE2_OBJS := $(STAGE2_SRCS:.c=.o) $(DIR)/overwritten/main-overwritten.o $(DIR)/overwritten/exec-free-space-overwritten.o $(patsubst %.s, %.o, $(wildcard $(DIR)/*/*.s))
STAGE2_DEPS := $(STAGE2_OBJS:.o=.d)

SRCS += $(STAGE2_SRCS)
ERROR_FILES += $(DIR)/stage2_errors.hx

OBJS += $(DIR)/overwritten/main-overwritten.o $(DIR)/overwritten/exec-free-space-overwritten.o
OUTPUTS += $(DIR)/stage2.so $(DIR)/overwritten/exec-free-space-overwritten.h $(DIR)/overwritten/main-overwritten.h $(DIR)/arora-stage2

.PHONY: $(DIR)/stage2
$(DIR)/stage2:  $(DIR)/arora-stage2

$(DIR)/arora-stage2: stage1/arora-stage1 $(DIR)/stage2.so
    cat $^ > $@ && chmod +x $@

$(DIR)/stage2.so: LDFLAGS += -shared
$(DIR)/stage2.so: $(STAGE2_OBJS) utils/libpluginutils.a
    $(LD) $(LDFLAGS) $^ -o $@ 

$(STAGE2_OBJS): CFLAGS += -fPIC

$(DIR)/overwritten/main-overwritten.o: stage1/arora-main-overwritten
    objcopy -F elf64-x86-64 -B i386 -I binary $^ $@

$(DIR)/overwritten/exec-free-space-overwritten.o: stage1/arora-exec-free-space-overwritten
    objcopy -F elf64-x86-64 -B i386 -I binary $^ $@

$(DIR)/overwritten/data-free-space-overwritten.o: stage1/arora-data-free-space-overwritten
    objcopy -F elf64-x86-64 -B i386 -I binary $^ $@

$(DIR)/overwritten/main-overwritten.h: $(DIR)/overwritten/main-overwritten.o $(DIR)/create_objcopy_header.sh
    $(lastword $^) $< > $@

$(DIR)/overwritten/exec-free-space-overwritten.h: $(DIR)/overwritten/exec-free-space-overwritten.o $(DIR)/create_objcopy_header.sh
    $(lastword $^) $< > $@

$(DIR)/overwritten/data-free-space-overwritten.h: $(DIR)/overwritten/data-free-space-overwritten.o $(DIR)/create_objcopy_header.sh
    $(lastword $^) $< > $@
  • 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-06-08T14:10:25+00:00Added an answer on June 8, 2026 at 2:10 pm

    GNU make reads the entire Makefile (and all included Makefiles) into memory before it starts evaluating the rules. The variables in the commands of a rule are expanded when the rule is executed, not when it is read. See the following example:

    VAR = aaa
    
    all:
        @echo $(VAR)
    
    VAR += bbb
    

    “make” produces the output “aaa bbb”, because when the “all” rule is executed, $(VAR) has that value.

    If a Makefile includes other files, everything is treated as one large Makefile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.