Makefile with sources in diferent folders


 
Thread Tools Search this Thread
Operating Systems Linux Makefile with sources in diferent folders
# 1  
Old 05-12-2008
Makefile with sources in diferent folders

Hi guys!
I have a problem to create a makefile when using 2 types of sources.
Suppose we have sources at master_source folder:
- 1.c
- 2.c
and also we have sources at platform_source folder:
- 1.c

I really need to use platform_source folder because there is many of them (one folder with 1.c, 2.c, neither or both for each platform)

I need to copy master_source files to a diferent folder (say tmp) and there overwrite files with ones at platform_source folder.

So if i touch platform_source/1.c it shoul copy only this file to tmp folder. And if i touch master_src/1.c, it should copy master_src/1.c to tmp and after it copy platform_source/1.c to tmp (or not do anything, because our source depends mostly on platform_source folder)

If someone can help me to create such a makefile i would apreciate it.
Thanks!
# 2  
Old 05-12-2008
It could be done, I suppose, but are you sure this is really the right approach? A customary arrangement would be to factor the platform-dependent stuff to individual #include files or directories, then at compilation time pass in a #define which selects which platform to build for. By and large, this sounds like a more maintainable and scalable approach than what you are proposing (and avoids this pesky issue of copying files and then being sure whatever is there is indeed the correct version).

"Classic" make is not very amenable to conditional dependencies; if GNU make syntax or some other extension is permissible, then it almost sounds doable, but still not necessarilly elegant and sustainable.

Whatever you come up with, I'd think you need to take into account idempotency and concurrency issues; what if a make is aborted, and the files are left lying there for the next make to pick up; or, what if two makes are started at roughly the same time?

Last edited by era; 05-12-2008 at 12:41 PM.. Reason: Idempotency and concurrency remarks
# 3  
Old 05-12-2008
Bug

Well, that what you propose is very nice, but i just give you an example, so you can understand that i have no other way.
I'm working in a company that makes games for cellphones, games have common java source files and specific for phone. So for example i have midlet.jpp at common source, and for phone Sony Ericsson k790 this source is working fine, but for Motorola Z6 it's not. So programmers here create midlet.jpp for Motorola Z6.
I'm sure that putting defines everywhere at code for all phones will be a mess, i have seen projects like this, and it is very difficult to read that kind of source.
And what's for concurrency issues, i really don't much care, because i will just compile project without starting two makes.
Thanks for your reply

Last edited by borzh62; 05-13-2008 at 04:59 PM..
# 4  
Old 05-12-2008
I created a makefile that is not copying 2.c to tmp:

