Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Makefile cross-platform (Linux, Mac) #97

Closed
wants to merge 2 commits into from

Conversation

daveyproctor
Copy link
Contributor

@daveyproctor daveyproctor commented Jul 17, 2017

Indeed, thanks to @crossroads1112 for step by step guidance and @americanhanko for his first pass in PR 86

@dmalan dmalan requested review from cmlsharp and kzidane July 17, 2017 01:46
@cmlsharp
Copy link
Contributor

cmlsharp commented Jul 17, 2017

I looked this over with Davey before he submitted the PR. Looks good to me!

Only thing I might note in the README.md is that sudo make install is only required on Linux, not on OSX.

Makefile Outdated
cp -r build/* $(DESTDIR)
cp -r debian/docs/* $(DESTDIR)/share/man/man3
cp debian/docs/* $(DESTDIR)/$(MANDIR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crossroads1112 @daveyproctor is ldconfig needed for Mac?

Copy link
Contributor Author

@daveyproctor daveyproctor Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kzidane are you asking about the command export LD_LIBRARY_PATH=/usr/local/lib asked for on Linux per line 35 of the updated README.md?

As per Apple Dynamic Libraries documentation, /usr/local is automatically checked for libraries.

A user can install elsewhere as desired, setting LD_LIBRARY_PATH.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Mind running ldconfig if installing on Linux, please?

@americanhanko
Copy link

americanhanko commented Jul 17, 2017

This permissions issue is still occuring for me on macOS. This wouldn't happen if there was a formula added for Homebrew installs, but not sure if you want this working without that or not.

$ make install
cc -Wall -Wextra -Werror -pedantic -std=c99 -fPIC -shared -Wl,-install_name,libcs50-8.dylib -o libcs50-8.0.6.dylib src/cs50.c
ln -s libcs50-8.0.6.dylib libcs50-8.dylib
ln -s libcs50-8.dylib libcs50.dylib
mkdir -p src build/include
install -m 644 src/cs50.h build/include/cs50.h
mkdir -p build/lib build/src/libcs50
mv libcs50-8.0.6.dylib libcs50-8.dylib libcs50.dylib build/lib
cp -r src/cs50.c src/cs50.h build/src/libcs50
asciidoctor -d manpage -b manpage -D debian/docs/ docs/eprintf.adoc docs/get_char.adoc docs/get_double.adoc docs/get_float.adoc docs/get_int.adoc docs/get_long_long.adoc docs/get_string.adoc
mkdir -p /usr/local /usr/local/share/man/man3
cp -r build/* /usr/local
cp: /usr/local/src: Permission denied
cp: build/src: unable to copy extended attributes to /usr/local/src: Permission denied
cp: /usr/local/src/libcs50: No such file or directory
cp: build/src/libcs50: unable to copy extended attributes to /usr/local/src/libcs50: No such file or directory
cp: /usr/local/src/libcs50/cs50.c: No such file or directory
cp: /usr/local/src/libcs50/cs50.h: No such file or directory
make: *** [install] Error 1```

@daveyproctor
Copy link
Contributor Author

daveyproctor commented Jul 18, 2017

@americanhanko mind showing me ls -l /usr/local/src?
I'm also wondering if sudo make install works?

@daveyproctor
Copy link
Contributor Author

@kzidane ideas on how to pass travis-ci tests?

@kzidane
Copy link
Member

kzidane commented Jul 18, 2017

@daveyproctor don't worry about that! It's complaining because you're PR'ing from a fork, and we have some environment variables set that are not available when building PRs from forks for security reasons. If you have write-access to this repo, you may push a branch and PR from that. Otherwise, I can fix later after merging, instead of having you worry about modifying the .travis.yml file. How does that sound?

cmlsharp
cmlsharp previously approved these changes Jul 20, 2017
@cmlsharp
Copy link
Contributor

:shipit:

@daveyproctor
Copy link
Contributor Author

@dmalan ready to merge?

cmlsharp
cmlsharp previously approved these changes Jul 21, 2017
@kzidane kzidane mentioned this pull request Jul 25, 2017
@kzidane
Copy link
Member

kzidane commented Aug 21, 2017

@dmalan any takes on this one?

@americanhanko
Copy link

americanhanko commented Aug 22, 2017

@daveyproctor Apologies for the delay in my response! sudo make install works on macOS and files that include cs50.h compile successfully with both gcc and clang. As expected, it does set root as the owner of/usr/local/src/. I don't foresee any issues with that though unless something else were to utilize that directory with different permissions.

Given all that, I do think a more elegant solution to installation on macOS would be to create a Homebrew recipe for libcs50 that utilizes the changes in this PR. This way, a student using macOS could install, uninstall, update, etc. with brew. Any thoughts on that?

Either way, thanks! Great work on this.

@daveyproctor
Copy link
Contributor Author

@americanhanko I did a little research on this, per the below. Unless I'm missing something(?), a problem with Brew seems to be that even upping the version number requires a PR. Rather unergonomic, if so. My full review:

Getting libcs50 via Brew

Goal

$ brew install libcs50
==> Using the sandbox
==> Downloading https://github.com/cs50/libcs50/archive/v8.0.5.zip
######################################################################## 100.0%
==> make install
🍺  /usr/local/Cellar/libcs50/8.0.5: 14 files, 33.2KB, built in 2 seconds

Steps and UX

  • Create a brew formula how to: Formula Cookbook
    • Everything happens via Github.
    • Fork the homebrew-core repo, add a Ruby "formula", and PR.
    • example formulas
    • $brew create https://github.com/cs50/libcs50/archive/v8.0.5.zip opens a pre-populated file /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libcs50.rb
    • Formula contains
      • a link to source zip / tarball
      • Minimum 1 test to make sure library is installed properly
  • On brew install cs50, Brew
    • gets and extracts the library
    • runs ./configure and make install, by default
      • installed into /usr/local/Cellar/
      • symlinks /usr/local/* to the Cellar
    • runs tests specified in the Formula
  • On brew upgrade cs50, Brew
    • checks the current version against the formula in GitHub
    • reinstalls as needed

Concerns + workarounds

  • As they say in the Formula Cookbook, upping the library version involves creating a new pull request with a trivially-changed brew formula.
    • Example.
    • This is bad because we would be reliant on brew in order to keep our libary versions in sync via multiple download methods.
    • Workaround
      • Brew makes this somewhat ergonomic with the command brew bump-formula-pr, which forks, commits, and pushes all in one step. Link
        • Also, brew bump-formula-pr --help
  • Installing into /usr/local/Cellar and symlinking /usr/local/* to it is different from installing from source on Mac and Linux, as per PR 97
    • Workaround
      • We could keep a different Makefile, Makefile.brew for Brew to use. In our formula, we could do make -f Makefile.brew

@americanhanko
Copy link

@daveyproctor thanks for the quick reply (and the excellent review).

We could keep a different Makefile, Makefile.brew for Brew to use. In our formula, we could do make -f Makefile.brew

This is one of the main reasons I chose to create Makefile.macos in #86. If keeping a different Makefile for Homebrew is legitimately an option, feel free to take from the one I wrote. Also, I completely agree with naming it Makefile.brew - it would better communicate its purpose.

Perhaps another option would be to write another target definition in the Makefile (e.g. make brew) which could be called in the Homebrew formula.

@cmlsharp
Copy link
Contributor

cmlsharp commented Aug 23, 2017

Homebrew concerns aside, I think we should merge this PR so we get rudimentary support for OSX and support for locally-installed asciidoctor (a nice side-effect of build and docs no longer being PHONY). We can worry about Homebrew after that.

@daveyproctor
Copy link
Contributor Author

@crossroads1112 would you consider pre-building the man pages on our end so the end user doesn't need to worry about asciidoctor?

@cmlsharp
Copy link
Contributor

So every time a change is made to the adoc files, we'd have to remember to regenerate the man pages? That doesn't feel super clean to me but maybe there's a better way? In any case, I don't really have a problem with keeping asciidoctor as a dependency.

@daveyproctor
Copy link
Contributor Author

That CS50 generates the man pages from .adoc seems like a convenience for us more than being relevant to the user. For instance, a maker of a library could write straight to their raw man pages, right? It almost seems like the .adoc files should live in our .gitignore, and not come with the library at all (only the man pages). Do you happen to know if asciidoctor or other man page generator is often a dependency for library installs?

@cmlsharp
Copy link
Contributor

It is absolutely a convenience for us but I don't see why that a bad thing. I don't know about asciidoctor specifically but it is very common for software to have "build dependencies" which are only required to make the project in the first place and are thus inherently conveniences for the developers as they aren't relavent to the actual use of the software.

@americanhanko
Copy link

@crossroads1112

So every time a change is made to the adoc files, we'd have to remember to regenerate the man pages?

Don't you have to do that anyway since the Debian package is distributed with the compiled man pages?

@cmlsharp
Copy link
Contributor

cmlsharp commented Aug 28, 2017 via email

@cmlsharp
Copy link
Contributor

cmlsharp commented Aug 28, 2017 via email

@kzidane kzidane mentioned this pull request Aug 29, 2017
@kzidane
Copy link
Member

kzidane commented Aug 29, 2017

Merged as part of #106. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants