Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.20 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. git clone git://github.com/bagder/curl.git
  4.  
  5. mv curl/CMakeLists.txt curl/CMakeLists.old
  6. awk ' 1
  7. /^project/ {
  8.  print "SET(CMAKE_C_FLAGS \"${CMAKE_C_FLAGS} -m32\")"
  9.  print "SET(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -m32\")"
  10. } ' curl/CMakeLists.old >> curl/CMakeLists.txt
  11.  
  12. mkdir .bin_curl; pushd .bin_curl
  13. cmake ../curl \
  14.   -DBUILD_CURL_TESTS=OFF \
  15.   -DBUILD_CURL_EXE=OFF \
  16.   -DCURL_STATICLIB=ON \
  17.   -DCURL_DISABLE_LDAP=ON \
  18.   -DCURL_DISABLE_CRYPTO_AUTH=ON \
  19.   -DCMAKE_USE_OPENSSL=OFF \
  20.   -DCURL_ZLIB=OFF \
  21.   -DHAVE_LIBIDN=OFF
  22. make
  23. popd
  24.  
  25. mkdir .bin; pushd .bin
  26. echo \
  27. '#include <stdio.h>
  28. #include <sys/socket.h>
  29. #include "curl/curl.h"
  30. int get_qwerty(void)
  31. {
  32.  CURL *curl;
  33.  CURLcode res;
  34.  
  35.  curl = curl_easy_init();
  36.  if(curl) {
  37.    curl_easy_setopt(curl, CURLOPT_URL, "http://www.haxx.se/curl.html");
  38.    /* example.com is redirected, so we tell libcurl to follow redirection */
  39.    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  40.  
  41.    /* Perform the request, res will get the return code */
  42.    res = curl_easy_perform(curl);
  43.    /* Check for errors */
  44.    if(res != CURLE_OK)
  45.      fprintf(stderr, "curl_easy_perform() failed: %s\n",
  46.              curl_easy_strerror(res));
  47.  
  48.    /* always cleanup */
  49.    curl_easy_cleanup(curl);
  50.  }
  51.  return 0;
  52. }
  53. ' > library.cpp
  54. echo \
  55. '#ifndef __LIBRARY_H__
  56. #define __LIBRARY_H__
  57.  
  58. int get_qwerty(void);
  59.  
  60. #endif //__LIBRARY_H__
  61. ' > library.h
  62. echo \
  63. '#include <stdio.h>
  64. #include "library.h"
  65.  
  66. int main()
  67. {
  68.  printf("\nmain-start.\n\n");
  69.  get_qwerty();
  70.  printf("\nmain-end.\n\n");
  71.  return 0;
  72. }
  73. ' > main.cpp
  74. echo \
  75. 'CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
  76.  
  77. set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
  78. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  79. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  80.  
  81. INCLUDE_DIRECTORIES(.)
  82.  
  83. FILE(GLOB CurlLibrary ${CMAKE_SOURCE_DIR}/curl.a/*.o)
  84. ADD_LIBRARY(foo STATIC library.cpp ${CurlLibrary})
  85. ADD_EXECUTABLE(main main.cpp)
  86. TARGET_LINK_LIBRARIES(main foo)
  87. ' > CMakeLists.txt
  88. mkdir curl
  89. cp ../.bin_curl/include/curl/*.h ./curl/
  90. cp ../curl/include/curl/*.h ./curl/
  91. mkdir curl.a; pushd curl.a
  92. ar x ../../.bin_curl/lib/libcurl.a
  93. popd
  94. cmake .
  95. make
  96.  
  97. ./main
  98.  
  99. popd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement