flat assembler
Message board for the users of flat assembler.

Index > Heap > A few GNU make questions.

Author
Thread Post new topic Reply to topic
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
Can I use variables defined in a calling makefile inside the makefile being called? For example, in "makefile_1", I cd to another directory and use make on "makefile_2", can I use a variable defined in "makefile_1" in "makefile_2"?
Post 01 Jun 2010, 01:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Tyler: I don't know the answer to your question, since I don't use GNU myself, but it seems that it would have been faster to have just set up a small test to see if it works. Probably about one minute of effort at most. Now you have waited almost 3 hours and no one so far has been able to help you. Hehe, experience is the best teacher.
Post 01 Jun 2010, 04:32
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
So far, it doesn't work, the variables defined in one file do not work in another which is called by the file containing the variables, as far as I can tell.

revolution: Thanks for your input, I thought it would be better to ask because there may be some trick to do it. Just as most GNU utilities, make is very complex, and it would take a lot of time to master it to the extent that one could say definitively that it does or doesn't work, I was hoping someone here would have experience with it and could either tell me it's impossible or show me the secret behind it. See the docs, not something I look forward to reading Shocked!
Post 01 Jun 2010, 23:51
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
Unrelated, but what is used to link multiple object files into one? I've got my main makefile set up to produce one object for every directory(init, kernel, mm, ...), but say there are more than one source file I need to compile, how do I link those separate objects into the main object file for that directory? They must be compiled into separate file originally because I'm using Fasm for asm and gcc for C. For example, I've got start.asm and main.c in directory init, after compiling start.o and main.o, how would I link them together to produce init.o(which would latter be linked into the main kernel executable to be loaded by Grub)?

I'm not asking for specific args, or even specific names of programs, just what type of tool(compiler or linker) is used to do such a thing.
Post 02 Jun 2010, 00:15
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Tyler,
GNU make manual wrote:
5.7.2 Communicating Variables to a Sub-make

Variable values of the top-level make can be passed to the sub-make through the environment by explicit request. These variables are defined in the sub-make as defaults, but do not override what is specified in the makefile used by the sub-make makefile unless you use the ā€˜-eā€™ switch (see Section 9.7 [Summary of Options], page 96).

To pass down, or export, a variable, make adds the variable and its value to the environment for running each command. The sub-make, in turn, uses the environment to initialize its table of variable values. See Section 6.9 [Variables from the Environment], page 67.

Except by explicit request, make exports a variable only if it is either defined in the environment initially or set on the command line, and if its name consists only of letters, numbers, and underscores. Some shells cannot cope with environment variable names consisting of characters other than letters, numbers, and underscores.
Another point to mention is .EXPORT_ALL_VARIABLES pseudo-target. Why you need to guess or wait for fellow forumers' answer while you have manuals?
Post 02 Jun 2010, 09:05
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
baldr wrote:

Why you need to guess or wait for fellow forumers' answer while you have manuals?

I suck at finding things because I'm not good with the terminology. If I know what I am searching for, I can find and learn it quickly, but it's frustrating to know exactly what I'm trying to find out but not be able to find info on it. I ask for help prematurely out of frustration sometimes, I'm sorry.
Post 03 Jun 2010, 02:13
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Tyler,

Most manuals have table of contents and index; this particular one is only 188 pages long ā€” not a "War and Peace"-sized book. Read it and you'll be better with terminology and stuff. Wink
Post 03 Jun 2010, 06:15
View user's profile Send private message Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 521
Location: ( . Y . )
ass0
Jezz tyler most books of programming are ~ 1000 pages more or less, don't be too lazy xD

_________________
Image
Nombre: Aquiles Castro.
Location2: about:robots
Post 03 Jun 2010, 13:48
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
I don't read books(or much else for that matter) that I'm not required to by school assignments.
Post 03 Jun 2010, 20:32
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
This is more of a question about individual opinion than makefile semantics, but which is better(in your opinion), a central makefile that can build everything, or multiple makefiles, one for each directory, all relying on a central include?

Right now, I've got a makefile set up on the central do-everything model:
Code:
ASM=fasm
ASMFLAGS=-m 262144 -p 1000
CC=gcc
CFLAGS=-ansi -c -ffreestanding -I $(BASEDIR) -m32 -Wall
LDFLAGS=-melf_i386 -nostdlib --oformat elf32-i386 -r -T $(BASEDIR)/objlink.ld --warn-unresolved-symbols 

BASEDIR=. # alternative: $(shell pwd)
VPATH=$(foreach DIR,$(DIRS),./$(DIR))

DIRS=boot init mm kernel # list of directories relative to the root of the make
SRCS=console.c gdt.asm grubheader.asm main.c mem.c start.asm # list of sources to be compiled, must be in one of the directories in VPATH
OBJS=$(addsuffix .o,$(basename $(SRCS)))
LIBS=

# Set up implicit rules:
.SUFFIXES :
.SUFFIXES : .asm .c .o
.asm.o :
   $(info ==== .asm -> .o rule)
     @$(ASM) $(ASMFLAGS) $< $(BASEDIR)/$@
.c.o :
       $(info ==== .c -> .o rule)
       @$(CC) $(CFLAGS) $<
.o.o :
        $(info ==== .o -> .o rule)
       @ld $(LDFLAGS) $< -o $@

# Default target: all
all : kern.img

kern.img : $(LIBS) $(OBJS)
     ld -melf_i386 -nostdlib --oformat elf32-i386 -T $(BASEDIR)/link.ld $(LIBS) $(OBJS) -o kern.img

clean :
   $(info Cleaning directories...)
     rm $(wildcard *.a) $(wildcard *.o)
    

Simple, huh? Cool
Post 12 Jun 2010, 06:53
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.