Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Building Makefile Projects With Xcode

I'm trying to learn how to build a makefile project in Xcode, using the built-in documentation. (See Porting UNIX/Linux Applications to Mac OS X > Preparing to Port > Building Makefile Projects With Xcode) I get up to step six, which says, "Select 'GNU Make Target' from the list. If this is not shown in the 'Special Targets' list, you are not running the latest version of Xcode. Upgrade first."

Well, I am running Xcode 2.5, technically not the latest version, but it's the latest version I can run in Tiger. Besides, this documentation came with the version of Xcode that I'm using, so why would it be telling me to upgrade?

Somehow I suspect that the version of Xcode is not the problem, but the documentation becomes useless at this point. Any ideas?

MacBook Pro 17, Mac OS X (10.4.11), 4 GB RAM, 160 GB HD

Posted on Mar 20, 2008 3:04 PM

Reply
19 replies

Mar 20, 2008 6:33 PM in response to David Livesay

Hmm. I have Xcode 2.4.1 installed and I get the opportunity to select "External Target" when I add a new target. I have four "Special Target" choices listed in the New Target assistant:

Aggregate
Copy Files Target
External Target
Shell Script Target

What are the contents of:

/Library/Application Support/Apple/Developer Tools/Target Templates/Special Targets/ on your system? I get this:

<pre class="command">-rw-rw-r-- 1 root admin 309 Sep 11 2006 Copy Files Target.trgttmpl
-rw-rw-r-- 1 root admin 255 Sep 11 2006 External Target.trgttmpl
-rw-rw-r-- 1 root admin 302 Sep 11 2006 Shell Script Target.trgttmpl</pre>

charlie

Mar 20, 2008 6:51 PM in response to David Livesay

The expectation is that developers will figure things out for themselves. Consequently, the developer documentation is usually out of date compared to the tools and applications. The actual API documentation is kept up to date, but that is about it.

Create an empty project, add your files, then add a shell script target to run "make". I don't know if it is possible to hook up the "make clean" actions or not. I haven't tried.

Mar 20, 2008 7:58 PM in response to Charles Minow

I have the same choices in the Target Assistant, but no "GNU Make Target," which is what the documentation says to use. I tried using "External Target," but when I try to build the project I get "No targets specified and no makefile found." There is definitely a makefile in the directory I added, so I thought I must be using the wrong template.

Oddly enough, I don't have a "Target Templates" directory where you do. There's just

File Templates
Plug-ins
Project Templates
WebObjects Support

Mar 20, 2008 8:11 PM in response to etresoft

If "the expectation is that developers will figure things out for themselves" then why take up disk space with obsolete documentation? Besides, how does someone become a developer without any documentation? I can figure out a lot of things on my own, but how a particular software program works is subject to the choices the authors of that program made, and they really owe it to their users to document those arbitrary choices accurately.

Using a shell script target isn't what I'm trying to do. According to the documentation, if you use the right kind of target you can use the "run" and "clean" commands in Xcode instead of calling the shell commands. If I wanted to do that I'd just run them from the shell. I'm trying to learn how to build makefile projects with Xcode.

Mar 20, 2008 9:33 PM in response to David Livesay

David Livesay wrote:
I get "No targets specified and no makefile found." There is definitely a makefile in the directory I added, so I thought I must be using the wrong template.


Hmm. If I follow José Coelho's PDF from the link in my other post, it works just like he says. The advantage of his PDF is the illustrations. They made it so much easier to figure out what I should be seeing. So when I didn't see it, I knew there was something else. The first time, I got confused over which target was which, so I kept looking for stuff that wasn't there.

Once I figured out from his PDF what I was doing, I started over and made a brand new project just like he did, instead of using an old program I was compiling from Terminal with a Makefile.

Also, dumb question, but is your Makefile called "Makefile"? I suspect it's case-sensitive, as I've only ever seen them capitalized.

If you still can't get it to work, I'll try installing Xcode 2.4.1 this weekend and see if that makes a difference...

charlie

Mar 20, 2008 9:41 PM in response to David Livesay

David Livesay wrote:
It just occurred to me that if I were building this from the command line I'd run configure before make, but these instructions don't mention configure.


Is this a project that you made, or something you downloaded? The point of configure is to build a Makefile. So if you downloaded the source, but never ran configure, you wouldn't have a Makefile. Or if you do have one, it might not work on OS X.

charlie

Mar 21, 2008 6:24 AM in response to David Livesay

David Livesay wrote:
It's something I downloaded. Specifically, postgresql-8.3.0.


Oh, OK. I downloaded 8.3.1 and built it with Xcode. Here's what I did:

1. After I untarred the source, I looked at the main directory, and noticed there's a Makefile there already. So I looked at it, and it says that you need to run the configure script first or it won't use the Makefile. So I ran configure.

2. I opened Xcode and created a new target (using "External Target") and called it "Build with Make". I deleted the original target and made my new target the active build target.

3. I double clicked on the "Build with Make" target and set the directory under the "Custom Build Command" section to my downloaded postgresql directory. In this case it was: /Users/username/Documents/Downloads/postgresql-8.3.1.

4. Tell Xcode to build it, which it did (it takes a while).

I didn't try importing all the source into Xcode, but you don't have to do that to build it, just point make at the right directory. I could play with it a bit more this weekend.

Actually, there are a whole bunch of makefiles. Maybe part of the trick is to figure out which one to use.


Well, it would always just be the main one. Then the main one would use all the other makefiles as needed. Unless you're pretty certain of what you're doing, you probably don't want to mess with the way the main Makefile is set up in a project. Particularly one as complex as postgresql. You'd probably end up going in circles with all kinds of dependency problems.

charlie

Mar 21, 2008 8:32 AM in response to David Livesay

David Livesay wrote:
It's something I downloaded. Specifically, postgresql-8.3.0.


If this is an open-source project, there is little reason to need to have it in Xcode. If you were doing some significant work in the project and want to work in Xcode, that would be a good reason. If you just want to build and use it, then you can just do configure and make in the Terminal. Even if you wanted to debug something, you can attach the Xcode debugger to a running process without ever needing to build it.

Don't get me wrong. "Just because I want to build it in Xcode" is a perfectly valid reason, but you don't need Xcode. Sometimes people think that using the Xcode IDE is required on a Mac.

Mar 21, 2008 8:53 AM in response to David Livesay

David Livesay wrote:
If "the expectation is that developers will figure things out for themselves" then why take up disk space with obsolete documentation?


Because it would take a lot of effort to review all the shipping documentation and remove the obsolete stuff. If they had that much time they would have updated the documentation to begin with. Periodically they do go through and get rid of obsolete documentation, but not very often. Xcode 3.0 only came out recently. They have pretty much gotten rid of all the old ProjectBuilder documentation. They will do it eventually, but they do expect developers to put up with many more rough edges than end-users ever would.

Besides, how does someone become a developer without any documentation? I can figure out a lot of things on my own, but how a particular software program works is subject to the choices the authors of that program made, and they really owe it to their users to document those arbitrary choices accurately.


Learning to develop for a specific, non-market leading platform using free tools does have a steep learning curve. If you were on MS Windows, there would be lots of books available. If you were on something odd like VxWorks, your company would fly in a VxWorks training for a couple of weeks in addition to the extensive documentation that your several thousand dollars-per-seat license would have provided.

On MacOS X, you are going to have make to with what is available, learn on your own, and make use of resources such as this discussion forum to fill in the missing information. I even started a blog just for myself so that I could have a place to remember all of these tiny, undocumented, critically important MacOS X development topics I have to deal with. Sometimes I have to go through quite a bit of research to find the best way to do something and I need to remember the final answer along with the reasoning that got me to that answer.

Using a shell script target isn't what I'm trying to do. According to the documentation, if you use the right kind of target you can use the "run" and "clean" commands in Xcode instead of calling the shell commands. If I wanted to do that I'd just run them from the shell. I'm trying to learn how to build makefile projects with Xcode.


You have an excellent point. I have a couple of projects in Xcode that are websites. I have "make" hooked up to build the site (using XSLT) but I don't have "clean" hooked up, but I would like to. I will look into it right now and see if I can track it down.

I don't want this to seem discouraging for a new developer. This is part of the excitement about using a platform like MacOS X. Once you figure something out on your own, you could be one of the few people in the world to know how to do something. "one of the few people in the world" may be an exaggeration, but it is not an exaggeration to say that this "lack of documentation" really levels the playing field between small developers and big corporations on MacOS X. For example, in the first version of Mac Office 2008, the Microsoft developers didn't do their installer correctly. I could honestly say that I know how to do things that programmers at multinational corporations hadn't figured out yet. So, if you stick with it and don't give up, you can crest that learning curve and quickly become a true expert.

Mar 21, 2008 1:26 PM in response to David Livesay

OK. Here is the definitive answer.

To create a Makefile-based project using Xcode 3
1) Create a new, empty project.
2) Add your files to the project.
3) Add a new "External" target to your project.
4) Double-click the External target. You will get a very nice dialog where you can defined all the make, environment, and directory settings. I was able to get my makefile working perfecting. It builds in both Debug and Release configurations and Clean works as well.

So, while it is very poorly documented, it is a significant improvement from the old Makefile-based projects. There is actually an offhand reference to using an "External" target in the Xcode 3.0 documentation. You just have to pay very close attention to the date associated with any developer documentation. The old Xcode 2.3 docs from 2006 are still included with Xcode 3.0.

Mar 22, 2008 6:59 AM in response to etresoft

Not only is the built-in documentation in Xcode undated (unless you go to the trouble of figuring out where the documents reside, check their modification dates and assume they are correct), but they actually put the following statement at the top of the document on building makefile projects: "Note: These instructions apply to the latest version of Xcode." I mean, it's like they have gone out of their way and bent over backwards to mislead people! This isn't just sloppy. It's deceptive.

I'm glad to hear that it works well, so at least once I get this working it should prove to be worthwhile, but I just can't get over the fact that Apple would go to the trouble of building this support into Xcode and then obscure that fact by making arbitrary changes (i.e. the names of a few templates) that render their documentation obsolete and then not making the few simple changes required to correct it. Talk about hiding your light under a bushel! I wonder how many would-be Windows developer converts have simply given up and gone back to Windows because the documentation for Xcode is so pathetic.

Mar 22, 2008 7:12 AM in response to Charles Minow

Thanks for all your help, Charlie. The next thing I need to do is figure out how to run configure so that it adds the contributed modules I'm interested in and builds a universal binary. It looks like I have a lot of reading to do there.

If I ever get to upgrade to Leopard I'll add supporting multiple OS versions to the list. Fun!

Building Makefile Projects With Xcode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.