Code:
all: tmp/*.c

master_source/*.c:

platform_source/*.c:

tmp/*.c: master_source/*.c platform_source/*.c
      @cp $< tmp/

Note that if there exists platform_source/3.c it must be copied too, when modificated.

Last edited by borzh62; 05-13-2008 at 10:56 AM..
# 5  
Old 05-12-2008
And forking a file every time you need to tweak it for another platform is not a mess? Brrr ....

Still, doesn't Java allow you to create an include path, so that when instructed to compile fnord.jpp, it would look first for motorola/fnord.jpp and then if it's not available, fall back to generic/fnord.jpp?

Make doesn't understand wildcards; again, if GNU make syntax is acceptable, then there is some hope, but still, I'm thinking that there are ways to work with the compiler which would obviate the need for copying stuff in the Makefile.
# 6  
Old 05-12-2008
wildcards

Its okay when we're talking about small program, but we're talking about lines and lines of code. If you would see something ugly as:

#ifdef MOTOROLA_Z6
// 3000 lines of code
#else
#ifdef SONYERICSSON_K790
//other 3000 lines of code
#else
//other 3000 lines of code
#endif
#endif

i'm sure you would understand this. It's better sometimes to "fork" a new file that use one file for 10-20 phones. But we are out of subject Smilie. I just wanted to know if there is a way to copy only necessarily files using make.
I have GNU make, and it understand wildcards: but appearently when using rule:
tmp/*.c: master_source/*.c platform_source/*.c
it only looks for files with same name in both master_source and platform_source. Is there some way to workaround this feature?, so it can copy all needed files not only ones with same name.
# 7  
Old 05-13-2008
Tools Figured it out

I figured it out. The solution was to use timestamps. Here is the makefile:

Code:
MASTER_SRC_DIR         = master_src
MASTER_SRC_FILES       = $(wildcard $(MASTER_SRC_DIR)/*.c)
SPECIFIC_SRC_DIR       = platform_src
SPECIFIC_SRC_FILES     = $(wildcard $(SPECIFIC_SRC_DIR)/*.c)

SOURCE_DIR             = tmp
SOURCE_FILES           = $(subst $(MASTER_SRC_DIR),$(SOURCE_DIR),$(MASTER_SRC_FILES)) \
                         $(subst $(SPECIFIC_SRC_DIR),$(SOURCE_DIR),$(SPECIFIC_SRC_FILES))

TIMESTAMP_MASTER_SRC   = $(SOURCE_DIR)/MasterSrc.time
TIMESTAMP_PLATFORM_SRC = $(SOURCE_DIR)/PlatformSrc.time

all: $(SOURCE_FILES)

$(SOURCE_FILES): $(TIMESTAMP_MASTER_SRC) $(TIMESTAMP_PLATFORM_SRC)

$(TIMESTAMP_MASTER_SRC): $(MASTER_SRC_FILES)
	$(foreach FILE, $?, \
		if [ ! -e $(subst $(MASTER_SRC_DIR),$(SPECIFIC_SRC_DIR),$(FILE)) ] ; then cp $(FILE) $(SOURCE_DIR)/ ; \
		else cp $(subst $(MASTER_SRC_DIR),$(SPECIFIC_SRC_DIR),$(FILE)) $(SOURCE_DIR)/ ; fi ; \
	)
	echo Do not delete! >$(TIMESTAMP_MASTER_SRC)

$(TIMESTAMP_PLATFORM_SRC): $(SPECIFIC_SRC_FILES)
	$(foreach FILE, $?, cp $(FILE) $(SOURCE_DIR)/ ; )
	echo Do not delete! >$(TIMESTAMP_PLATFORM_SRC)

That's it. As era said it's pretty ugly, but it's working. Can close the thread now.

Last edited by borzh62; 05-13-2008 at 11:03 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Connection to diferent server

Hello I'm conecting in server1 and I need connect to server2(other). I need doing that becouse I need run a lot bach of diferent serverX. I explain better: Connectionn server1 ## I need that all the step exit for xxx.txt of the server1 - run xxxx.sh - Conection server2 - su -... (1 Reply)
Discussion started by: bsebastian
1 Replies

2. UNIX for Dummies Questions & Answers

Question about I/O sources

Hi all, What is the difference between these two comands? sed s/a/b/ <f1 >f2 sed s/a/b/ f1 >f2 Best, santiagorf (3 Replies)
Discussion started by: santiagorf
3 Replies

3. Shell Programming and Scripting

multiple and diferent printf(s) for diferent fields in awk

Hi, I'm trying to print and outrput of a timestamp from a script i did that calcs de time diference betwen 2 timestamps in the format HH:MM:SS and i properly formated it with printf inside awk, but i can't do it with separate statements. This works fine, but can you explaim-me how to do it... (2 Replies)
Discussion started by: grafman
2 Replies

4. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

5. Homework & Coursework Questions

Help with Simple Multi-Level Makefile (Extremely New at Makefile)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Basically, the prompt is make a makefile with various sub makefiles in their respective subdirectories. All code... (1 Reply)
Discussion started by: Tatl
1 Replies

6. News, Links, Events and Announcements

Are the UnixWare 7.1.1 sources available?

So, I was browsing groklaw.net, and I was surprised to read that Pamela Jones was reading the copyright notices in the UnixWare 7.1.1 source code files... Groklaw - Santa Cruz Listed Novell as Owning the Copyrights in 1999 How can that be? Are the UnixWare 7.1.1 sources available to the... (1 Reply)
Discussion started by: pepinox
1 Replies

7. UNIX for Advanced & Expert Users

Makefile problem - How to run module load in a Makefile

Hi, I'm trying to run the module load command in a Makefile and i'm getting the following error: make: module: command not found Why is this? Is there any way to run this command in a Makefile? NOTE: command - module load msjava/sunjdk/1.5.0 works fine outside of the Makefile (2 Replies)
Discussion started by: hernandinho
2 Replies

8. Linux

Kernel sources

I"m installing my ATI card in FC4. I'm going off of instructions that i've found. The firs step says that i need my kernel sources which i've got then it says that i've gotta unpack them so i can make links to the file later. My kernel sources that i've got are .src.rpm I've installed them but... (1 Reply)
Discussion started by: byblyk
1 Replies

9. UNIX for Dummies Questions & Answers

Subtract date & time in diferent rows

Hi Friends :) I have a long file having fields in the form : Field1 yy/mm/dd hh:mm:ss Duration(Sec) line 1) 123123 05/11/30 12:12:56 145 line 2) 145235 05/11/30 12:15:15 30 line 3) 145264 05/11/30 13:14:56 178 . . I want to subtract yy/dd/dd hh:mm:ss in line (2) from yy/mm/dd hh:mm:ss in... (1 Reply)
Discussion started by: vanand420
1 Replies

10. UNIX for Dummies Questions & Answers

unix sources

hello, i'm looking for the sources of the old, original unices (v3 preferred). could someone point a link? (2 Replies)
Discussion started by: fdarkangel
2 Replies
Login or Register to Ask a Question