The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > Linux
Google UNIX.COM


Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
CEP Event Sources iBot Complex Event Processing RSS News 0 08-23-2007 11:50 AM
Kernel sources byblyk Linux 1 03-06-2006 02:02 PM
Subtract date & time in diferent rows vanand420 UNIX for Dummies Questions & Answers 1 07-10-2005 05:07 AM
unix sources fdarkangel UNIX for Dummies Questions & Answers 2 06-09-2005 07:39 AM
Backing up Folders without some folders...;) chimpu Shell Programming and Scripting 1 04-26-2004 07:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-12-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-12-2008
era era is online now
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,250
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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 08:41 AM. Reason: Idempotency and concurrency remarks
Reply With Quote
  #3 (permalink)  
Old 05-12-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Smile

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 12:59 PM.
Reply With Quote
  #4 (permalink)  
Old 05-12-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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 06:56 AM.
Reply With Quote
  #5 (permalink)  
Old 05-12-2008
era era is online now
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,250
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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.
Reply With Quote
  #6 (permalink)  
Old 05-12-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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 . 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.
Reply With Quote
  #7 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Cool 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 07:03 AM.
Reply With Quote
  #8 (permalink)  
Old 05-13-2008
era era is online now
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,250
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
I would have thought something more or less along these lines:

Code:
tmp/%.c:
      cp $$(test -e platform_source/$*.c && echo platform_source || echo master_source)/$*.c $@
I'm still just struggling with the idea that it's probably better to tell the compiler to prefer files from platform_source over files from master_source and avoid this whole silly copying business (gripes over apparent negligence towards code modularity notwithstanding).
Reply With Quote
  #9 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: May 2008
Posts: 6
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Talking

jeje, it's really better, but the company is working with batch files (Windows XP), and that's my idea to reduce compiling time. It would really take a long time to modify all source files along with creating Makefiles. For now I just will create makefile, repeating steps of batch files. Anyway thanks for replys. Good luck!

Last edited by borzh62; 05-13-2008 at 12:59 PM.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash for loop boot: cannot open kernel/sparcv9/unix command copy/move folder in unix curses.h cut command in unix daemon process export command in unix find grep find mtime find null character in a unix file glance unix grep multiple lines grep or grep recursive inaddr_any inappropriate ioctl for device lynx javascript mailx attachment mget mtime perl array length ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude tar extract to folder test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi substitute while loop within while loop shell script


All times are GMT -7. The time now is 12:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101